[gnome-builder] lsp: Accept "Deprecated" diagnostic tag



commit 01e46ec8ce30ca97536a649fc60e347bca49b7c9
Author: James Westman <james jwestman net>
Date:   Tue Apr 20 20:11:35 2021 -0500

    lsp: Accept "Deprecated" diagnostic tag
    
    A Diagnostic object returned from the language server can contain a
    "tags" field denoting specific types of diagnostics, such as
    deprecations or unused code.
    
    See
    <https://microsoft.github.io/language-server-protocol/specifications/specification-current/#diagnostic>.

 src/libide/lsp/ide-lsp-client.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
---
diff --git a/src/libide/lsp/ide-lsp-client.c b/src/libide/lsp/ide-lsp-client.c
index 3fd20efdf..f9a10502c 100644
--- a/src/libide/lsp/ide-lsp-client.c
+++ b/src/libide/lsp/ide-lsp-client.c
@@ -80,6 +80,11 @@ enum {
   SEVERITY_HINT        = 4,
 };
 
+enum {
+  TAG_UNNECESSARY      = 1,
+  TAG_DEPRECATED       = 2,
+};
+
 enum {
   TEXT_DOCUMENT_SYNC_NONE,
   TEXT_DOCUMENT_SYNC_FULL,
@@ -680,6 +685,8 @@ ide_lsp_client_translate_diagnostics (IdeLspClient *self,
       g_autoptr(GVariant) range = NULL;
       const gchar *message = NULL;
       const gchar *source = NULL;
+      g_autoptr(GVariantIter) tags = NULL;
+      GVariant *current_tag;
       gint64 severity = 0;
       gboolean success;
       struct {
@@ -696,6 +703,7 @@ ide_lsp_client_translate_diagnostics (IdeLspClient *self,
       /* Optional Fields */
       JSONRPC_MESSAGE_PARSE (value, "severity", JSONRPC_MESSAGE_GET_INT64 (&severity));
       JSONRPC_MESSAGE_PARSE (value, "source", JSONRPC_MESSAGE_GET_STRING (&source));
+      JSONRPC_MESSAGE_PARSE (value, "tags", JSONRPC_MESSAGE_GET_ITER (&tags));
 
       /* Extract location information */
       success = JSONRPC_MESSAGE_PARSE (range,
@@ -732,6 +740,21 @@ ide_lsp_client_translate_diagnostics (IdeLspClient *self,
           break;
         }
 
+      while (tags != NULL && g_variant_iter_loop (tags, "v", &current_tag))
+        {
+          if (!g_variant_is_of_type (current_tag, G_VARIANT_TYPE_INT64))
+            continue;
+
+          switch (g_variant_get_int64 (current_tag))
+            {
+            case TAG_DEPRECATED:
+              severity = IDE_DIAGNOSTIC_DEPRECATED;
+              break;
+            default:
+              break;
+            }
+        }
+
       diag = ide_diagnostic_new (severity, message, begin_loc);
       ide_diagnostic_take_range (diag, ide_range_new (begin_loc, end_loc));
 
@@ -1646,6 +1669,13 @@ ide_lsp_client_start (IdeLspClient *self)
             "]",
           "}",
         "}",
+        "publishDiagnostics", "{",
+          "tagSupport", "{",
+            "valueSet", "[",
+              JSONRPC_MESSAGE_PUT_INT64 (1),
+            "]",
+          "}",
+        "}",
       "}",
       "window", "{",
         "workDoneProgress", JSONRPC_MESSAGE_PUT_BOOLEAN (TRUE),


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]