[PATCH] D65486: [clangd] Ignore semicolons, whitespace, and comments in SelectionTree.
Sam McCall via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 30 15:53:43 PDT 2019
sammccall created this revision.
sammccall added reviewers: SureYeaah, kadircet.
Herald added subscribers: cfe-commits, arphaman, jkorous, MaskRay.
Herald added a project: clang.
Whitespace and comments are a clear bugfix: selecting some
comments/space near a statement doesn't mean you're selecting the
Semicolons are less obvious, but for similar reasons: these tokens
aren't actually claimed by any AST node (usually), so an AST-based model
like SelectionTree shouldn't take them into account.
Callers may still sometimes care about semis of course:
- when the selection is an expr with a non-expr parent, selection of the semicolon indicates intent to select the statement.
- when a statement with a trailing semi is selected, we need to know its range to ensure it can be removed.
SelectionTree may or may not play a role here, but these are separate questions
from its core function of describing which AST nodes were selected.
The mechanism here is the TokenBuffer from syntax-trees. We use it in a
fairly low-level way (just to get boundaries of raw spelled tokens). The
actual mapping of AST nodes to coordinates continues to use the (fairly
mature) SourceLocation based logic. TokenBuffer/Syntax trees
don't currently offer an alternative to getFileRange(), I think.
rG LLVM Github Monorepo
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 14736 bytes
Desc: not available
More information about the cfe-commits