hokein updated this revision to Diff 189455.
hokein added a comment.
Don't emit the source to LSP level (as this is a UI change as least in vscode)
Repository:
rCTE Clang Tools Extra
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D58600/new/
https://reviews.llvm.org/D58600
Files:
clangd/ClangdUnit.cpp
clangd/Diagnostics.cpp
clangd/Diagnostics.h
unittests/clangd/DiagnosticsTests.cpp
Index: unittests/clangd/DiagnosticsTests.cpp
===================================================================
--- unittests/clangd/DiagnosticsTests.cpp
+++ unittests/clangd/DiagnosticsTests.cpp
@@ -58,6 +58,8 @@
std::tie(LSPDiag.range, LSPDiag.severity, LSPDiag.message);
}
+MATCHER_P(DiagSource, Source, "") { return arg.S == Source; }
+
MATCHER_P(EqualToFix, Fix, "LSP fix " + llvm::to_string(Fix)) {
if (arg.Message != Fix.Message)
return false;
@@ -102,6 +104,7 @@
// This range spans lines.
AllOf(Diag(Test.range("typo"),
"use of undeclared identifier 'goo'; did you mean 'foo'?"),
+ DiagSource(Diag::Clang),
WithFix(
Fix(Test.range("typo"), "foo", "change 'go\\ o' to 'foo'")),
// This is a pretty normal range.
@@ -137,6 +140,18 @@
WithFix(Fix(Test.range(), "int", "change return type to 'int'")))));
}
+TEST(DiagnosticsTest, DiagnosticPreamble) {
+ Annotations Test(R"cpp(
+ #include $[["not-found.h"]]
+ )cpp");
+
+ auto TU = TestTU::withCode(Test.code());
+ EXPECT_THAT(TU.build().getDiagnostics(),
+ ElementsAre(testing::AllOf(
+ Diag(Test.range(), "'not-found.h' file not found"),
+ DiagSource(Diag::Clang))));
+}
+
TEST(DiagnosticsTest, ClangTidy) {
Annotations Test(R"cpp(
#include $deprecated[["assert.h"]]
@@ -159,6 +174,7 @@
AllOf(Diag(Test.range("deprecated"),
"inclusion of deprecated C++ header 'assert.h'; consider "
"using 'cassert' instead [modernize-deprecated-headers]"),
+ DiagSource(Diag::ClangTidy),
WithFix(Fix(Test.range("deprecated"), "<cassert>",
"change '\"assert.h\"' to '<cassert>'"))),
Diag(Test.range("doubled"),
@@ -168,6 +184,7 @@
Diag(Test.range("macroarg"),
"side effects in the 1st macro argument 'X' are repeated in "
"macro expansion [bugprone-macro-repeated-side-effects]"),
+ DiagSource(Diag::ClangTidy),
WithNote(Diag(Test.range("macrodef"),
"macro 'SQUARE' defined here "
"[bugprone-macro-repeated-side-effects]"))),
Index: clangd/Diagnostics.h
===================================================================
--- clangd/Diagnostics.h
+++ clangd/Diagnostics.h
@@ -68,6 +68,14 @@
/// A top-level diagnostic that may have Notes and Fixes.
struct Diag : DiagBase {
+ // Diagnostic enum ID.
+ unsigned ID;
+ // The source of this diagnostic.
+ enum Source {
+ Clang,
+ ClangTidy,
+ };
+ Source S = Clang;
/// Elaborate on the problem, usually pointing to a related piece of code.
std::vector<Note> Notes;
/// *Alternative* fixes for this diagnostic, one should be chosen.
Index: clangd/Diagnostics.cpp
===================================================================
--- clangd/Diagnostics.cpp
+++ clangd/Diagnostics.cpp
@@ -377,6 +377,7 @@
flushLastDiag();
LastDiag = Diag();
+ LastDiag->ID = Info.getID();
FillDiagBase(*LastDiag);
if (!Info.getFixItHints().empty())
Index: clangd/ClangdUnit.cpp
===================================================================
--- clangd/ClangdUnit.cpp
+++ clangd/ClangdUnit.cpp
@@ -372,6 +372,10 @@
Clang->getPreprocessor().EndSourceFile();
std::vector<Diag> Diags = ASTDiags.take();
+ // Populate diagnostic source.
+ for (auto &D : Diags)
+ D.S =
+ !CTContext->getCheckName(D.ID).empty() ? Diag::ClangTidy : Diag::Clang;
// Add diagnostics from the preamble, if any.
if (Preamble)
Diags.insert(Diags.begin(), Preamble->Diags.begin(), Preamble->Diags.end());
@@ -539,8 +543,11 @@
if (BuiltPreamble) {
vlog("Built preamble of size {0} for file {1}", BuiltPreamble->getSize(),
FileName);
+ std::vector<Diag> Diags = PreambleDiagnostics.take();
+ for (auto &Diag : Diags)
+ Diag.S = Diag::Clang;
return std::make_shared<PreambleData>(
- std::move(*BuiltPreamble), PreambleDiagnostics.take(),
+ std::move(*BuiltPreamble), std::move(Diags),
SerializedDeclsCollector.takeIncludes(), std::move(StatCache),
SerializedDeclsCollector.takeCanonicalIncludes());
} else {
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits