[PATCH] D66074: [clangd] Drop diags from non-written #include.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 12 01:46:47 PDT 2019


hokein created this revision.
hokein added a reviewer: ilya-biryukov.
Herald added subscribers: kadircet, arphaman, jkorous, MaskRay.
Herald added a project: clang.

This would fix that we show weird diagnostics on random lines of the main file.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D66074

Files:
  clang-tools-extra/clangd/Diagnostics.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp


Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -948,6 +948,13 @@
   EXPECT_THAT(TU.build().getDiagnostics(), UnorderedElementsAre());
 }
 
+TEST(IgnoreDiags, FromNonWrittenInclude) {
+  TestTU TU = TestTU::withCode("");
+  TU.ExtraArgs.push_back("--include=a.h");
+  TU.AdditionalFiles = {{"a.h", "void main();"}};
+  EXPECT_THAT(TU.build().getDiagnostics(), UnorderedElementsAre());
+}
+
 } // namespace
 
 } // namespace clangd
Index: clang-tools-extra/clangd/Diagnostics.cpp
===================================================================
--- clang-tools-extra/clangd/Diagnostics.cpp
+++ clang-tools-extra/clangd/Diagnostics.cpp
@@ -122,8 +122,12 @@
     return SM.getIncludeLoc(SM.getFileID(SLoc));
   };
   for (auto IncludeLocation = GetIncludeLoc(DiagLoc); IncludeLocation.isValid();
-       IncludeLocation = GetIncludeLoc(IncludeLocation))
-    IncludeInMainFile = IncludeLocation;
+       IncludeLocation = GetIncludeLoc(IncludeLocation)) {
+    if (clangd::isInsideMainFile(IncludeLocation, SM)) {
+      IncludeInMainFile = IncludeLocation;
+      break;
+    }
+  }
   if (IncludeInMainFile.isInvalid())
     return false;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66074.214587.patch
Type: text/x-patch
Size: 1349 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190812/b8164390/attachment.bin>


More information about the cfe-commits mailing list