[clangd] Make WorkspaceSymbols request work with empty queries

Clangd uses codecompletion limit as the limit for workspacesymbols, so
in theory this should only be an order of magnitude slower than a
codecompletion request with empty identifier (as code completion limits
the available symbols).

This is also what LSP suggests "Clients may send an empty string here to request all symbols.".
Clangd doesn't really fulfill the "all" part of that statement, but we
never do unless user set the index query limit to zero explicitly.

Differential Revision: https://reviews.llvm.org/D97773
This commit is contained in:
Kadir Cetinkaya 2021-03-02 16:43:21 +01:00
parent 15f495c0bc
commit 188373fb46
No known key found for this signature in database
GPG Key ID: E39E36B8D2057ED6
2 changed files with 4 additions and 2 deletions

View File

@ -88,7 +88,7 @@ llvm::Expected<std::vector<SymbolInformation>>
getWorkspaceSymbols(llvm::StringRef Query, int Limit,
const SymbolIndex *const Index, llvm::StringRef HintPath) {
std::vector<SymbolInformation> Result;
if (Query.empty() || !Index)
if (!Index)
return Result;
// Lookup for qualified names are performed as:

View File

@ -216,7 +216,9 @@ TEST(WorkspaceSymbols, GlobalNamespaceQueries) {
AllOf(QName("foo"), WithKind(SymbolKind::Function)),
AllOf(QName("ns"), WithKind(SymbolKind::Namespace))));
EXPECT_THAT(getSymbols(TU, ":"), IsEmpty());
EXPECT_THAT(getSymbols(TU, ""), IsEmpty());
EXPECT_THAT(getSymbols(TU, ""),
UnorderedElementsAre(QName("foo"), QName("Foo"), QName("Foo::a"),
QName("ns"), QName("ns::foo2")));
}
TEST(WorkspaceSymbols, Enums) {