kbobyrev created this revision. kbobyrev added a reviewer: ioeric. kbobyrev added a project: clang-tools-extra. Herald added subscribers: kadircet, arphaman, jkorous, MaskRay.
`Dex` should utilize `FuzzyFindRequest.RestrictForCodeCompletion` flags and omit symbols not meant for code completion when asked for it. Results show that the average query time did not change significantly. Although, it might be faster/cleaner to have a single token and implement `NOT` iterator to append it on top smaller posting list. | | Before, ns | After, ns | Relative difference | | -------------------------------------------------------------------------- | ---------- | --------- | ------------------- | | Cumulative query latency (7000 `FuzzyFindRequest`s over LLVM static index) | 7270930798 | 7282297568 | +0.0015 | https://reviews.llvm.org/D52357 Files: clang-tools-extra/clangd/index/dex/Dex.cpp clang-tools-extra/unittests/clangd/DexTests.cpp Index: clang-tools-extra/unittests/clangd/DexTests.cpp =================================================================== --- clang-tools-extra/unittests/clangd/DexTests.cpp +++ clang-tools-extra/unittests/clangd/DexTests.cpp @@ -583,6 +583,23 @@ EXPECT_THAT(lookup(*I, SymbolID("ns::nonono")), UnorderedElementsAre()); } +TEST(DexTest, SymbolIndexOptionsFilter) { + auto CodeCompletionSymbol = symbol("Completion"); + auto NonCodeCompletionSymbol = symbol("NoCompletion"); + std::vector<Symbol> Symbols{CodeCompletionSymbol, NonCodeCompletionSymbol}; + Dex I(Symbols, URISchemes); + FuzzyFindRequest Req; + EXPECT_THAT(match(I, Req), ElementsAre("Completion", "NoCompletion")); + CodeCompletionSymbol.Flags = Symbol::SymbolFlag::IndexedForCodeCompletion; + NonCodeCompletionSymbol.Flags = Symbol::SymbolFlag::None; + Symbols = {CodeCompletionSymbol, NonCodeCompletionSymbol}; + I = Dex(Symbols, URISchemes); + Req.RestrictForCodeCompletion = true; + EXPECT_THAT(match(I, Req), ElementsAre("Completion")); + Req.RestrictForCodeCompletion = false; + EXPECT_THAT(match(I, Req), ElementsAre("NoCompletion")); +} + TEST(DexTest, ProximityPathsBoosting) { auto RootSymbol = symbol("root::abc"); RootSymbol.CanonicalDeclaration.FileURI = "unittest:///file.h"; Index: clang-tools-extra/clangd/index/dex/Dex.cpp =================================================================== --- clang-tools-extra/clangd/index/dex/Dex.cpp +++ clang-tools-extra/clangd/index/dex/Dex.cpp @@ -22,6 +22,11 @@ namespace { +static const Token RestrictedForCodeCompletion = + Token(Token::Kind::Sentinel, "Restricted For Code Completion"); +static const Token NotRestrictedForCodeCompletion = + Token(Token::Kind::Sentinel, "Not Restricted For Code Completion"); + // Returns the tokens which are given symbol's characteristics. Currently, the // generated tokens only contain fuzzy matching trigrams and symbol's scope, // but in the future this will also return path proximity tokens and other @@ -39,6 +44,9 @@ for (const auto &ProximityURI : generateProximityURIs(Sym.CanonicalDeclaration.FileURI)) Result.emplace_back(Token::Kind::ProximityURI, ProximityURI); + Result.emplace_back(Sym.Flags & Symbol::IndexedForCodeCompletion + ? RestrictedForCodeCompletion + : NotRestrictedForCodeCompletion); return Result; } @@ -119,7 +127,6 @@ for (const auto &Token : generateSearchTokens(*Sym)) TempInvertedIndex[Token].push_back(SymbolRank); } - // Convert lists of items to posting lists. for (const auto &TokenToPostingList : TempInvertedIndex) InvertedIndex.insert({TokenToPostingList.first, @@ -175,6 +182,13 @@ TopLevelChildren.push_back(createOr(move(BoostingIterators))); } + // Filter symbols which are (not) indexed for code completion. + TopLevelChildren.push_back(InvertedIndex + .find(Req.RestrictForCodeCompletion + ? RestrictedForCodeCompletion + : NotRestrictedForCodeCompletion) + ->second.iterator()); + // Use TRUE iterator if both trigrams and scopes from the query are not // present in the symbol index. auto QueryIterator = TopLevelChildren.empty()
Index: clang-tools-extra/unittests/clangd/DexTests.cpp =================================================================== --- clang-tools-extra/unittests/clangd/DexTests.cpp +++ clang-tools-extra/unittests/clangd/DexTests.cpp @@ -583,6 +583,23 @@ EXPECT_THAT(lookup(*I, SymbolID("ns::nonono")), UnorderedElementsAre()); } +TEST(DexTest, SymbolIndexOptionsFilter) { + auto CodeCompletionSymbol = symbol("Completion"); + auto NonCodeCompletionSymbol = symbol("NoCompletion"); + std::vector<Symbol> Symbols{CodeCompletionSymbol, NonCodeCompletionSymbol}; + Dex I(Symbols, URISchemes); + FuzzyFindRequest Req; + EXPECT_THAT(match(I, Req), ElementsAre("Completion", "NoCompletion")); + CodeCompletionSymbol.Flags = Symbol::SymbolFlag::IndexedForCodeCompletion; + NonCodeCompletionSymbol.Flags = Symbol::SymbolFlag::None; + Symbols = {CodeCompletionSymbol, NonCodeCompletionSymbol}; + I = Dex(Symbols, URISchemes); + Req.RestrictForCodeCompletion = true; + EXPECT_THAT(match(I, Req), ElementsAre("Completion")); + Req.RestrictForCodeCompletion = false; + EXPECT_THAT(match(I, Req), ElementsAre("NoCompletion")); +} + TEST(DexTest, ProximityPathsBoosting) { auto RootSymbol = symbol("root::abc"); RootSymbol.CanonicalDeclaration.FileURI = "unittest:///file.h"; Index: clang-tools-extra/clangd/index/dex/Dex.cpp =================================================================== --- clang-tools-extra/clangd/index/dex/Dex.cpp +++ clang-tools-extra/clangd/index/dex/Dex.cpp @@ -22,6 +22,11 @@ namespace { +static const Token RestrictedForCodeCompletion = + Token(Token::Kind::Sentinel, "Restricted For Code Completion"); +static const Token NotRestrictedForCodeCompletion = + Token(Token::Kind::Sentinel, "Not Restricted For Code Completion"); + // Returns the tokens which are given symbol's characteristics. Currently, the // generated tokens only contain fuzzy matching trigrams and symbol's scope, // but in the future this will also return path proximity tokens and other @@ -39,6 +44,9 @@ for (const auto &ProximityURI : generateProximityURIs(Sym.CanonicalDeclaration.FileURI)) Result.emplace_back(Token::Kind::ProximityURI, ProximityURI); + Result.emplace_back(Sym.Flags & Symbol::IndexedForCodeCompletion + ? RestrictedForCodeCompletion + : NotRestrictedForCodeCompletion); return Result; } @@ -119,7 +127,6 @@ for (const auto &Token : generateSearchTokens(*Sym)) TempInvertedIndex[Token].push_back(SymbolRank); } - // Convert lists of items to posting lists. for (const auto &TokenToPostingList : TempInvertedIndex) InvertedIndex.insert({TokenToPostingList.first, @@ -175,6 +182,13 @@ TopLevelChildren.push_back(createOr(move(BoostingIterators))); } + // Filter symbols which are (not) indexed for code completion. + TopLevelChildren.push_back(InvertedIndex + .find(Req.RestrictForCodeCompletion + ? RestrictedForCodeCompletion + : NotRestrictedForCodeCompletion) + ->second.iterator()); + // Use TRUE iterator if both trigrams and scopes from the query are not // present in the symbol index. auto QueryIterator = TopLevelChildren.empty()
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits