ioeric created this revision. ioeric added a reviewer: ilya-biryukov. Herald added subscribers: cfe-commits, kadircet, arphaman, jkorous, MaskRay.
For example, when anonymous namespace is present, duplicated namespaces might be generated for the enclosing namespace. Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D54105 Files: clangd/CodeComplete.cpp unittests/clangd/CodeCompleteTests.cpp Index: unittests/clangd/CodeCompleteTests.cpp =================================================================== --- unittests/clangd/CodeCompleteTests.cpp +++ unittests/clangd/CodeCompleteTests.cpp @@ -1142,6 +1142,23 @@ 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( Index: clangd/CodeComplete.cpp =================================================================== --- clangd/CodeComplete.cpp +++ clangd/CodeComplete.cpp @@ -538,16 +538,14 @@ // 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()}; } };
Index: unittests/clangd/CodeCompleteTests.cpp =================================================================== --- unittests/clangd/CodeCompleteTests.cpp +++ unittests/clangd/CodeCompleteTests.cpp @@ -1142,6 +1142,23 @@ 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( Index: clangd/CodeComplete.cpp =================================================================== --- clangd/CodeComplete.cpp +++ clangd/CodeComplete.cpp @@ -538,16 +538,14 @@ // 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()}; } };
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits