Skip to content

Commit 2d4cdac

Browse files
committed
[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
1 parent 7e19dfc commit 2d4cdac

File tree

3 files changed

+33
-18
lines changed

3 files changed

+33
-18
lines changed

Diff for: clang-tools-extra/clangd/ClangdUnit.cpp

+4-17
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include "llvm/ADT/ArrayRef.h"
2727
#include "llvm/ADT/SmallVector.h"
2828
#include "llvm/Support/CrashRecoveryContext.h"
29-
#include "llvm/Support/Format.h"
3029
#include "llvm/Support/raw_ostream.h"
3130
#include <algorithm>
3231

@@ -178,27 +177,15 @@ TextEdit toTextEdit(const FixItHint &FixIt, const SourceManager &M,
178177
llvm::Optional<DiagWithFixIts> toClangdDiag(const clang::Diagnostic &D,
179178
DiagnosticsEngine::Level Level,
180179
const LangOptions &LangOpts) {
181-
SmallString<64> Message;
182-
D.FormatDiagnostic(Message);
183-
184180
if (!D.hasSourceManager() || !D.getLocation().isValid() ||
185181
!D.getSourceManager().isInMainFile(D.getLocation())) {
186-
187-
SmallString<64> Location;
188-
if (D.hasSourceManager() && D.getLocation().isValid()) {
189-
auto &SourceMgr = D.getSourceManager();
190-
auto Loc = SourceMgr.getFileLoc(D.getLocation());
191-
llvm::raw_svector_ostream OS(Location);
192-
Loc.print(OS, SourceMgr);
193-
} else {
194-
Location = "<no-loc>";
195-
}
196-
197-
log(llvm::formatv("Ignored diagnostic outside main file. {0}: {1}",
198-
Location, Message));
182+
IgnoreDiagnostics::log(Level, D);
199183
return llvm::None;
200184
}
201185

186+
SmallString<64> Message;
187+
D.FormatDiagnostic(Message);
188+
202189
DiagWithFixIts Result;
203190
Result.Diag.range = diagnosticRange(D, LangOpts);
204191
Result.Diag.severity = getSeverity(Level);

Diff for: clang-tools-extra/clangd/Compiler.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,37 @@
88
//===---------------------------------------------------------------------===//
99

1010
#include "Compiler.h"
11+
#include "Logger.h"
1112
#include "clang/Basic/TargetInfo.h"
1213
#include "clang/Lex/PreprocessorOptions.h"
14+
#include "llvm/Support/Format.h"
15+
#include "llvm/Support/FormatVariadic.h"
1316

1417
namespace clang {
1518
namespace clangd {
1619

20+
void IgnoreDiagnostics::log(DiagnosticsEngine::Level DiagLevel,
21+
const clang::Diagnostic &Info) {
22+
SmallString<64> Message;
23+
Info.FormatDiagnostic(Message);
24+
25+
SmallString<64> Location;
26+
if (Info.hasSourceManager() && Info.getLocation().isValid()) {
27+
auto &SourceMgr = Info.getSourceManager();
28+
auto Loc = SourceMgr.getFileLoc(Info.getLocation());
29+
llvm::raw_svector_ostream OS(Location);
30+
Loc.print(OS, SourceMgr);
31+
OS << ":";
32+
}
33+
34+
clangd::log(llvm::formatv("Ignored diagnostic. {0}{1}", Location, Message));
35+
}
36+
37+
void IgnoreDiagnostics::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
38+
const clang::Diagnostic &Info) {
39+
IgnoreDiagnostics::log(DiagLevel, Info);
40+
}
41+
1742
std::unique_ptr<CompilerInstance>
1843
prepareCompilerInstance(std::unique_ptr<clang::CompilerInvocation> CI,
1944
const PrecompiledPreamble *Preamble,

Diff for: clang-tools-extra/clangd/Compiler.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ namespace clangd {
2424

2525
class IgnoreDiagnostics : public DiagnosticConsumer {
2626
public:
27+
static void log(DiagnosticsEngine::Level DiagLevel,
28+
const clang::Diagnostic &Info);
29+
2730
void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
28-
const clang::Diagnostic &Info) override {}
31+
const clang::Diagnostic &Info) override;
2932
};
3033

3134
/// Creates a compiler instance, configured so that:

0 commit comments

Comments
 (0)