[PATCH] D72874: [clangd] Add a textual fallback for go-to-definition

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 21 11:17:03 PST 2020


sammccall added a comment.

I've tried this out locally and it's fun! As suspected on the bug though, IMO it's far from accurate enough. Examples from clangd/Compiler.cpp:

- it triggers on almost every word, even words that plainly don't refer to any decl like `format [[lazily]], in case vlog is off`. This means that e.g. (in VSCode) the underline on ctrl-hover gives no/misleading signal. It also means that missing your target now jumps you somewhere random instead of doing nothing.
- when it works properly, the correct result usually mixed with incorrect results (e.g. `createInvocationFromCommandLine sets [[DisableFree]]`).
- it doesn't work for some symbols - ones that are not indexable (e.g. `RemappedFileBuffers will handle the lifetime of the [[Buffer]] pointer`, gives a variety of wrong results)

So while I want to stress this is really cool, it doesn't feel reliable on any dimension: you can't trust clangd on whether the word is an actual reference, you can't trust any particular result, and you can't trust the correct result is in the set.

Some suggestions:

- only trigger when there's *some* positive signal for the word.
  - Markup like quotes/backticks/brackets/`\p`
  - weird case like `lowerCamel`, `UpperCamel`, `CAPS`, `mid-sentence Capitalization`, `under_scores`.
  - use of the word as a token in nearby code (very close if very short, anywhere in file if longer)
  - (maybe you want to support `ns::Qualifiers`?)
- post-filter aggressively - only return exact name matches (I think including case).
- call `fuzzyFind` directly and set `ProximityPath` as well as the enclosing scopes from lexing. For extra strictness consider AnyScope=false
- if you get more than 3 results, and none from current file, maybe don't return anything, as confidence is too low. Or try a stricter query...
- handle the most common case of non-indexable symbols (local symbols) by running the query against the closest occurrence of the token in code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72874





More information about the cfe-commits mailing list