[clangd] add an extension field to LSP to transfer the diagnostic's category

This patch adds a 'category' extension field to the LSP diagnostic that's sent
by Clangd. This extension is always on by default.

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

llvm-svn: 339738
This commit is contained in:
Alex Lorenz 2018-08-14 22:21:40 +00:00
parent 3738dba69b
commit 37146431d2
11 changed files with 24 additions and 0 deletions

View File

@ -506,6 +506,8 @@ void ClangdLSPServer::onDiagnosticsReady(PathRef File,
}
LSPDiag["clangd_fixes"] = std::move(ClangdFixes);
}
if (!Diag.category.empty())
LSPDiag["category"] = Diag.category;
DiagnosticsJSON.push_back(std::move(LSPDiag));
auto &FixItsForDiagnostic = LocalFixIts[Diag];

View File

@ -226,6 +226,7 @@ void toLSPDiags(
clangd::Diagnostic Res;
Res.range = D.Range;
Res.severity = getSeverity(D.Severity);
Res.category = D.Category;
return Res;
};
@ -292,6 +293,9 @@ void StoreDiags::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
D.InsideMainFile = InsideMainFile;
D.File = Info.getSourceManager().getFilename(Info.getLocation());
D.Severity = DiagLevel;
D.Category = DiagnosticIDs::getCategoryNameFromID(
DiagnosticIDs::getCategoryNumberForDiag(Info.getID()))
.str();
return D;
};

View File

@ -37,6 +37,7 @@ struct DiagBase {
std::string File;
clangd::Range Range;
DiagnosticsEngine::Level Severity = DiagnosticsEngine::Note;
std::string Category;
// Since File is only descriptive, we store a separate flag to distinguish
// diags from the main file.
bool InsideMainFile = false;

View File

@ -544,6 +544,12 @@ struct Diagnostic {
/// The diagnostic's message.
std::string message;
/// The diagnostic's category. Can be omitted.
/// An LSP extension that's used to send the name of the category over to the
/// client. The category typically describes the compilation stage during
/// which the issue was produced, e.g. "Semantic Issue" or "Parse Issue".
std::string category;
};
/// A LSP-specific comparator used to find diagnostic in a container like

View File

@ -23,6 +23,7 @@
# CHECK-NEXT: "params": {
# CHECK-NEXT: "diagnostics": [
# CHECK-NEXT: {
# CHECK-NEXT: "category": "#pragma message Directive",
# CHECK-NEXT: "message": "MACRO is one",
---
{"jsonrpc":"2.0","id":0,"method":"workspace/didChangeConfiguration","params":{"settings":{"compilationDatabasePath":"INPUT_DIR/build-2"}}}
@ -30,6 +31,7 @@
# CHECK-NEXT: "params": {
# CHECK-NEXT: "diagnostics": [
# CHECK-NEXT: {
# CHECK-NEXT: "category": "#pragma message Directive",
# CHECK-NEXT: "message": "MACRO is two",
---
{"jsonrpc":"2.0","id":10000,"method":"shutdown"}

View File

@ -23,6 +23,7 @@
# CHECK-NEXT: "params": {
# CHECK-NEXT: "diagnostics": [
# CHECK-NEXT: {
# CHECK-NEXT: "category": "#pragma message Directive",
# CHECK-NEXT: "message": "MACRO is not defined",
---
{"jsonrpc":"2.0","id":0,"method":"workspace/didChangeConfiguration","params":{"settings":{"compilationDatabasePath":"INPUT_DIR/build-1"}}}
@ -30,6 +31,7 @@
# CHECK-NEXT: "params": {
# CHECK-NEXT: "diagnostics": [
# CHECK-NEXT: {
# CHECK-NEXT: "category": "#pragma message Directive",
# CHECK-NEXT: "message": "MACRO is one",
---
{"jsonrpc":"2.0","id":0,"method":"workspace/didChangeConfiguration","params":{"settings":{"compilationDatabasePath":"INPUT_DIR/build-2"}}}
@ -37,6 +39,7 @@
# CHECK-NEXT: "params": {
# CHECK-NEXT: "diagnostics": [
# CHECK-NEXT: {
# CHECK-NEXT: "category": "#pragma message Directive",
# CHECK-NEXT: "message": "MACRO is two",
---
{"jsonrpc":"2.0","id":10000,"method":"shutdown"}

View File

@ -6,6 +6,7 @@
# CHECK-NEXT: "params": {
# CHECK-NEXT: "diagnostics": [
# CHECK-NEXT: {
# CHECK-NEXT: "category": "Semantic Issue",
# CHECK-NEXT: "message": "Return type of 'main' is not 'int'",
# CHECK-NEXT: "range": {
# CHECK-NEXT: "end": {

View File

@ -24,6 +24,7 @@
# CHECK-NEXT: "params": {
# CHECK-NEXT: "diagnostics": [
# CHECK-NEXT: {
# CHECK-NEXT: "category": "Semantic Issue",
# CHECK-NEXT: "message": "Variable 'i' is uninitialized when used here",
# CHECK-NEXT: "range": {
# CHECK-NEXT: "end": {

View File

@ -6,6 +6,7 @@
# CHECK-NEXT: "params": {
# CHECK-NEXT: "diagnostics": [
# CHECK-NEXT: {
# CHECK-NEXT: "category": "Semantic Issue",
# CHECK-NEXT: "message": "Using the result of an assignment as a condition without parentheses",
# CHECK-NEXT: "range": {
# CHECK-NEXT: "end": {

View File

@ -6,6 +6,7 @@
# CHECK-NEXT: "params": {
# CHECK-NEXT: "diagnostics": [
# CHECK-NEXT: {
# CHECK-NEXT: "category": "Semantic Issue",
# CHECK-NEXT: "message": "Variable 'i' is uninitialized when used here",
# CHECK-NEXT: "range": {
# CHECK-NEXT: "end": {
@ -28,6 +29,7 @@
# CHECK-NEXT: "params": {
# CHECK-NEXT: "diagnostics": [
# CHECK-NEXT: {
# CHECK-NEXT: "category": "Semantic Issue",
# CHECK-NEXT: "message": "Variable 'i' is uninitialized when used here",
# CHECK-NEXT: "range": {
# CHECK-NEXT: "end": {

View File

@ -6,6 +6,7 @@
# CHECK-NEXT: "params": {
# CHECK-NEXT: "diagnostics": [
# CHECK-NEXT: {
# CHECK-NEXT: "category": "Semantic Issue",
# CHECK-NEXT: "message": "Using the result of an assignment as a condition without parentheses",
# CHECK-NEXT: "range": {
# CHECK-NEXT: "end": {