[PATCH] D54105: [clangd] Deduplicate query scopes.
Eric Liu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 5 07:54:25 PST 2018
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()};
}
};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54105.172590.patch
Type: text/x-patch
Size: 1832 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181105/d5dd5abe/attachment-0001.bin>
More information about the cfe-commits
mailing list