[clang-tools-extra] r340449 - [clangd] send diagnostic categories only when 'categorySupport'

Alex Lorenz via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 22 13:30:06 PDT 2018


Author: arphaman
Date: Wed Aug 22 13:30:06 2018
New Revision: 340449

URL: http://llvm.org/viewvc/llvm-project?rev=340449&view=rev
Log:
[clangd] send diagnostic categories only when 'categorySupport'
capability was given by the client

After r339738 Clangd started sending categories with each diagnostic, but that
broke the eglot client. This commit puts the categories behind a capability to
fix that breakage.

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

Added:
    clang-tools-extra/trunk/test/clangd/diagnostic-category.test
Modified:
    clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
    clang-tools-extra/trunk/clangd/Diagnostics.h
    clang-tools-extra/trunk/clangd/Protocol.cpp
    clang-tools-extra/trunk/clangd/Protocol.h
    clang-tools-extra/trunk/test/clangd/compile-commands-path-in-initialize.test
    clang-tools-extra/trunk/test/clangd/compile-commands-path.test
    clang-tools-extra/trunk/test/clangd/diagnostics.test
    clang-tools-extra/trunk/test/clangd/did-change-configuration-params.test
    clang-tools-extra/trunk/test/clangd/execute-command.test
    clang-tools-extra/trunk/test/clangd/extra-flags.test
    clang-tools-extra/trunk/test/clangd/fixits-embed-in-diagnostic.test
    clang-tools-extra/trunk/test/clangd/fixits.test

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=340449&r1=340448&r2=340449&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Wed Aug 22 13:30:06 2018
@@ -84,6 +84,8 @@ void ClangdLSPServer::onInitialize(Initi
       Params.capabilities.textDocument.completion.completionItem.snippetSupport;
   DiagOpts.EmbedFixesInDiagnostics =
       Params.capabilities.textDocument.publishDiagnostics.clangdFixSupport;
+  DiagOpts.SendDiagnosticCategory =
+      Params.capabilities.textDocument.publishDiagnostics.categorySupport;
 
   if (Params.capabilities.workspace && Params.capabilities.workspace->symbol &&
       Params.capabilities.workspace->symbol->symbolKind) {
@@ -506,7 +508,7 @@ void ClangdLSPServer::onDiagnosticsReady
         }
         LSPDiag["clangd_fixes"] = std::move(ClangdFixes);
       }
-      if (!Diag.category.empty())
+      if (DiagOpts.SendDiagnosticCategory && !Diag.category.empty())
         LSPDiag["category"] = Diag.category;
       DiagnosticsJSON.push_back(std::move(LSPDiag));
 

Modified: clang-tools-extra/trunk/clangd/Diagnostics.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Diagnostics.h?rev=340449&r1=340448&r2=340449&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/Diagnostics.h (original)
+++ clang-tools-extra/trunk/clangd/Diagnostics.h Wed Aug 22 13:30:06 2018
@@ -27,6 +27,12 @@ struct ClangdDiagnosticOptions {
   /// If true, Clangd uses an LSP extension to embed the fixes with the
   /// diagnostics that are sent to the client.
   bool EmbedFixesInDiagnostics = false;
+
+  /// If true, Clangd uses an LSP extension to send the diagnostic's
+  /// category to the client. The category typically describes the compilation
+  /// stage during which the issue was produced, e.g. "Semantic Issue" or "Parse
+  /// Issue".
+  bool SendDiagnosticCategory = false;
 };
 
 /// Contains basic information about a diagnostic.

Modified: clang-tools-extra/trunk/clangd/Protocol.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Protocol.cpp?rev=340449&r1=340448&r2=340449&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/Protocol.cpp (original)
+++ clang-tools-extra/trunk/clangd/Protocol.cpp Wed Aug 22 13:30:06 2018
@@ -184,6 +184,7 @@ bool fromJSON(const llvm::json::Value &P
   if (!O)
     return false;
   O.map("clangdFixSupport", R.clangdFixSupport);
+  O.map("categorySupport", R.categorySupport);
   return true;
 }
 

Modified: clang-tools-extra/trunk/clangd/Protocol.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Protocol.h?rev=340449&r1=340448&r2=340449&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/Protocol.h (original)
+++ clang-tools-extra/trunk/clangd/Protocol.h Wed Aug 22 13:30:06 2018
@@ -255,6 +255,10 @@ struct PublishDiagnosticsClientCapabilit
   /// Whether the client accepts diagnostics with fixes attached using the
   /// "clangd_fixes" extension.
   bool clangdFixSupport = false;
+
+  /// Whether the client accepts diagnostics with category attached to it
+  /// using the "category" extension.
+  bool categorySupport = false;
 };
 bool fromJSON(const llvm::json::Value &,
               PublishDiagnosticsClientCapabilities &);

Modified: clang-tools-extra/trunk/test/clangd/compile-commands-path-in-initialize.test
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/compile-commands-path-in-initialize.test?rev=340449&r1=340448&r2=340449&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clangd/compile-commands-path-in-initialize.test (original)
+++ clang-tools-extra/trunk/test/clangd/compile-commands-path-in-initialize.test Wed Aug 22 13:30:06 2018
@@ -23,7 +23,6 @@
 # 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"}}}
@@ -31,7 +30,6 @@
 # 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"}

Modified: clang-tools-extra/trunk/test/clangd/compile-commands-path.test
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/compile-commands-path.test?rev=340449&r1=340448&r2=340449&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clangd/compile-commands-path.test (original)
+++ clang-tools-extra/trunk/test/clangd/compile-commands-path.test Wed Aug 22 13:30:06 2018
@@ -23,7 +23,6 @@
 # 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"}}}
