unsigned num_unsaved_files,
unsigned options);
+/**
+ * \brief Sort the code-completion results in case-insensitive alphabetical
+ * order.
+ *
+ * \param Results The set of results to sort.
+ * \param NumResults The number of results in \p Results.
+ */
+CINDEX_LINKAGE
+void clang_sortCodeCompletionResults(CXCompletionResult *Results,
+ unsigned NumResults);
+
/**
* \brief Free the given set of code-completion results.
*/
Next.ProcessCodeCompleteResults(S, Context, Results, NumResults);
return;
}
-
- // Sort the completion results before passing them on to the actual consumer.
- std::stable_sort(AllResults.begin(), AllResults.end());
+
Next.ProcessCodeCompleteResults(S, Context, AllResults.data(),
AllResults.size());
CodeCompletionContext Context,
CodeCompletionResult *Results,
unsigned NumResults) {
+ std::stable_sort(Results, Results + NumResults);
+
// Print the results.
for (unsigned I = 0; I != NumResults; ++I) {
OS << "COMPLETION: ";
if (cmp)
return cmp < 0;
+ // If case-insensitive comparison fails, try case-sensitive comparison.
+ cmp = XStr.compare(YStr);
+ if (cmp)
+ return cmp < 0;
+
// Non-hidden names precede hidden names.
if (X.Hidden != Y.Hidden)
return !X.Hidden;
unsigned NumCandidates) {
for (unsigned I = 0; I != NumCandidates; ++I) {
WriteUnsigned(OS, CXCursor_NotImplemented);
- WriteUnsigned(OS, /*Priority=*/0);
+ WriteUnsigned(OS, /*Priority=*/I);
WriteUnsigned(OS, /*Availability=*/CXAvailability_Available);
CodeCompletionString *CCS
= Candidates[I].CreateSignatureString(CurrentArg, SemaRef);
CodeCompletionContext Context,
CodeCompletionResult *Results,
unsigned NumResults) {
- std::stable_sort(Results, Results + NumResults);
-
if (CodeCompleter)
CodeCompleter->ProcessCodeCompleteResults(*S, Context, Results, NumResults);
/* c-index-test.c */
#include "clang-c/Index.h"
+#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
fprintf(file, "\n");
}
+int my_stricmp(const char *s1, const char *s2) {
+ while (*s1 && *s2) {
+ int c1 = tolower(*s1), c2 = tolower(*s2);
+ if (c1 < c2)
+ return -1;
+ else if (c1 > c2)
+ return 1;
+
+ ++s1;
+ ++s2;
+ }
+
+ if (*s1)
+ return 1;
+ else if (*s2)
+ return -1;
+ return 0;
+}
+
int perform_code_completion(int argc, const char **argv, int timing_only) {
const char *input = argv[1];
char *filename = 0;
if (results) {
unsigned i, n = results->NumResults;
- if (!timing_only)
+ if (!timing_only) {
+ /* Sort the code-completion results based on the typed text. */
+ clang_sortCodeCompletionResults(results->Results, results->NumResults);
+
for (i = 0; i != n; ++i)
print_completion_result(results->Results + i, stdout);
+ }
n = clang_codeCompleteGetNumDiagnostics(results);
for (i = 0; i != n; ++i) {
CXDiagnostic diag = clang_codeCompleteGetDiagnostic(results, i);
AllocatedResults.Results[I].CompletionString = StoredCompletion;
}
}
+
+ // FIXME: Add ProcessOverloadCandidates?
};
}
} // end extern "C"
+
+namespace {
+ struct OrderCompletionResults {
+ bool operator()(const CXCompletionResult &XR,
+ const CXCompletionResult &YR) const {
+ CXStoredCodeCompletionString *X
+ = (CXStoredCodeCompletionString *)XR.CompletionString;
+ CXStoredCodeCompletionString *Y
+ = (CXStoredCodeCompletionString *)YR.CompletionString;
+
+ const char *XText = X->getTypedText();
+ const char *YText = Y->getTypedText();
+ if (!XText || !YText)
+ return XText != 0;
+
+ int result = llvm::StringRef(XText).compare_lower(YText);
+ if (result < 0)
+ return true;
+ if (result > 0)
+ return false;
+
+ result = llvm::StringRef(XText).compare(YText);
+ return result;
+ }
+ };
+}
+
+extern "C" {
+ void clang_sortCodeCompletionResults(CXCompletionResult *Results,
+ unsigned NumResults) {
+ std::stable_sort(Results, Results + NumResults, OrderCompletionResults());
+ }
+}
\ No newline at end of file
_clang_reparseTranslationUnit
_clang_saveTranslationUnit
_clang_setUseExternalASTGeneration
+_clang_sortCodeCompletionResults
_clang_tokenize
_clang_visitChildren
clang_reparseTranslationUnit
clang_saveTranslationUnit
clang_setUseExternalASTGeneration
+clang_sortCodeCompletionResults
clang_tokenize
clang_visitChildren