diff options
author | Ilya Biryukov <ibiryukov@google.com> | 2018-02-01 19:06:45 +0000 |
---|---|---|
committer | Ilya Biryukov <ibiryukov@google.com> | 2018-02-01 19:06:45 +0000 |
commit | 59e591368712092ddef1d5ee92e3bf494fa1f59e (patch) | |
tree | 9033a41d90431bc87d93c5d24433bb88a6fc343c /clang-tools-extra/clangd/ClangdUnit.cpp | |
parent | 889f4842827552142551e2ce9be228dda8ac3908 (diff) |
[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
Diffstat (limited to 'clang-tools-extra/clangd/ClangdUnit.cpp')
-rw-r--r-- | clang-tools-extra/clangd/ClangdUnit.cpp | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/clang-tools-extra/clangd/ClangdUnit.cpp b/clang-tools-extra/clangd/ClangdUnit.cpp index 917294499fb..256f2b3699b 100644 --- a/clang-tools-extra/clangd/ClangdUnit.cpp +++ b/clang-tools-extra/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 @@ TextEdit toTextEdit(const FixItHint &FixIt, const SourceManager &M, 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)); |