[clangd] Do not offer "Add using" tweak in header files.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D79488
This commit is contained in:
Adam Czachorowski 2020-05-06 15:46:56 +02:00 committed by Sam McCall
parent 5010b5b7e6
commit 319787315d
2 changed files with 13 additions and 0 deletions

View File

@ -175,6 +175,12 @@ findInsertionPoint(const Tweak::Selection &Inputs,
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;

View File

@ -2463,6 +2463,13 @@ public:
// 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) {