Skip to content

Commit 206740e

Browse files
author
Eric Liu
committedFeb 21, 2019
[CodeComplete] Collect visited contexts when scope specifier is invalid.
Summary: This will allow completion consumers to guess the specified scope by putting together scopes in the context with the specified scope (e.g. when the specified namespace is not imported yet). Reviewers: ilya-biryukov Subscribers: jdoerfert, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D58446 llvm-svn: 354570
1 parent 7a183a8 commit 206740e

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed
 

‎clang/lib/Sema/SemaCodeComplete.cpp

+14-1
Original file line numberDiff line numberDiff line change
@@ -5061,7 +5061,20 @@ void Sema::CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS,
50615061
if (SS.isInvalid()) {
50625062
CodeCompletionContext CC(CodeCompletionContext::CCC_Symbol);
50635063
CC.setCXXScopeSpecifier(SS);
5064-
HandleCodeCompleteResults(this, CodeCompleter, CC, nullptr, 0);
5064+
// As SS is invalid, we try to collect accessible contexts from the current
5065+
// scope with a dummy lookup so that the completion consumer can try to
5066+
// guess what the specified scope is.
5067+
ResultBuilder DummyResults(*this, CodeCompleter->getAllocator(),
5068+
CodeCompleter->getCodeCompletionTUInfo(), CC);
5069+
if (S->getEntity()) {
5070+
CodeCompletionDeclConsumer Consumer(DummyResults, S->getEntity(),
5071+
BaseType);
5072+
LookupVisibleDecls(S, LookupOrdinaryName, Consumer,
5073+
/*IncludeGlobalScope=*/false,
5074+
/*LoadExternal=*/false);
5075+
}
5076+
HandleCodeCompleteResults(this, CodeCompleter,
5077+
DummyResults.getCompletionContext(), nullptr, 0);
50655078
return;
50665079
}
50675080
// Always pretend to enter a context to ensure that a dependent type

‎clang/unittests/Sema/CodeCompleteTest.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,16 @@ TEST(SemaCodeCompleteTest, VisitedNSForValidQualifiedId) {
173173
"foo::(anonymous)"));
174174
}
175175

176-
TEST(SemaCodeCompleteTest, VisitedNSForInvalideQualifiedId) {
176+
TEST(SemaCodeCompleteTest, VisitedNSForInvalidQualifiedId) {
177177
auto VisitedNS = runCodeCompleteOnCode(R"cpp(
178-
namespace ns { foo::^ }
178+
namespace na {}
179+
namespace ns1 {
180+
using namespace na;
181+
foo::^
182+
}
179183
)cpp")
180184
.VisitedNamespaces;
181-
EXPECT_TRUE(VisitedNS.empty());
185+
EXPECT_THAT(VisitedNS, UnorderedElementsAre("ns1", "na"));
182186
}
183187

184188
TEST(SemaCodeCompleteTest, VisitedNSWithoutQualifier) {

0 commit comments

Comments
 (0)