[clang-tools-extra] fc7a9f3 - [clangd] Ignore cvr-qualifiers in selection.
Sam McCall via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 13 06:08:56 PST 2022
Author: Sam McCall
Date: 2022-01-13T15:08:50+01:00
New Revision: fc7a9f36a9232794f8b5414347024b726954fe53
URL: https://github.com/llvm/llvm-project/commit/fc7a9f36a9232794f8b5414347024b726954fe53
DIFF: https://github.com/llvm/llvm-project/commit/fc7a9f36a9232794f8b5414347024b726954fe53.diff
LOG: [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
Added:
Modified:
clang-tools-extra/clangd/Selection.cpp
clang-tools-extra/clangd/unittests/SelectionTests.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/Selection.cpp b/clang-tools-extra/clangd/Selection.cpp
index f2403e03d7716..011e24ee70b2f 100644
--- a/clang-tools-extra/clangd/Selection.cpp
+++ b/clang-tools-extra/clangd/Selection.cpp
@@ -188,7 +188,19 @@ void update(SelectionTree::Selection &Result, SelectionTree::Selection New) {
// 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
diff --git a/clang-tools-extra/clangd/unittests/SelectionTests.cpp b/clang-tools-extra/clangd/unittests/SelectionTests.cpp
index 7e19f07a2215e..b3a0847c2a4a8 100644
--- a/clang-tools-extra/clangd/unittests/SelectionTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SelectionTests.cpp
@@ -331,9 +331,17 @@ TEST(SelectionTest, CommonAncestor) {
{"int (*getFunc([[do^uble]]))(int);", "BuiltinTypeLoc"},
+ // Member pointers and pack expansion use declarator syntax, but are
+ // restricted so they don't need special casing.
+ {"class X{}; [[int X::^*]]y[10];", "MemberPointerTypeLoc"},
+ {"template<typename ...T> void foo([[T*^...]]x);",
+ "PackExpansionTypeLoc"},
+ {"template<typename ...T> void foo([[^T]]*...x);",
+ "TemplateTypeParmTypeLoc"},
+
// FIXME: the AST has no location info for qualifiers.
{"const [[a^uto]] x = 42;", "AutoTypeLoc"},
- {"[[co^nst auto x = 42]];", "VarDecl"},
+ {"co^nst auto x = 42;", nullptr},
{"^", nullptr},
{"void foo() { [[foo^^]] (); }", "DeclRefExpr"},
More information about the cfe-commits
mailing list