[PATCH] D69615: [clangd] Implement a function to lex the file to find candidate occurrences.

Ilya Biryukov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 5 10:10:49 PST 2019


ilya-biryukov accepted this revision.
ilya-biryukov added inline comments.
This revision is now accepted and ready to land.


================
Comment at: clang-tools-extra/clangd/SourceCode.cpp:757
+  lex(Content, LangOpts, [&](const clang::Token &Tok, const SourceManager &SM) {
+    if (Tok.getKind() == tok::raw_identifier)
+      if (Tok.getRawIdentifier() == Identifier)
----------------
NIT: [[ https://llvm.org/docs/CodingStandards.html#use-early-exits-and-continue-to-simplify-code | use early exits ]] to keep the code flat.
```
if (Tok.getKind() != ...)
  return;
auto Range = ...;
if (!Range)
  return;
...
```


================
Comment at: clang-tools-extra/clangd/unittests/SourceCodeTests.cpp:690
+   void f() {
+     [[Foo]] foo;
+   }
----------------
hokein wrote:
> ilya-biryukov wrote:
> > Could you add a few more occurrences?
> > Maybe also with the weird things like multi-line tokens:
> > ```
> > F\
> > o\
> > o
> > ```
> Done, note that multi-line identifier is not supported -- `getRawIdentifier` returns a literal name `F\o\o` which makes the check `Tok.getRawIdentifier() == Identifier` fail. I think it is fine to not support it.
Yeah, it's probably ok.
I'd still add this as a test-case to make sure we don't crash and fix the behavior.

Although agree it's not very important, this is super rare.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69615





More information about the cfe-commits mailing list