@@ -31,7 +30,6 @@
 # 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"}}}
@@ -39,7 +37,6 @@
 # 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"}

Added: clang-tools-extra/trunk/test/clangd/diagnostic-category.test
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/diagnostic-category.test?rev=340449&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clangd/diagnostic-category.test (added)
+++ clang-tools-extra/trunk/test/clangd/diagnostic-category.test Wed Aug 22 13:30:06 2018
@@ -0,0 +1,43 @@
+# RUN: clangd -lit-test < %s | FileCheck -strict-whitespace %s
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{"textDocument":{"publishDiagnostics":{"categorySupport":true}}},"trace":"off"}}
+---
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"test:///foo.c","languageId":"c","version":1,"text":"struct Point {}; union Point p;"}}}
+#      CHECK:    "method": "textDocument/publishDiagnostics",
+# CHECK-NEXT:    "params": {
+# CHECK-NEXT:     "diagnostics": [
+# CHECK-NEXT:      {
+# CHECK-NEXT:        "category": "Semantic Issue",
+# CHECK-NEXT:        "message": "Use of 'Point' with tag type that does not match previous declaration\n\nfoo.c:1:8: note: previous use is here",
+# CHECK-NEXT:        "range": {
+# CHECK-NEXT:          "end": {
+# CHECK-NEXT:            "character": 22,
+# CHECK-NEXT:            "line": 0
+# CHECK-NEXT:          },
+# CHECK-NEXT:          "start": {
+# CHECK-NEXT:            "character": 17,
+# CHECK-NEXT:            "line": 0
+# CHECK-NEXT:          }
+# CHECK-NEXT:        },
+# CHECK-NEXT:        "severity": 1
+# CHECK-NEXT:      },
+# CHECK-NEXT:      {
+# CHECK-NEXT:        "message": "Previous use is here\n\nfoo.c:1:18: error: use of 'Point' with tag type that does not match previous declaration",
+# CHECK-NEXT:        "range": {
+# CHECK-NEXT:          "end": {
+# CHECK-NEXT:            "character": 12,
+# CHECK-NEXT:            "line": 0
+# CHECK-NEXT:          },
+# CHECK-NEXT:          "start": {
+# CHECK-NEXT:            "character": 7,
+# CHECK-NEXT:            "line": 0
+# CHECK-NEXT:          }
+# CHECK-NEXT:        },
+# CHECK-NEXT:        "severity": 3
+# CHECK-NEXT:      }
+# CHECK-NEXT:    ],
+# CHECK-NEXT:    "uri": "file://{{.*}}/foo.c"
+# CHECK-NEXT:  }
+---
+{"jsonrpc":"2.0","id":4,"method":"shutdown"}
+---
+{"jsonrpc":"2.0","method":"exit"}

Modified: clang-tools-extra/trunk/test/clangd/diagnostics.test
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/diagnostics.test?rev=340449&r1=340448&r2=340449&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clangd/diagnostics.test (original)
+++ clang-tools-extra/trunk/test/clangd/diagnostics.test Wed Aug 22 13:30:06 2018
@@ -6,7 +6,6 @@
 # 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": {

Modified: clang-tools-extra/trunk/test/clangd/did-change-configuration-params.test
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/did-change-configuration-params.test?rev=340449&r1=340448&r2=340449&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clangd/did-change-configuration-params.test (original)
+++ clang-tools-extra/trunk/test/clangd/did-change-configuration-params.test Wed Aug 22 13:30:06 2018
@@ -24,7 +24,6 @@
 # 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": {

Modified: clang-tools-extra/trunk/test/clangd/execute-command.test
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/execute-command.test?rev=340449&r1=340448&r2=340449&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clangd/execute-command.test (original)
+++ clang-tools-extra/trunk/test/clangd/execute-command.test Wed Aug 22 13:30:06 2018
@@ -6,7 +6,6 @@
 # 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": {

Modified: clang-tools-extra/trunk/test/clangd/extra-flags.test
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/extra-flags.test?rev=340449&r1=340448&r2=340449&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clangd/extra-flags.test (original)
+++ clang-tools-extra/trunk/test/clangd/extra-flags.test Wed Aug 22 13:30:06 2018
@@ -6,7 +6,6 @@
 # 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": {
@@ -29,7 +28,6 @@
 # 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": {

Modified: clang-tools-extra/trunk/test/clangd/fixits-embed-in-diagnostic.test
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/fixits-embed-in-diagnostic.test?rev=340449&r1=340448&r2=340449&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clangd/fixits-embed-in-diagnostic.test (original)
+++ clang-tools-extra/trunk/test/clangd/fixits-embed-in-diagnostic.test Wed Aug 22 13:30:06 2018
@@ -6,7 +6,6 @@
 # CHECK-NEXT:    "params": {
 # CHECK-NEXT:     "diagnostics": [
 # CHECK-NEXT:      {
-# CHECK-NEXT:        "category": "Semantic Issue",
 # CHECK-NEXT:        "clangd_fixes": [
 # CHECK-NEXT:          {
 # CHECK-NEXT:            "edit": {

Modified: clang-tools-extra/trunk/test/clangd/fixits.test
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/fixits.test?rev=340449&r1=340448&r2=340449&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clangd/fixits.test (original)
+++ clang-tools-extra/trunk/test/clangd/fixits.test Wed Aug 22 13:30:06 2018
@@ -6,7 +6,6 @@
 # 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": {




More information about the cfe-commits mailing list