[PATCH] D79488: [clangd] Do not offer "Add using" tweak in header files.
Sam McCall via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed May 6 06:58:05 PDT 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rG319787315dd6: [clangd] Do not offer "Add using" tweak in header files. (authored by adamcz, committed by sammccall).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D79488/new/
https://reviews.llvm.org/D79488
Files:
clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
clang-tools-extra/clangd/unittests/TweakTests.cpp
Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -2463,6 +2463,13 @@
// test that we don't crash.
EXPECT_UNAVAILABLE(Header +
"template<typename TT> using foo = one::tt<T^T>;");
+
+ // Check that we do not trigger in header files.
+ FileName = "test.h";
+ ExtraArgs.push_back("-xc++-header"); // .h file is treated a C by default.
+ EXPECT_UNAVAILABLE(Header + "void fun() { one::two::f^f(); }");
+ FileName = "test.hpp";
+ EXPECT_UNAVAILABLE(Header + "void fun() { one::two::f^f(); }");
}
TEST_F(AddUsingTest, Apply) {
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
@@ -175,6 +175,12 @@
bool AddUsing::prepare(const Selection &Inputs) {
auto &SM = Inputs.AST->getSourceManager();
+
+ // Do not suggest "using" in header files. That way madness lies.
+ if (isHeaderFile(SM.getFileEntryForID(SM.getMainFileID())->getName(),
+ Inputs.AST->getLangOpts()))
+ return false;
+
auto *Node = Inputs.ASTSelection.commonAncestor();
if (Node == nullptr)
return false;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79488.262369.patch
Type: text/x-patch
Size: 1420 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200506/9c356289/attachment.bin>
More information about the cfe-commits
mailing list