forked from OSchip/llvm-project
[clangd] Also get scope for RK_pattern completion results.
For exmaple, clas field candidates in constructor initializers can be RK_Pattern, but they can still have scopes. llvm-svn: 337396
This commit is contained in:
parent
027a9fc2c5
commit
f433c2dab7
|
@ -270,12 +270,14 @@ struct CodeCompletionBuilder {
|
|||
if (C.SemaResult) {
|
||||
Completion.Origin |= SymbolOrigin::AST;
|
||||
Completion.Name = llvm::StringRef(SemaCCS->getTypedText());
|
||||
if (Completion.Scope.empty())
|
||||
if (C.SemaResult->Kind == CodeCompletionResult::RK_Declaration)
|
||||
if (Completion.Scope.empty()) {
|
||||
if ((C.SemaResult->Kind == CodeCompletionResult::RK_Declaration) ||
|
||||
(C.SemaResult->Kind == CodeCompletionResult::RK_Pattern))
|
||||
if (const auto *D = C.SemaResult->getDeclaration())
|
||||
if (const auto *ND = llvm::dyn_cast<NamedDecl>(D))
|
||||
Completion.Scope =
|
||||
splitQualifiedName(printQualifiedName(*ND)).first;
|
||||
}
|
||||
Completion.Kind =
|
||||
toCompletionItemKind(C.SemaResult->Kind, C.SemaResult->Declaration);
|
||||
}
|
||||
|
|
|
@ -1309,6 +1309,18 @@ TEST(CompletionTest, IgnoreRecoveryResults) {
|
|||
EXPECT_THAT(Results.Completions, UnorderedElementsAre(Named("NotRecovered")));
|
||||
}
|
||||
|
||||
TEST(CompletionTest, ScopeOfClassFieldInConstructorInitializer) {
|
||||
auto Results = completions(
|
||||
R"cpp(
|
||||
namespace ns {
|
||||
class X { public: X(); int x_; };
|
||||
X::X() : x_^(0) {}
|
||||
}
|
||||
)cpp");
|
||||
EXPECT_THAT(Results.Completions,
|
||||
UnorderedElementsAre(AllOf(Scope("ns::X::"), Named("x_"))));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace clangd
|
||||
} // namespace clang
|
||||
|
|
Loading…
Reference in New Issue