llvm-project/clang-tools-extra/clangd/refactor
Sam McCall abe3c29a8c [clangd] Ignore semicolons, whitespace, and comments in SelectionTree.
Summary:
Whitespace and comments are a clear bugfix: selecting some
comments/space near a statement doesn't mean you're selecting the
surrounding block.

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.

Reviewers: SureYeaah, kadircet

Subscribers: MaskRay, jkorous, arphaman, cfe-commits, ilya-biryukov

Tags: #clang

Differential Revision: https://reviews.llvm.org/D65486

llvm-svn: 367453
2019-07-31 17:52:40 +00:00
..
tweaks [clangd] Fix a regression in rL366996. 2019-07-30 14:17:45 +00:00
Rename.cpp [clangd] cleanup: unify the implemenation of checking a location is inside main file. 2019-07-19 08:33:39 +00:00
Rename.h [clangd] Narrow rename to local symbols. 2019-06-25 08:43:17 +00:00
Tweak.cpp [clangd] Ignore semicolons, whitespace, and comments in SelectionTree. 2019-07-31 17:52:40 +00:00
Tweak.h [Clangd] Changed ExtractVariable to only work on non empty selections 2019-07-18 15:38:03 +00:00