[PATCH] D156441: [clangd]Fix addUsing tweak doesn't traverse same-level anon namespaces
zhou via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 27 08:33:55 PDT 2023
chouzz created this revision.
chouzz added reviewers: kadircet, sammccall.
Herald added a subscriber: arphaman.
Herald added a project: All.
chouzz requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.
This patch provide fixes about addUsing tweak doesn't traverse same-level anon namespaces.
Fixes: https://github.com/clangd/clangd/issues/1572
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D156441
Files:
clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
clang-tools-extra/clangd/unittests/tweaks/AddUsingTests.cpp
Index: clang-tools-extra/clangd/unittests/tweaks/AddUsingTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/tweaks/AddUsingTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/AddUsingTests.cpp
@@ -395,6 +395,28 @@
cc C;
})cpp"},
+ // Should drop the qualifier in anon namespaces
+ {R"cpp(
+namespace ns { struct Foo; struct Bar; }
+namespace { using ns::Foo; }
+void foo() { ns::^Foo *f; ns::Bar *b;
+})cpp",
+ R"cpp(
+namespace ns { struct Foo; struct Bar; }
+namespace { using ns::Foo; }
+void foo() { Foo *f; ns::Bar *b;
+})cpp"},
+ // Should insert the using decl into the anon namespace
+ {R"cpp(
+namespace ns { struct Foo; struct Bar; }
+namespace { using ns::Foo; }
+void foo() { ns::Foo *f; ns::^Bar *b; }
+)cpp",
+ R"cpp(
+namespace ns { struct Foo; struct Bar; }
+namespace { using ns::Bar;using ns::Foo; }
+void foo() { ns::Foo *f; Bar *b; }
+)cpp"},
// Type defined in main file, make sure using is after that.
{R"cpp(
namespace xx {
Index: clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
===================================================================
--- clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
@@ -90,12 +90,19 @@
if (SM.getFileID(Loc) != SM.getMainFileID()) {
return true;
}
- if (D->getDeclContext()->Encloses(SelectionDeclContext)) {
- Results.push_back(D);
- }
+ Results.push_back(D);
return true;
}
+ bool TraverseNamespaceDecl(NamespaceDecl *D) {
+ for (auto *Decl : D->decls()) {
+ if (auto *Node = dyn_cast<UsingDecl>(Decl)) {
+ VisitUsingDecl(Node);
+ }
+ }
+ return RecursiveASTVisitor<UsingFinder>::TraverseNamespaceDecl(D);
+ }
+
bool TraverseDecl(Decl *Node) {
if (!Node)
return true;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156441.544786.patch
Type: text/x-patch
Size: 1901 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230727/9c9ef3e1/attachment.bin>
More information about the cfe-commits
mailing list