[clangd] Log all ignored diagnostics.

Summary:
To aid debugging failures and crashes.
Only part of ignored diagnostics was logged before, now we log all of
them.

Reviewers: ioeric, hokein, sammccall

Reviewed By: hokein

Subscribers: klimek, jkorous-apple, cfe-commits

Differential Revision: https://reviews.llvm.org/D43123

llvm-svn: 324888
This commit is contained in:
Ilya Biryukov 2018-02-12 12:48:51 +00:00
parent 7e19dfc45f
commit 2d4cdacd26
3 changed files with 33 additions and 18 deletions

View File

@ -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 @@ 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())) {
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);

View File

@ -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,

View File

@ -24,8 +24,11 @@ namespace clangd {
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: