[PATCH] D75106: [clangd] Fix early selection for non-vardecl declarators
Kadir Cetinkaya via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 25 01:10:21 PST 2020
kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added subscribers: cfe-commits, usaxena95, arphaman, jkorous, MaskRay, ilya-biryukov.
Herald added a project: clang.
Selection tree was performing an early claim only for VarDecls, but
there are other cases where we can have declarators, e.g. FieldDecls. This patch
extends the early claim logic to all types of declarators.
Fixes https://github.com/clangd/clangd/issues/292
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D75106
Files:
clang-tools-extra/clangd/Selection.cpp
clang-tools-extra/clangd/unittests/SelectionTests.cpp
Index: clang-tools-extra/clangd/unittests/SelectionTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/SelectionTests.cpp
+++ clang-tools-extra/clangd/unittests/SelectionTests.cpp
@@ -369,6 +369,17 @@
int test(I *f) { return 42 + [[f.^foo]]; }
)cpp",
"ObjCPropertyRefExpr"},
+ {
+ R"cpp(
+ // We've got this nice trick, as annotation library eagerly selects
+ // the range and if we've got [32] below, there's no way to select
+ // the full range.
+ #define X [32]
+ struct foo {
+ [[int has^h X]];
+ };
+ )cpp",
+ "FieldDecl"},
};
for (const Case &C : Cases) {
Annotations Test(C.Code);
Index: clang-tools-extra/clangd/Selection.cpp
===================================================================
--- clang-tools-extra/clangd/Selection.cpp
+++ clang-tools-extra/clangd/Selection.cpp
@@ -10,6 +10,7 @@
#include "Logger.h"
#include "SourceCode.h"
#include "clang/AST/ASTTypeTraits.h"
+#include "clang/AST/Decl.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/Expr.h"
#include "clang/AST/ExprCXX.h"
@@ -602,12 +603,15 @@
// Usually empty, but sometimes children cover tokens but shouldn't own them.
SourceRange earlySourceRange(const DynTypedNode &N) {
if (const Decl *D = N.get<Decl>()) {
+ // FunctionDecl is also a DeclaratorDecl, but getLocation doesn't work for
+ // operator overloads, e.g. operator [[int]](); Therefore we handle them
+ // explicitly.
// void [[foo]]();
if (auto *FD = llvm::dyn_cast<FunctionDecl>(D))
return FD->getNameInfo().getSourceRange();
// int (*[[s]])();
- else if (auto *VD = llvm::dyn_cast<VarDecl>(D))
- return VD->getLocation();
+ if (auto *DD = llvm::dyn_cast<DeclaratorDecl>(D))
+ return DD->getLocation();
} else if (const auto* CCI = N.get<CXXCtorInitializer>()) {
// : [[b_]](42)
return CCI->getMemberLocation();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75106.246385.patch
Type: text/x-patch
Size: 2089 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200225/ebe56b25/attachment.bin>
More information about the cfe-commits
mailing list