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

Repository:
  rL LLVM

https://reviews.llvm.org/D43123

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

Index: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
===================================================================
--- clang-tools-extra/trunk/clangd/ClangdUnit.cpp
+++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp
@@ -26,7 +26,6 @@
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/CrashRecoveryContext.h"
-#include "llvm/Support/Format.h"
 #include "llvm/Support/raw_ostream.h"
 #include <algorithm>
 
@@ -178,27 +177,15 @@
 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())) {
-
-    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));
+    IgnoreDiagnostics::log(Level, D);
     return llvm::None;
   }
 
+  SmallString<64> Message;
+  D.FormatDiagnostic(Message);
+
   DiagWithFixIts Result;
   Result.Diag.range = diagnosticRange(D, LangOpts);
   Result.Diag.severity = getSeverity(Level);
Index: clang-tools-extra/trunk/clangd/Compiler.cpp
===================================================================
--- clang-tools-extra/trunk/clangd/Compiler.cpp
+++ clang-tools-extra/trunk/clangd/Compiler.cpp
@@ -8,12 +8,37 @@
 //===---------------------------------------------------------------------===//
 
 #include "Compiler.h"
+#include "Logger.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Lex/PreprocessorOptions.h"
+#include "llvm/Support/Format.h"
+#include "llvm/Support/FormatVariadic.h"
 
 namespace clang {
 namespace clangd {
 
+void IgnoreDiagnostics::log(DiagnosticsEngine::Level DiagLevel,
+                            const clang::Diagnostic &Info) {
+  SmallString<64> Message;
+  Info.FormatDiagnostic(Message);
+
+  SmallString<64> Location;
+  if (Info.hasSourceManager() && Info.getLocation().isValid()) {
+    auto &SourceMgr = Info.getSourceManager();
+    auto Loc = SourceMgr.getFileLoc(Info.getLocation());
+    llvm::raw_svector_ostream OS(Location);
+    Loc.print(OS, SourceMgr);
+    OS << ":";
+  }
+
+  clangd::log(llvm::formatv("Ignored diagnostic. {0}{1}", Location, Message));
+}
+
+void IgnoreDiagnostics::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
+                                         const clang::Diagnostic &Info) {
+  IgnoreDiagnostics::log(DiagLevel, Info);
+}
+
 std::unique_ptr<CompilerInstance>
 prepareCompilerInstance(std::unique_ptr<clang::CompilerInvocation> CI,
                         const PrecompiledPreamble *Preamble,
Index: clang-tools-extra/trunk/clangd/Compiler.h
===================================================================
--- clang-tools-extra/trunk/clangd/Compiler.h
+++ clang-tools-extra/trunk/clangd/Compiler.h
@@ -24,8 +24,11 @@
 
 class IgnoreDiagnostics : public DiagnosticConsumer {
 public:
+  static void log(DiagnosticsEngine::Level DiagLevel,
+                  const clang::Diagnostic &Info);
+
   void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
-                        const clang::Diagnostic &Info) override {}
+                        const clang::Diagnostic &Info) override;
 };
 
 /// Creates a compiler instance, configured so that:
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to