[clang-tools-extra] r354664 - [clangd] Don't attach FixIt to the source code in macro.
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 22 01:43:56 PST 2019
Author: hokein
Date: Fri Feb 22 01:43:56 2019
New Revision: 354664
URL: http://llvm.org/viewvc/llvm-project?rev=354664&view=rev
Log:
[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
Modified:
clang-tools-extra/trunk/clangd/Diagnostics.cpp
clang-tools-extra/trunk/unittests/clangd/DiagnosticsTests.cpp
Modified: clang-tools-extra/trunk/clangd/Diagnostics.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Diagnostics.cpp?rev=354664&r1=354663&r2=354664&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/Diagnostics.cpp (original)
+++ clang-tools-extra/trunk/clangd/Diagnostics.cpp Fri Feb 22 01:43:56 2019
@@ -335,6 +335,11 @@ void StoreDiags::HandleDiagnostic(Diagno
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;
Modified: clang-tools-extra/trunk/unittests/clangd/DiagnosticsTests.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/DiagnosticsTests.cpp?rev=354664&r1=354663&r2=354664&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clangd/DiagnosticsTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/DiagnosticsTests.cpp Fri Feb 22 01:43:56 2019
@@ -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";
More information about the cfe-commits
mailing list