[PATCH] D72874: [clangd] Add a textual fallback for go-to-definition
Sam McCall via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 2 10:21:01 PST 2020
sammccall added inline comments.
================
Comment at: clang-tools-extra/clangd/SourceCode.cpp:313
SourceLocation getBeginningOfIdentifier(const Position &Pos,
const SourceManager &SM,
----------------
sammccall wrote:
> @kadircet is working on getting rid of this function because creating raw lexers is is wasteful and not actually very powerful. Mostly we're moving to syntax::TokenBuffer, which records actual lexed tokens, but that doesn't apply here.
>
> The examples in the tests seem like they'd be covered by something *really* simple, like enclosing identifier chars:
>
> ```
> unsigned Begin, End;
> for (Begin = Offset; Begin > 0 && isIdentifierBody(Code[Begin-1]); --BeginEnd) {}
> for (End = Offset; End < Code.size() && isIdentifierBody(Code[End]); ++End) {}
> return Code.slice(Begin, End);
> ```
>
> (Lexer::isIdentifierBodyChar requires langopts but just passes through DollarIdents to isIdentifierBody, and I don't think we care much about identifiers with $ in them.)
>
> If we really want to do something more subtle here, we should check it in SourceCodeTests.
> Mostly we're moving to syntax::TokenBuffer, which records actual lexed tokens, but that doesn't apply here.
Oops, this isn't true - token buffer's expanded token stream has "real" tokens, but the spelled token streams use the raw lexer. You can just use spelledIdentifierTouching(), I think.
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