diff options
author | Eric Liu <ioeric@google.com> | 2018-11-06 11:08:17 +0000 |
---|---|---|
committer | Eric Liu <ioeric@google.com> | 2018-11-06 11:08:17 +0000 |
commit | b04869a4aa42a7716a552daa0caa53282233628b (patch) | |
tree | c231fdde4b968249101ad1b1226e7476a632589b | |
parent | cc297272c708d6a3223453efe3a82645016d4e71 (diff) | |
download | llvm-b04869a4aa42a7716a552daa0caa53282233628b.zip llvm-b04869a4aa42a7716a552daa0caa53282233628b.tar.gz llvm-b04869a4aa42a7716a552daa0caa53282233628b.tar.bz2 |
[clangd] Get rid of QueryScopes.empty() == AnyScope special case.
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D53933
llvm-svn: 346223
-rw-r--r-- | clang-tools-extra/clangd/FindSymbols.cpp | 2 | ||||
-rw-r--r-- | clang-tools-extra/clangd/index/Index.h | 3 | ||||
-rw-r--r-- | clang-tools-extra/clangd/index/MemIndex.cpp | 3 | ||||
-rw-r--r-- | clang-tools-extra/clangd/index/dex/Dex.cpp | 2 | ||||
-rw-r--r-- | clang-tools-extra/unittests/clangd/DexTests.cpp | 9 | ||||
-rw-r--r-- | clang-tools-extra/unittests/clangd/IndexTests.cpp | 4 | ||||
-rw-r--r-- | clang-tools-extra/unittests/clangd/SyncAPI.cpp | 1 |
7 files changed, 17 insertions, 7 deletions
diff --git a/clang-tools-extra/clangd/FindSymbols.cpp b/clang-tools-extra/clangd/FindSymbols.cpp index f6d3cf5..64a0896 100644 --- a/clang-tools-extra/clangd/FindSymbols.cpp +++ b/clang-tools-extra/clangd/FindSymbols.cpp @@ -116,6 +116,8 @@ getWorkspaceSymbols(StringRef Query, int Limit, const SymbolIndex *const Index, // not). if (IsGlobalQuery || !Names.first.empty()) Req.Scopes = {Names.first}; + else + Req.AnyScope = true; if (Limit) Req.Limit = Limit; TopN<ScoredSymbolInfo, ScoredSymbolGreater> Top( diff --git a/clang-tools-extra/clangd/index/Index.h b/clang-tools-extra/clangd/index/Index.h index b5d78096..76148f1 100644 --- a/clang-tools-extra/clangd/index/Index.h +++ b/clang-tools-extra/clangd/index/Index.h @@ -460,9 +460,6 @@ struct FuzzyFindRequest { /// namespace xyz::abc. /// /// The global scope is "", a top level scope is "foo::", etc. - /// FIXME: drop the special case for empty list, which is the same as - /// `AnyScope = true`. - /// FIXME: support scope proximity. std::vector<std::string> Scopes; /// If set to true, allow symbols from any scope. Scopes explicitly listed /// above will be ranked higher. diff --git a/clang-tools-extra/clangd/index/MemIndex.cpp b/clang-tools-extra/clangd/index/MemIndex.cpp index 5c124878..42340e8 100644 --- a/clang-tools-extra/clangd/index/MemIndex.cpp +++ b/clang-tools-extra/clangd/index/MemIndex.cpp @@ -39,8 +39,7 @@ bool MemIndex::fuzzyFind(const FuzzyFindRequest &Req, const Symbol *Sym = Pair.second; // Exact match against all possible scopes. - if (!Req.AnyScope && !Req.Scopes.empty() && - !is_contained(Req.Scopes, Sym->Scope)) + if (!Req.AnyScope && !is_contained(Req.Scopes, Sym->Scope)) continue; if (Req.RestrictForCodeCompletion && !(Sym->Flags & Symbol::IndexedForCodeCompletion)) diff --git a/clang-tools-extra/clangd/index/dex/Dex.cpp b/clang-tools-extra/clangd/index/dex/Dex.cpp index 9dab722..ba6c325 100644 --- a/clang-tools-extra/clangd/index/dex/Dex.cpp +++ b/clang-tools-extra/clangd/index/dex/Dex.cpp @@ -178,7 +178,7 @@ bool Dex::fuzzyFind(const FuzzyFindRequest &Req, std::vector<std::unique_ptr<Iterator>> ScopeIterators; for (const auto &Scope : Req.Scopes) ScopeIterators.push_back(iterator(Token(Token::Kind::Scope, Scope))); - if (Req.AnyScope || /*legacy*/ Req.Scopes.empty()) + if (Req.AnyScope) ScopeIterators.push_back( Corpus.boost(Corpus.all(), ScopeIterators.empty() ? 1.0 : 0.2)); Criteria.push_back(Corpus.unionOf(move(ScopeIterators))); diff --git a/clang-tools-extra/unittests/clangd/DexTests.cpp b/clang-tools-extra/unittests/clangd/DexTests.cpp index 450d7e8..6bf8111 100644 --- a/clang-tools-extra/unittests/clangd/DexTests.cpp +++ b/clang-tools-extra/unittests/clangd/DexTests.cpp @@ -485,6 +485,7 @@ TEST(Dex, FuzzyFind) { UnorderedElementsAre("other::A", "other::ABC")); Req.Query = ""; Req.Scopes = {}; + Req.AnyScope = true; EXPECT_THAT(match(*Index, Req), UnorderedElementsAre("ns::ABC", "ns::BCD", "::ABC", "ns::nested::ABC", "other::ABC", @@ -495,6 +496,7 @@ TEST(DexTest, DexLimitedNumMatches) { auto I = Dex::build(generateNumSymbols(0, 100), RefSlab(), URISchemes); FuzzyFindRequest Req; Req.Query = "5"; + Req.AnyScope = true; Req.Limit = 3; bool Incomplete; auto Matches = match(*I, Req, &Incomplete); @@ -509,6 +511,7 @@ TEST(DexTest, FuzzyMatch) { RefSlab(), URISchemes); FuzzyFindRequest Req; Req.Query = "lol"; + Req.AnyScope = true; Req.Limit = 2; EXPECT_THAT(match(*I, Req), UnorderedElementsAre("LaughingOutLoud", "LittleOldLady")); @@ -518,6 +521,7 @@ TEST(DexTest, ShortQuery) { auto I = Dex::build(generateSymbols({"OneTwoThreeFour"}), RefSlab(), URISchemes); FuzzyFindRequest Req; + Req.AnyScope = true; bool Incomplete; EXPECT_THAT(match(*I, Req, &Incomplete), ElementsAre("OneTwoThreeFour")); @@ -540,6 +544,7 @@ TEST(DexTest, MatchQualifiedNamesWithoutSpecificScope) { auto I = Dex::build(generateSymbols({"a::y1", "b::y2", "y3"}), RefSlab(), URISchemes); FuzzyFindRequest Req; + Req.AnyScope = true; Req.Query = "y"; EXPECT_THAT(match(*I, Req), UnorderedElementsAre("a::y1", "b::y2", "y3")); } @@ -584,9 +589,9 @@ TEST(DexTest, WildcardScope) { auto I = Dex::build(generateSymbols({"a::y1", "a::b::y2", "c::y3"}), RefSlab(), URISchemes); FuzzyFindRequest Req; + Req.AnyScope = true; Req.Query = "y"; Req.Scopes = {"a::"}; - Req.AnyScope = true; EXPECT_THAT(match(*I, Req), UnorderedElementsAre("a::y1", "a::b::y2", "c::y3")); } @@ -626,6 +631,7 @@ TEST(DexTest, SymbolIndexOptionsFilter) { std::vector<Symbol> Symbols{CodeCompletionSymbol, NonCodeCompletionSymbol}; Dex I(Symbols, RefSlab(), URISchemes); FuzzyFindRequest Req; + Req.AnyScope = true; Req.RestrictForCodeCompletion = false; EXPECT_THAT(match(I, Req), ElementsAre("Completion", "NoCompletion")); Req.RestrictForCodeCompletion = true; @@ -642,6 +648,7 @@ TEST(DexTest, ProximityPathsBoosting) { Dex I(Symbols, RefSlab(), URISchemes); FuzzyFindRequest Req; + Req.AnyScope = true; Req.Query = "abc"; // The best candidate can change depending on the proximity paths. Req.Limit = 1; diff --git a/clang-tools-extra/unittests/clangd/IndexTests.cpp b/clang-tools-extra/unittests/clangd/IndexTests.cpp index 77b59c1..286941b 100644 --- a/clang-tools-extra/unittests/clangd/IndexTests.cpp +++ b/clang-tools-extra/unittests/clangd/IndexTests.cpp @@ -90,6 +90,7 @@ TEST(MemIndexTest, MemIndexDeduplicate) { symbol("2") /* duplicate */}; FuzzyFindRequest Req; Req.Query = "2"; + Req.AnyScope = true; MemIndex I(Symbols, RefSlab()); EXPECT_THAT(match(I, Req), ElementsAre("2")); } @@ -98,6 +99,7 @@ TEST(MemIndexTest, MemIndexLimitedNumMatches) { auto I = MemIndex::build(generateNumSymbols(0, 100), RefSlab()); FuzzyFindRequest Req; Req.Query = "5"; + Req.AnyScope = true; Req.Limit = 3; bool Incomplete; auto Matches = match(*I, Req, &Incomplete); @@ -112,6 +114,7 @@ TEST(MemIndexTest, FuzzyMatch) { RefSlab()); FuzzyFindRequest Req; Req.Query = "lol"; + Req.AnyScope = true; Req.Limit = 2; EXPECT_THAT(match(*I, Req), UnorderedElementsAre("LaughingOutLoud", "LittleOldLady")); @@ -122,6 +125,7 @@ TEST(MemIndexTest, MatchQualifiedNamesWithoutSpecificScope) { MemIndex::build(generateSymbols({"a::y1", "b::y2", "y3"}), RefSlab()); FuzzyFindRequest Req; Req.Query = "y"; + Req.AnyScope = true; EXPECT_THAT(match(*I, Req), UnorderedElementsAre("a::y1", "b::y2", "y3")); } diff --git a/clang-tools-extra/unittests/clangd/SyncAPI.cpp b/clang-tools-extra/unittests/clangd/SyncAPI.cpp index 019bba0..dd6f37c 100644 --- a/clang-tools-extra/unittests/clangd/SyncAPI.cpp +++ b/clang-tools-extra/unittests/clangd/SyncAPI.cpp @@ -130,6 +130,7 @@ runDocumentSymbols(ClangdServer &Server, PathRef File) { SymbolSlab runFuzzyFind(const SymbolIndex &Index, StringRef Query) { FuzzyFindRequest Req; Req.Query = Query; + Req.AnyScope = true; return runFuzzyFind(Index, Req); } |