Index: include/clang/Sema/CodeCompleteConsumer.h =================================================================== --- include/clang/Sema/CodeCompleteConsumer.h +++ include/clang/Sema/CodeCompleteConsumer.h @@ -29,6 +29,7 @@ namespace clang { class Decl; +class Scope; /// \brief Default priority values for code-completion results based /// on their kind. @@ -268,6 +269,14 @@ CCC_Recovery }; + struct QualifiedCompletionContext { + /// \brief The scope specifier that comes before the completion token e.g. + /// "a::b::" + CXXScopeSpec ScopeSpecifier; + /// \brief The closest scope where the qualified code completion occurs. + Scope *ClosestScope; + }; + private: enum Kind Kind; @@ -281,9 +290,9 @@ /// \brief The identifiers for Objective-C selector parts. ArrayRef SelIdents; - /// \brief The scope specifier that comes before the completion token e.g. - /// "a::b::" - llvm::Optional ScopeSpecifier; + /// \brief The context for qualified-id completion, containing information + /// about the scope specifier. + llvm::Optional QualifiedCC; public: /// \brief Construct a new code-completion context of the given kind. @@ -321,16 +330,17 @@ /// context. bool wantConstructorResults() const; - /// \brief Sets the scope specifier that comes before the completion token. - /// This is expected to be set in code completions on qualfied specifiers + /// \brief Sets the qualified context. + /// This is expected to be set in code completions on qualified specifiers /// (e.g. "a::b::"). - void setCXXScopeSpecifier(CXXScopeSpec SS) { - this->ScopeSpecifier = std::move(SS); + void setQualifiedCompletionContext(QualifiedCompletionContext QCC) { + this->QualifiedCC = std::move(QCC); } - llvm::Optional getCXXScopeSpecifier() { - if (ScopeSpecifier) - return ScopeSpecifier.getPointer(); + llvm::Optional + getQualifiedCompletionContext() const { + if (QualifiedCC) + return QualifiedCC.getPointer(); return llvm::None; } }; Index: lib/Sema/SemaCodeComplete.cpp =================================================================== --- lib/Sema/SemaCodeComplete.cpp +++ lib/Sema/SemaCodeComplete.cpp @@ -4618,7 +4618,7 @@ // contexts/symbols that are not in the AST. if (SS.isInvalid()) { CodeCompletionContext CC(CodeCompletionContext::CCC_Name); - CC.setCXXScopeSpecifier(SS); + CC.setQualifiedCompletionContext({SS, S}); HandleCodeCompleteResults(this, CodeCompleter, CC, nullptr, 0); return; } @@ -4663,7 +4663,7 @@ } auto CC = Results.getCompletionContext(); - CC.setCXXScopeSpecifier(SS); + CC.setQualifiedCompletionContext({SS, S}); HandleCodeCompleteResults(this, CodeCompleter, CC, Results.data(), Results.size());