Index: lib/Sema/SemaCodeComplete.cpp =================================================================== --- lib/Sema/SemaCodeComplete.cpp +++ lib/Sema/SemaCodeComplete.cpp @@ -3741,10 +3741,12 @@ if (CodeCompleter->includeMacros()) AddMacroResults(PP, Results, false, PreferredTypeIsPointer); - HandleCodeCompleteResults(this, CodeCompleter, - CodeCompletionContext(CodeCompletionContext::CCC_Expression, - Data.PreferredType), - Results.data(),Results.size()); + CodeCompletionContext CC(CodeCompletionContext::CCC_Expression, + Data.PreferredType); + for (auto *Visited : Results.getCompletionContext().getVisitedContexts()) + CC.addVisitedContext(Visited); + HandleCodeCompleteResults(this, CodeCompleter, CC, Results.data(), + Results.size()); } void Sema::CodeCompletePostfixExpression(Scope *S, ExprResult E) { @@ -4360,17 +4362,11 @@ } Results.ExitScope(); - //We need to make sure we're setting the right context, - //so only say we include macros if the code completer says we do - enum CodeCompletionContext::Kind kind = CodeCompletionContext::CCC_Other; if (CodeCompleter->includeMacros()) { AddMacroResults(PP, Results, false); - kind = CodeCompletionContext::CCC_OtherWithMacros; } - - HandleCodeCompleteResults(this, CodeCompleter, - kind, - Results.data(),Results.size()); + HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), + Results.data(), Results.size()); } static bool anyNullArguments(ArrayRef Args) { @@ -4773,10 +4769,9 @@ CodeCompleter->includeGlobals(), CodeCompleter->loadExternal()); Results.ExitScope(); - - HandleCodeCompleteResults(this, CodeCompleter, - CodeCompletionContext::CCC_PotentiallyQualifiedName, - Results.data(),Results.size()); + + HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), + Results.data(), Results.size()); } void Sema::CodeCompleteUsingDirective(Scope *S) { @@ -4795,9 +4790,8 @@ CodeCompleter->includeGlobals(), CodeCompleter->loadExternal()); Results.ExitScope(); - HandleCodeCompleteResults(this, CodeCompleter, - CodeCompletionContext::CCC_Namespace, - Results.data(),Results.size()); + HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), + Results.data(), Results.size()); } void Sema::CodeCompleteNamespaceDecl(Scope *S) { @@ -4893,10 +4887,9 @@ // Add any type specifiers AddTypeSpecifierResults(getLangOpts(), Results); Results.ExitScope(); - - HandleCodeCompleteResults(this, CodeCompleter, - CodeCompletionContext::CCC_Type, - Results.data(),Results.size()); + + HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), + Results.data(), Results.size()); } void Sema::CodeCompleteConstructorInitializer( @@ -5177,9 +5170,8 @@ else AddObjCTopLevelResults(Results, false); Results.ExitScope(); - HandleCodeCompleteResults(this, CodeCompleter, - CodeCompletionContext::CCC_Other, - Results.data(),Results.size()); + HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), + Results.data(), Results.size()); } static void AddObjCExpressionResults(ResultBuilder &Results, bool NeedAt) { @@ -5311,9 +5303,8 @@ Results.EnterNewScope(); AddObjCVisibilityResults(getLangOpts(), Results, false); Results.ExitScope(); - HandleCodeCompleteResults(this, CodeCompleter, - CodeCompletionContext::CCC_Other, - Results.data(),Results.size()); + HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), + Results.data(), Results.size()); } void Sema::CodeCompleteObjCAtStatement(Scope *S) { @@ -5324,9 +5315,8 @@ AddObjCStatementResults(Results, false); AddObjCExpressionResults(Results, false); Results.ExitScope(); - HandleCodeCompleteResults(this, CodeCompleter, - CodeCompletionContext::CCC_Other, - Results.data(),Results.size()); + HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), + Results.data(), Results.size()); } void Sema::CodeCompleteObjCAtExpression(Scope *S) { @@ -5336,9 +5326,8 @@ Results.EnterNewScope(); AddObjCExpressionResults(Results, false); Results.ExitScope(); - HandleCodeCompleteResults(this, CodeCompleter, - CodeCompletionContext::CCC_Other, - Results.data(),Results.size()); + HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), + Results.data(), Results.size()); } /// Determine whether the addition of the given flag to an Objective-C @@ -5432,9 +5421,8 @@ Results.AddResult(CodeCompletionResult("null_resettable")); } Results.ExitScope(); - HandleCodeCompleteResults(this, CodeCompleter, - CodeCompletionContext::CCC_Other, - Results.data(),Results.size()); + HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), + Results.data(), Results.size()); } /// Describes the kind of Objective-C method that we want to find @@ -5616,9 +5604,8 @@ AddObjCMethods(Class, true, MK_ZeroArgSelector, None, CurContext, Selectors, /*AllowSameLength=*/true, Results); Results.ExitScope(); - HandleCodeCompleteResults(this, CodeCompleter, - CodeCompletionContext::CCC_Other, - Results.data(),Results.size()); + HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), + Results.data(), Results.size()); } void Sema::CodeCompleteObjCPropertySetter(Scope *S) { @@ -5645,9 +5632,8 @@ Selectors, /*AllowSameLength=*/true, Results); Results.ExitScope(); - HandleCodeCompleteResults(this, CodeCompleter, - CodeCompletionContext::CCC_Other, - Results.data(),Results.size()); + HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), + Results.data(), Results.size()); } void Sema::CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS, @@ -5723,8 +5709,7 @@ if (CodeCompleter->includeMacros()) AddMacroResults(PP, Results, false); - HandleCodeCompleteResults(this, CodeCompleter, - CodeCompletionContext::CCC_Type, + HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), Results.data(), Results.size()); } @@ -6396,9 +6381,8 @@ Results.AddResult(Builder.TakeString()); } Results.ExitScope(); - - HandleCodeCompleteResults(this, CodeCompleter, - CodeCompletionContext::CCC_SelectorName, + + HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), Results.data(), Results.size()); } @@ -6441,10 +6425,9 @@ Results.ExitScope(); } - - HandleCodeCompleteResults(this, CodeCompleter, - CodeCompletionContext::CCC_ObjCProtocolName, - Results.data(),Results.size()); + + HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), + Results.data(), Results.size()); } void Sema::CodeCompleteObjCProtocolDecl(Scope *) { @@ -6461,10 +6444,9 @@ Results.ExitScope(); } - - HandleCodeCompleteResults(this, CodeCompleter, - CodeCompletionContext::CCC_ObjCProtocolName, - Results.data(),Results.size()); + + HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), + Results.data(), Results.size()); } /// Add all of the Objective-C interface declarations that we find in @@ -6485,12 +6467,12 @@ } } -void Sema::CodeCompleteObjCInterfaceDecl(Scope *S) { +void Sema::CodeCompleteObjCInterfaceDecl(Scope *S) { ResultBuilder Results(*this, CodeCompleter->getAllocator(), CodeCompleter->getCodeCompletionTUInfo(), - CodeCompletionContext::CCC_Other); + CodeCompletionContext::CCC_ObjCInterfaceName); Results.EnterNewScope(); - + if (CodeCompleter->includeGlobals()) { // Add all classes. AddInterfaceResults(Context.getTranslationUnitDecl(), CurContext, false, @@ -6499,9 +6481,8 @@ Results.ExitScope(); - HandleCodeCompleteResults(this, CodeCompleter, - CodeCompletionContext::CCC_ObjCInterfaceName, - Results.data(),Results.size()); + HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), + Results.data(), Results.size()); } void Sema::CodeCompleteObjCSuperclass(Scope *S, IdentifierInfo *ClassName, @@ -6525,15 +6506,14 @@ Results.ExitScope(); - HandleCodeCompleteResults(this, CodeCompleter, - CodeCompletionContext::CCC_ObjCInterfaceName, - Results.data(),Results.size()); + HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), + Results.data(), Results.size()); } -void Sema::CodeCompleteObjCImplementationDecl(Scope *S) { +void Sema::CodeCompleteObjCImplementationDecl(Scope *S) { ResultBuilder Results(*this, CodeCompleter->getAllocator(), CodeCompleter->getCodeCompletionTUInfo(), - CodeCompletionContext::CCC_Other); + CodeCompletionContext::CCC_ObjCImplementation); Results.EnterNewScope(); if (CodeCompleter->includeGlobals()) { @@ -6544,9 +6524,8 @@ Results.ExitScope(); - HandleCodeCompleteResults(this, CodeCompleter, - CodeCompletionContext::CCC_ObjCInterfaceName, - Results.data(),Results.size()); + HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), + Results.data(), Results.size()); } void Sema::CodeCompleteObjCInterfaceCategory(Scope *S, @@ -6578,10 +6557,9 @@ nullptr), CurContext, nullptr, false); Results.ExitScope(); - - HandleCodeCompleteResults(this, CodeCompleter, - CodeCompletionContext::CCC_ObjCCategoryName, - Results.data(),Results.size()); + + HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), + Results.data(), Results.size()); } void Sema::CodeCompleteObjCImplementationCategory(Scope *S, @@ -6620,10 +6598,9 @@ IgnoreImplemented = false; } Results.ExitScope(); - - HandleCodeCompleteResults(this, CodeCompleter, - CodeCompletionContext::CCC_ObjCCategoryName, - Results.data(),Results.size()); + + HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), + Results.data(), Results.size()); } void Sema::CodeCompleteObjCPropertyDefinition(Scope *S) { @@ -6660,10 +6637,9 @@ false, /*AllowNullaryMethods=*/false, CurContext, AddedProperties, Results); Results.ExitScope(); - - HandleCodeCompleteResults(this, CodeCompleter, - CodeCompletionContext::CCC_Other, - Results.data(),Results.size()); + + HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), + Results.data(), Results.size()); } void Sema::CodeCompleteObjCPropertySynthesizeIvar(Scope *S, @@ -6753,10 +6729,9 @@ } Results.ExitScope(); - - HandleCodeCompleteResults(this, CodeCompleter, - CodeCompletionContext::CCC_Other, - Results.data(),Results.size()); + + HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), + Results.data(), Results.size()); } // Mapping from selectors to the methods that implement that selector, along @@ -7686,10 +7661,9 @@ } Results.ExitScope(); - - HandleCodeCompleteResults(this, CodeCompleter, - CodeCompletionContext::CCC_Other, - Results.data(),Results.size()); + + HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), + Results.data(), Results.size()); } void Sema::CodeCompleteObjCMethodDeclSelector(Scope *S, @@ -7776,9 +7750,8 @@ } } - HandleCodeCompleteResults(this, CodeCompleter, - CodeCompletionContext::CCC_Other, - Results.data(),Results.size()); + HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), + Results.data(), Results.size()); } void Sema::CodeCompletePreprocessorDirective(bool InConditional) { @@ -7934,9 +7907,8 @@ // FIXME: we don't support #assert or #unassert, so don't suggest them. Results.ExitScope(); - - HandleCodeCompleteResults(this, CodeCompleter, - CodeCompletionContext::CCC_PreprocessorDirective, + + HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), Results.data(), Results.size()); } @@ -7993,10 +7965,9 @@ Builder.AddChunk(CodeCompletionString::CK_RightParen); Results.AddResult(Builder.TakeString()); Results.ExitScope(); - - HandleCodeCompleteResults(this, CodeCompleter, - CodeCompletionContext::CCC_PreprocessorExpression, - Results.data(), Results.size()); + + HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), + Results.data(), Results.size()); } void Sema::CodeCompletePreprocessorMacroArgument(Scope *S, @@ -8028,9 +7999,8 @@ Twine(Platform) + "ApplicationExtension"))); } Results.ExitScope(); - HandleCodeCompleteResults(this, CodeCompleter, - CodeCompletionContext::CCC_Other, Results.data(), - Results.size()); + HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), + Results.data(), Results.size()); } void Sema::GatherGlobalCodeCompletions(CodeCompletionAllocator &Allocator, Index: unittests/Sema/CodeCompleteTest.cpp =================================================================== --- unittests/Sema/CodeCompleteTest.cpp +++ unittests/Sema/CodeCompleteTest.cpp @@ -131,4 +131,15 @@ EXPECT_TRUE(VisitedNS.empty()); } +TEST(SemaCodeCompleteTest, VisitedNSWithoutQualifier) { + auto VisitedNS = runCodeCompleteOnCode(R"cpp( + namespace n1 { + namespace n2 { + void f(^) {} + } + } + )cpp"); + EXPECT_THAT(VisitedNS, UnorderedElementsAre("n1", "n1::n2")); +} + } // namespace