[PATCH] D88814: [clangd] Enable partial namespace matches for workspace symbols

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 6 04:08:00 PDT 2020


sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.


================
Comment at: clang-tools-extra/clangd/FindSymbols.cpp:44
 
+// Returns true if \p Query can be found as a sub-scope inside \p Scope.
+bool approximateScopeMatch(llvm::StringRef Scope,
----------------
I had a little trouble following this...
It seems a little simpler (fewer vars to track) if we avoid the up-front split on scopes.

```
assert(Scope.empty() || Scope.endswith("::")); // or handle in some way
// Walk through Scope, consuming matching tokens from Query.
StringRef First;
while (!Scope.empty() && !Query.empty()) {
  tie(First, Scope) = Scope.split("::");
  if (Query.front() == First)
    Query = Query.drop_front();
}
return Query.empty(); // all components of query matched
```

in fact we can avoid preprocessing query too:

```
// Query is just a StringRef
assert(Scope.empty() || Scope.endswith("::")); // or handle in some way
assert(Query.empty() || Query.endswith("::"));

// Walk through Scope, consuming matching tokens from Query.
StringRef First;
while (!Scope.empty() && !Query.empty()) {
  tie(First, Scope) = Scope.split("::");
  Query.consume_front(StringRef(First.data(), First.size() + 2) /*Including ::*/);
}
return Query.empty(); // all components of query matched
```


================
Comment at: clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp:262
 
+TEST(WorkspaceSymbols, RankingPartilNamespace) {
+  TestTU TU;
----------------
Partil -> Partial


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88814/new/

https://reviews.llvm.org/D88814



More information about the cfe-commits mailing list