[PATCH] D76098: [WIP] [clangd] Do not trigger go-to-def textual fallback inside string literals

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 16 04:35:40 PDT 2020


sammccall added inline comments.


================
Comment at: clang-tools-extra/clangd/XRefs.cpp:360
+
+TokenFlavor getTokenFlavor(SourceLocation Loc, const SourceManager &SM,
+                           const LangOptions &LangOpts) {
----------------
I don't think we need this function, which just maps one enum onto another - just use the token kind directly?


================
Comment at: clang-tools-extra/clangd/XRefs.cpp:380
 
+  TokenFlavor Flavor = getTokenFlavor(Loc, SM, AST.getLangOpts());
+  // Only consider comment and (raw) identifier tokens.
----------------
kadircet wrote:
> you can rather use `AST.getTokens().spelledTokenAt(Loc)` to get preprocessed token, and pass that into getTokenFlavor rather than a SourceLocation.
for a bit more context: running Lexer::getRawToken runs a raw lex that only sees the piece of text you point at. If you're inside a huge comment, it won't know that.

Using AST.getTokens() uses the results of an earlier raw lex of the whole file.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76098





More information about the cfe-commits mailing list