[PATCH] D42803: [clangd] Log dropped diagnostics.

Ilya Biryukov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 1 11:07:43 PST 2018


ilya-biryukov updated this revision to Diff 132430.
ilya-biryukov added a comment.

- Show location of dropped diagnostic.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42803

Files:
  clangd/ClangdUnit.cpp


Index: clangd/ClangdUnit.cpp
===================================================================
--- clangd/ClangdUnit.cpp
+++ clangd/ClangdUnit.cpp
@@ -27,6 +27,7 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/CrashRecoveryContext.h"
 #include "llvm/Support/Format.h"
+#include "llvm/Support/raw_ostream.h"
 #include <algorithm>
 #include <chrono>
 
@@ -178,15 +179,30 @@
 llvm::Optional<DiagWithFixIts> toClangdDiag(const clang::Diagnostic &D,
                                             DiagnosticsEngine::Level Level,
                                             const LangOptions &LangOpts) {
+  SmallString<64> Message;
+  D.FormatDiagnostic(Message);
+
   if (!D.hasSourceManager() || !D.getLocation().isValid() ||
-      !D.getSourceManager().isInMainFile(D.getLocation()))
+      !D.getSourceManager().isInMainFile(D.getLocation())) {
+
+    SmallString<64> Location;
+    if (D.hasSourceManager() && D.getLocation().isValid()) {
+      auto &SourceMgr = D.getSourceManager();
+      auto Loc = SourceMgr.getFileLoc(D.getLocation());
+      llvm::raw_svector_ostream OS(Location);
+      Loc.print(OS, SourceMgr);
+    } else {
+      Location = "<no-loc>";
+    }
+
+    log(llvm::formatv("Ignored diagnostic outside main file. {0}: {1}",
+                      Location, Message));
     return llvm::None;
+  }
 
   DiagWithFixIts Result;
   Result.Diag.range = diagnosticRange(D, LangOpts);
   Result.Diag.severity = getSeverity(Level);
-  SmallString<64> Message;
-  D.FormatDiagnostic(Message);
   Result.Diag.message = Message.str();
   for (const FixItHint &Fix : D.getFixItHints())
     Result.FixIts.push_back(toTextEdit(Fix, D.getSourceManager(), LangOpts));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42803.132430.patch
Type: text/x-patch
Size: 1694 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180201/69aad20d/attachment.bin>


More information about the cfe-commits mailing list