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

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


This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE323992: [clangd] Log dropped diagnostics. (authored by ibiryukov, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D42803?vs=132430&id=132432#toc

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.132432.patch
Type: text/x-patch
Size: 1694 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180201/d401d9fd/attachment.bin>


More information about the cfe-commits mailing list