summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHaojian Wu <hokein@google.com>2019-02-22 09:43:56 +0000
committerHaojian Wu <hokein@google.com>2019-02-22 09:43:56 +0000
commitc8f7496257f6c385e3eff33cd14cdb060c49063f (patch)
treed35bd5b3405b309ccc8113d5ad623d5d2a2ade97
parentd22686b637ef4925005110178ea26667c66b0347 (diff)
downloadbcm5719-llvm-c8f7496257f6c385e3eff33cd14cdb060c49063f.tar.gz
bcm5719-llvm-c8f7496257f6c385e3eff33cd14cdb060c49063f.zip
[clangd] Don't attach FixIt to the source code in macro.
Summary: We are less certain it is the correct fix. Also, clang doesn't apply FixIt to the source code in macro. Reviewers: ilya-biryukov Reviewed By: ilya-biryukov Subscribers: ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D58525 llvm-svn: 354664
-rw-r--r--clang-tools-extra/clangd/Diagnostics.cpp5
-rw-r--r--clang-tools-extra/unittests/clangd/DiagnosticsTests.cpp12
2 files changed, 17 insertions, 0 deletions
diff --git a/clang-tools-extra/clangd/Diagnostics.cpp b/clang-tools-extra/clangd/Diagnostics.cpp
index 186ab0661c7..210539532a3 100644
--- a/clang-tools-extra/clangd/Diagnostics.cpp
+++ b/clang-tools-extra/clangd/Diagnostics.cpp
@@ -335,6 +335,11 @@ void StoreDiags::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
llvm::SmallVector<TextEdit, 1> Edits;
for (auto &FixIt : Info.getFixItHints()) {
+ // Follow clang's behavior, don't apply FixIt to the code in macros,
+ // we are less certain it is the right fix.
+ if (FixIt.RemoveRange.getBegin().isMacroID() ||
+ FixIt.RemoveRange.getEnd().isMacroID())
+ return false;
if (!isInsideMainFile(FixIt.RemoveRange.getBegin(),
Info.getSourceManager()))
return false;
diff --git a/clang-tools-extra/unittests/clangd/DiagnosticsTests.cpp b/clang-tools-extra/unittests/clangd/DiagnosticsTests.cpp
index bbd94b80eea..4bbc7c742ff 100644
--- a/clang-tools-extra/unittests/clangd/DiagnosticsTests.cpp
+++ b/clang-tools-extra/unittests/clangd/DiagnosticsTests.cpp
@@ -215,6 +215,18 @@ TEST(DiagnosticsTest, InsideMacros) {
"'int *' with an rvalue of type 'int'")));
}
+TEST(DiagnosticsTest, NoFixItInMacro) {
+ Annotations Test(R"cpp(
+ #define Define(name) void name() {}
+
+ [[Define]](main)
+ )cpp");
+ auto TU = TestTU::withCode(Test.code());
+ EXPECT_THAT(TU.build().getDiagnostics(),
+ ElementsAre(AllOf(Diag(Test.range(), "'main' must return 'int'"),
+ Not(WithFix(_)))));
+}
+
TEST(DiagnosticsTest, ToLSP) {
clangd::Diag D;
D.Message = "something terrible happened";
OpenPOWER on IntegriCloud