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

Nathan Ridge via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 17 13:29:50 PDT 2020


nridge marked an inline comment as done.
nridge added inline comments.


================
Comment at: clang-tools-extra/clangd/XRefs.cpp:380
 
+  TokenFlavor Flavor = getTokenFlavor(Loc, SM, AST.getLangOpts());
+  // Only consider comment and (raw) identifier tokens.
----------------
nridge wrote:
> sammccall wrote:
> > 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.
> Hmm, I've tried this and `spelledTokenAt()` seems to return null for comment tokens.
It looks like there are two reasons for this:

  * The lexer that is producing the token buffer is using `inKeepCommentMode() == false`
  * `spelledTokenAt()` only returns a result if you give it the location at the beginning of the token, not something in the middle


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