aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Frontend/ASTUnit.cpp8
-rw-r--r--lib/Sema/CodeCompleteConsumer.cpp56
-rw-r--r--lib/Sema/SemaCodeComplete.cpp66
3 files changed, 64 insertions, 66 deletions
diff --git a/lib/Frontend/ASTUnit.cpp b/lib/Frontend/ASTUnit.cpp
index 31e42a3c36..452803acd2 100644
--- a/lib/Frontend/ASTUnit.cpp
+++ b/lib/Frontend/ASTUnit.cpp
@@ -1552,8 +1552,10 @@ void CalculateHiddenNames(const CodeCompletionContext &Context,
case CodeCompletionContext::CCC_MacroName:
case CodeCompletionContext::CCC_MacroNameUse:
case CodeCompletionContext::CCC_PreprocessorExpression:
+ case CodeCompletionContext::CCC_PreprocessorDirective:
case CodeCompletionContext::CCC_NaturalLanguage:
- // If we're just looking for protocol or macro names, nothing can hide them.
+ // We're looking for nothing, or we're looking for names that cannot
+ // be hidden.
return;
}
@@ -1676,7 +1678,9 @@ void AugmentedCodeCompleteConsumer::ProcessCodeCompleteResults(Sema &S,
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());
diff --git a/lib/Sema/CodeCompleteConsumer.cpp b/lib/Sema/CodeCompleteConsumer.cpp
index 303647bbc1..4345123558 100644
--- a/lib/Sema/CodeCompleteConsumer.cpp
+++ b/lib/Sema/CodeCompleteConsumer.cpp
@@ -615,6 +615,62 @@ void CodeCompletionResult::computeCursorKindAndAvailability() {
}
}
+/// \brief Retrieve the name that should be used to order a result.
+///
+/// If the name needs to be constructed as a string, that string will be
+/// saved into Saved and the returned StringRef will refer to it.
+static llvm::StringRef getOrderedName(const CodeCompletionResult &R,
+ std::string &Saved) {
+ switch (R.Kind) {
+ case CodeCompletionResult::RK_Keyword:
+ return R.Keyword;
+
+ case CodeCompletionResult::RK_Pattern:
+ return R.Pattern->getTypedText();
+
+ case CodeCompletionResult::RK_Macro:
+ return R.Macro->getName();
+
+ case CodeCompletionResult::RK_Declaration:
+ // Handle declarations below.
+ break;
+ }
+
+ DeclarationName Name = R.Declaration->getDeclName();
+
+ // If the name is a simple identifier (by far the common case), or a
+ // zero-argument selector, just return a reference to that identifier.
+ if (IdentifierInfo *Id = Name.getAsIdentifierInfo())
+ return Id->getName();
+ if (Name.isObjCZeroArgSelector())
+ if (IdentifierInfo *Id
+ = Name.getObjCSelector().getIdentifierInfoForSlot(0))
+ return Id->getName();
+
+ Saved = Name.getAsString();
+ return Saved;
+}
+
+bool clang::operator<(const CodeCompletionResult &X,
+ const CodeCompletionResult &Y) {
+ std::string XSaved, YSaved;
+ llvm::StringRef XStr = getOrderedName(X, XSaved);
+ llvm::StringRef YStr = getOrderedName(Y, YSaved);
+ int cmp = XStr.compare_lower(YStr);
+ if (cmp)
+ return cmp < 0;
+
+ // Non-hidden names precede hidden names.
+ if (X.Hidden != Y.Hidden)
+ return !X.Hidden;
+
+ // Non-nested-name-specifiers precede nested-name-specifiers.
+ if (X.StartsNestedNameSpecifier != Y.StartsNestedNameSpecifier)
+ return !X.StartsNestedNameSpecifier;
+
+ return false;
+}
+
void
CIndexCodeCompleteConsumer::ProcessCodeCompleteResults(Sema &SemaRef,
CodeCompletionContext Context,
diff --git a/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp
index 6d91b465de..f8bb9b5a75 100644
--- a/lib/Sema/SemaCodeComplete.cpp
+++ b/lib/Sema/SemaCodeComplete.cpp
@@ -2231,67 +2231,6 @@ CodeCompleteConsumer::OverloadCandidate::CreateSignatureString(
return Result;
}
-namespace {
- struct SortCodeCompleteResult {
- typedef CodeCompletionResult Result;
-
- /// \brief Retrieve the name that should be used to order a result.
- ///
- /// If the name needs to be constructed as a string, that string will be
- /// saved into Saved and the returned StringRef will refer to it.
- static llvm::StringRef getOrderedName(const Result &R,
- std::string &Saved) {
- switch (R.Kind) {
- case Result::RK_Keyword:
- return R.Keyword;
-
- case Result::RK_Pattern:
- return R.Pattern->getTypedText();
-
- case Result::RK_Macro:
- return R.Macro->getName();
-
- case Result::RK_Declaration:
- // Handle declarations below.
- break;
- }
-
- DeclarationName Name = R.Declaration->getDeclName();
-
- // If the name is a simple identifier (by far the common case), or a
- // zero-argument selector, just return a reference to that identifier.
- if (IdentifierInfo *Id = Name.getAsIdentifierInfo())
- return Id->getName();
- if (Name.isObjCZeroArgSelector())
- if (IdentifierInfo *Id
- = Name.getObjCSelector().getIdentifierInfoForSlot(0))
- return Id->getName();
-
- Saved = Name.getAsString();
- return Saved;
- }
-
- bool operator()(const Result &X, const Result &Y) const {
- std::string XSaved, YSaved;
- llvm::StringRef XStr = getOrderedName(X, XSaved);
- llvm::StringRef YStr = getOrderedName(Y, YSaved);
- int cmp = XStr.compare_lower(YStr);
- if (cmp)
- return cmp < 0;
-
- // Non-hidden names precede hidden names.
- if (X.Hidden != Y.Hidden)
- return !X.Hidden;
-
- // Non-nested-name-specifiers precede nested-name-specifiers.
- if (X.StartsNestedNameSpecifier != Y.StartsNestedNameSpecifier)
- return !X.StartsNestedNameSpecifier;
-
- return false;
- }
- };
-}
-
unsigned clang::getMacroUsagePriority(llvm::StringRef MacroName,
bool PreferredTypeIsPointer) {
unsigned Priority = CCP_Macro;
@@ -2338,7 +2277,7 @@ static void HandleCodeCompleteResults(Sema *S,
CodeCompletionContext Context,
CodeCompletionResult *Results,
unsigned NumResults) {
- std::stable_sort(Results, Results + NumResults, SortCodeCompleteResult());
+ std::stable_sort(Results, Results + NumResults);
if (CodeCompleter)
CodeCompleter->ProcessCodeCompleteResults(*S, Context, Results, NumResults);
@@ -4804,9 +4743,8 @@ void Sema::CodeCompletePreprocessorDirective(bool InConditional) {
// FIXME: we don't support #assert or #unassert, so don't suggest them.
Results.ExitScope();
- // FIXME: Create a new code-completion context for this?
HandleCodeCompleteResults(this, CodeCompleter,
- CodeCompletionContext::CCC_Other,
+ CodeCompletionContext::CCC_PreprocessorDirective,
Results.data(), Results.size());
}