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

Phabricator via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 1 11:08:49 PST 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL323992: [clangd] Log dropped diagnostics. (authored by ibiryukov, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D42803

Files:
  clang-tools-extra/trunk/clangd/ClangdUnit.cpp


Index: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
===================================================================
--- clang-tools-extra/trunk/clangd/ClangdUnit.cpp
+++ clang-tools-extra/trunk/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.132431.patch
Type: text/x-patch
Size: 1766 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180201/15b142e6/attachment.bin>


More information about the llvm-commits mailing list