[clangd] Ignore cvr-qualifiers in selection.
The AST doesn't track their locations, and the default behavior of attributing
them to the lexically-enclosing node is sloppy and often inaccurate.
Also add a couple of passing test cases for declarators that weren't obvious.
Differential Revision: https://reviews.llvm.org/D117185
diff --git a/clang-tools-extra/clangd/Selection.cpp b/clang-tools-extra/clangd/Selection.cpp
index f2403e0..011e24e 100644
--- a/clang-tools-extra/clangd/Selection.cpp
+++ b/clang-tools-extra/clangd/Selection.cpp
@@ -188,7 +188,19 @@
// As well as comments, don't count semicolons as real tokens.
// They're not properly claimed as expr-statement is missing from the AST.
bool shouldIgnore(const syntax::Token &Tok) {
- return Tok.kind() == tok::comment || Tok.kind() == tok::semi;
+ switch (Tok.kind()) {
+ // Even "attached" comments are not considered part of a node's range.
+ case tok::comment:
+ // The AST doesn't directly store locations for terminating semicolons.
+ case tok::semi:
+ // We don't have locations for cvr-qualifiers: see QualifiedTypeLoc.
+ case tok::kw_const:
+ case tok::kw_volatile:
+ case tok::kw_restrict:
+ return true;
+ default:
+ return false;
+ }
}
// Determine whether 'Target' is the first expansion of the macro