[PATCH] D54105: [clangd] Deduplicate query scopes.
Eric Liu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 6 03:21:29 PST 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rL346224: [clangd] Deduplicate query scopes. (authored by ioeric, committed by ).
Herald added a subscriber: llvm-commits.
Repository:
rL LLVM
https://reviews.llvm.org/D54105
Files:
clang-tools-extra/trunk/clangd/CodeComplete.cpp
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
Index: clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
===================================================================
--- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
+++ clang-tools-extra/trunk/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: clang-tools-extra/trunk/clangd/CodeComplete.cpp
===================================================================
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp
@@ -541,16 +541,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.172739.patch
Type: text/x-patch
Size: 1976 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181106/62a697f8/attachment.bin>
More information about the cfe-commits
mailing list