diff options
author | Ilya Biryukov <ibiryukov@google.com> | 2019-05-28 15:21:03 +0000 |
---|---|---|
committer | Ilya Biryukov <ibiryukov@google.com> | 2019-05-28 15:21:03 +0000 |
commit | adbb459ee00ba8b946135bf445109dd34b81d614 (patch) | |
tree | 1762b778a96cc3581de1724f3832a8cbaacda15d /lib | |
parent | ff610072dd570df36ae435896f74b1015f10e29b (diff) | |
download | clang-adbb459ee00ba8b946135bf445109dd34b81d614.tar.gz |
[CodeComplete] Set preferred type for qualified-id
Reviewers: kadircet
Reviewed By: kadircet
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D62514
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@361838 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Parse/ParseExprCXX.cpp | 5 | ||||
-rw-r--r-- | lib/Sema/SemaCodeComplete.cpp | 16 |
2 files changed, 15 insertions, 6 deletions
diff --git a/lib/Parse/ParseExprCXX.cpp b/lib/Parse/ParseExprCXX.cpp index 6173a6cd63..da39e2e223 100644 --- a/lib/Parse/ParseExprCXX.cpp +++ b/lib/Parse/ParseExprCXX.cpp @@ -232,13 +232,16 @@ bool Parser::ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS, HasScopeSpecifier = true; } + // Preferred type might change when parsing qualifiers, we need the original. + auto SavedType = PreferredType; while (true) { if (HasScopeSpecifier) { if (Tok.is(tok::code_completion)) { // Code completion for a nested-name-specifier, where the code // completion token follows the '::'. Actions.CodeCompleteQualifiedId(getCurScope(), SS, EnteringContext, - ObjectType.get()); + ObjectType.get(), + SavedType.get(SS.getBeginLoc())); // Include code completion token into the range of the scope otherwise // when we try to annotate the scope tokens the dangling code completion // token will cause assertion in diff --git a/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp index 3682dd0f4d..4f474032f6 100644 --- a/lib/Sema/SemaCodeComplete.cpp +++ b/lib/Sema/SemaCodeComplete.cpp @@ -5215,7 +5215,8 @@ void Sema::CodeCompleteAfterIf(Scope *S) { } void Sema::CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS, - bool EnteringContext, QualType BaseType) { + bool EnteringContext, QualType BaseType, + QualType PreferredType) { if (SS.isEmpty() || !CodeCompleter) return; @@ -5224,13 +5225,15 @@ void Sema::CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS, // it can be useful for global code completion which have information about // contexts/symbols that are not in the AST. if (SS.isInvalid()) { - CodeCompletionContext CC(CodeCompletionContext::CCC_Symbol); + CodeCompletionContext CC(CodeCompletionContext::CCC_Symbol, PreferredType); CC.setCXXScopeSpecifier(SS); // As SS is invalid, we try to collect accessible contexts from the current // scope with a dummy lookup so that the completion consumer can try to // guess what the specified scope is. ResultBuilder DummyResults(*this, CodeCompleter->getAllocator(), CodeCompleter->getCodeCompletionTUInfo(), CC); + if (!PreferredType.isNull()) + DummyResults.setPreferredType(PreferredType); if (S->getEntity()) { CodeCompletionDeclConsumer Consumer(DummyResults, S->getEntity(), BaseType); @@ -5253,9 +5256,12 @@ void Sema::CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS, if (!isDependentScopeSpecifier(SS) && RequireCompleteDeclContext(SS, Ctx)) return; - ResultBuilder Results(*this, CodeCompleter->getAllocator(), - CodeCompleter->getCodeCompletionTUInfo(), - CodeCompletionContext::CCC_Symbol); + ResultBuilder Results( + *this, CodeCompleter->getAllocator(), + CodeCompleter->getCodeCompletionTUInfo(), + CodeCompletionContext(CodeCompletionContext::CCC_Symbol, PreferredType)); + if (!PreferredType.isNull()) + Results.setPreferredType(PreferredType); Results.EnterNewScope(); // The "template" keyword can follow "::" in the grammar, but only |