[clang-tools-extra] r323992 - [clangd] Log dropped diagnostics.
Ilya Biryukov via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 1 11:06:45 PST 2018
Author: ibiryukov
Date: Thu Feb 1 11:06:45 2018
New Revision: 323992
URL: http://llvm.org/viewvc/llvm-project?rev=323992&view=rev
Log:
[clangd] Log dropped diagnostics.
Summary:
clangd drops diagnostics coming outside the main file, but it is still
useful to see that something went wrong in the logs.
Reviewers: hokein, ioeric, sammccall
Reviewed By: sammccall
Subscribers: klimek, jkorous-apple, cfe-commits
Differential Revision: https://reviews.llvm.org/D42803
Modified:
clang-tools-extra/trunk/clangd/ClangdUnit.cpp
Modified: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.cpp?rev=323992&r1=323991&r2=323992&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/ClangdUnit.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp Thu Feb 1 11:06:45 2018
@@ -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 @@ TextEdit toTextEdit(const FixItHint &Fix
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));
More information about the cfe-commits
mailing list