[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
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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D65486

Files:
  clang-tools-extra/clangd/Selection.cpp
  clang-tools-extra/clangd/Selection.h
  clang-tools-extra/clangd/refactor/Tweak.cpp
  clang-tools-extra/clangd/unittests/SelectionTests.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65486.212460.patch
Type: text/x-patch
Size: 14736 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190730/fde740b7/attachment.bin>


More information about the cfe-commits mailing list