[PATCH] D72867: [clangd] Support renaming designated initializers
Kirill Bobyrev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 16 12:57:02 PST 2020
kbobyrev created this revision.
kbobyrev added a reviewer: sammccall.
Herald added subscribers: usaxena95, kadircet, arphaman, jkorous, MaskRay, ilya-biryukov.
Herald added a project: clang.
kbobyrev updated this revision to Diff 238586.
kbobyrev added a comment.
Remove duplicated testt
Clangd does not find references of designated iniitializers yet and, as a
result, is unable to rename such references. This patch addresses this issue.
Resolves: https://github.com/clangd/clangd/issues/247
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D72867
Files:
clang-tools-extra/clangd/FindTarget.cpp
clang-tools-extra/clangd/unittests/FindTargetTests.cpp
clang-tools-extra/clangd/unittests/RenameTests.cpp
Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -403,6 +403,14 @@
template <template<typename> class Z> struct Bar { };
template <> struct Bar<[[Foo]]> {};
)cpp",
+
+ // Designated initializer.
+ R"cpp(
+ struct Bar {
+ int [[Fo^o]];
+ };
+ Bar bar { .[[^Foo]]= 42 };
+ )cpp",
};
for (llvm::StringRef T : Tests) {
Annotations Code(T);
Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -563,7 +563,7 @@
// FIXME: Auto-completion in a template requires disabling delayed template
// parsing.
TU.ExtraArgs.push_back("-fno-delayed-template-parsing");
- TU.ExtraArgs.push_back("-std=c++17");
+ TU.ExtraArgs.push_back("-std=c++2a");
auto AST = TU.build();
for (auto &D : AST.getDiagnostics()) {
@@ -969,7 +969,21 @@
}
)cpp",
"0: targets = {Test}\n"
- "1: targets = {a}, decl\n"}};
+ "1: targets = {a}, decl\n"},
+ // Designated initializers.
+ {R"cpp(
+ void foo() {
+ struct $0^Foo {
+ int $1^Bar;
+ };
+ $2^Foo $3^f { .$4^Bar = 42 };
+ }
+ )cpp",
+ "0: targets = {Foo}, decl\n"
+ "1: targets = {foo()::Foo::Bar}, decl\n"
+ "2: targets = {Foo}\n"
+ "3: targets = {f}, decl\n"
+ "4: targets = {foo()::Foo::Bar}\n"}};
for (const auto &C : Cases) {
llvm::StringRef ExpectedCode = C.first;
Index: clang-tools-extra/clangd/FindTarget.cpp
===================================================================
--- clang-tools-extra/clangd/FindTarget.cpp
+++ clang-tools-extra/clangd/FindTarget.cpp
@@ -634,6 +634,17 @@
/*IsDecl=*/false,
{E->getPack()}});
}
+
+ void VisitDesignatedInitExpr(const DesignatedInitExpr *DIE) {
+ for (const DesignatedInitExpr::Designator &D : DIE->designators()) {
+ if (!D.isFieldDesignator())
+ continue;
+ Refs.push_back(ReferenceLoc{NestedNameSpecifierLoc(),
+ D.getFieldLoc(),
+ /*IsDecl=*/false,
+ {D.getField()}});
+ }
+ }
};
Visitor V;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72867.238586.patch
Type: text/x-patch
Size: 2692 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200116/4af2c7a7/attachment-0001.bin>
More information about the cfe-commits
mailing list