diff options
author | Eric Liu <ioeric@google.com> | 2018-11-06 11:17:40 +0000 |
---|---|---|
committer | Eric Liu <ioeric@google.com> | 2018-11-06 11:17:40 +0000 |
commit | abbd713eb7417f3638541b75b8aff051d2f48377 (patch) | |
tree | 9b2d340627ba164821bbfa22a439390655049f00 | |
parent | b04869a4aa42a7716a552daa0caa53282233628b (diff) | |
download | llvm-abbd713eb7417f3638541b75b8aff051d2f48377.zip llvm-abbd713eb7417f3638541b75b8aff051d2f48377.tar.gz llvm-abbd713eb7417f3638541b75b8aff051d2f48377.tar.bz2 |
[clangd] Deduplicate query scopes.
Summary:
For example, when anonymous namespace is present, duplicated namespaces might be
generated for the enclosing namespace.
Reviewers: ilya-biryukov
Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D54105
llvm-svn: 346224
-rw-r--r-- | clang-tools-extra/clangd/CodeComplete.cpp | 14 | ||||
-rw-r--r-- | clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp | 17 |
2 files changed, 23 insertions, 8 deletions
diff --git a/clang-tools-extra/clangd/CodeComplete.cpp b/clang-tools-extra/clangd/CodeComplete.cpp index fec91e1..c79f017 100644 --- a/clang-tools-extra/clangd/CodeComplete.cpp +++ b/clang-tools-extra/clangd/CodeComplete.cpp @@ -541,16 +541,14 @@ struct SpecifiedScope { // Set if the qualifier is not fully resolved by Sema. Optional<std::string> UnresolvedQualifier; - // Construct scopes being queried in indexes. + // Construct scopes being queried in indexes. The results are deduplicated. // This method format the scopes to match the index request representation. std::vector<std::string> scopesForIndexQuery() { - std::vector<std::string> Results; - for (StringRef AS : AccessibleScopes) { - Results.push_back(AS); - if (UnresolvedQualifier) - Results.back() += *UnresolvedQualifier; - } - return Results; + std::set<std::string> Results; + for (StringRef AS : AccessibleScopes) + Results.insert( + ((UnresolvedQualifier ? *UnresolvedQualifier : "") + AS).str()); + return {Results.begin(), Results.end()}; } }; diff --git a/clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp b/clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp index 3e60b62..03a0f59 100644 --- a/clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp +++ b/clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp @@ -1142,6 +1142,23 @@ TEST(CompletionTest, GlobalQualifiedQuery) { UnorderedElementsAre("")))); } +TEST(CompletionTest, NoDuplicatedQueryScopes) { + auto Requests = captureIndexRequests(R"cpp( + namespace {} + + namespace na { + namespace {} + namespace nb { + ^ + } // namespace nb + } // namespace na + )cpp"); + + EXPECT_THAT(Requests, + ElementsAre(Field(&FuzzyFindRequest::Scopes, + UnorderedElementsAre("na::", "na::nb::", "")))); +} + TEST(CompletionTest, NoIndexCompletionsInsideClasses) { auto Completions = completions( R"cpp( |