[PATCH] D97773: [clangd] Make WorkspaceSymbols request work with empty queries

Kadir Cetinkaya via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 2 07:49:57 PST 2021


kadircet created this revision.
kadircet added a reviewer: hokein.
Herald added subscribers: usaxena95, arphaman.
kadircet requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang.

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.

Fixes https://github.com/clangd/clangd/issues/707.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97773

Files:
  clang-tools-extra/clangd/FindSymbols.cpp
  clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp


Index: clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
+++ clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
@@ -216,7 +216,9 @@
                   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) {
Index: clang-tools-extra/clangd/FindSymbols.cpp
===================================================================
--- clang-tools-extra/clangd/FindSymbols.cpp
+++ clang-tools-extra/clangd/FindSymbols.cpp
@@ -88,7 +88,7 @@
 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:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97773.327455.patch
Type: text/x-patch
Size: 1258 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210302/156fd6f5/attachment.bin>


More information about the cfe-commits mailing list