[gnome-builder] lsp: Send diagnostics with codeActions



commit c011a5333c88a8a488934490debcfcb9180b3fd1
Author: JCWasmx86 <JCWasmx86 t-online de>
Date:   Thu Feb 10 19:24:29 2022 +0100

    lsp: Send diagnostics with codeActions
    
    This fixes at least the hlint-Plugin for the Haskell-Language-Server.

 src/libide/code/ide-buffer.c                  |   4 +
 src/libide/code/ide-code-action-provider.c    |  18 +++
 src/libide/code/ide-code-action-provider.h    |  24 ++--
 src/libide/lsp/ide-lsp-client.c               |   9 +-
 src/libide/lsp/ide-lsp-code-action-provider.c | 111 ++++++++++++++++++-
 src/libide/lsp/ide-lsp-code-action-provider.h |   9 +-
 src/libide/lsp/ide-lsp-code-action.c          |  11 +-
 src/libide/lsp/ide-lsp-diagnostic.c           | 152 ++++++++++++++++++++++++++
 src/libide/lsp/ide-lsp-diagnostic.h           |  52 +++++++++
 src/libide/lsp/libide-lsp.h                   |   1 +
 src/libide/lsp/meson.build                    |   2 +
 11 files changed, 366 insertions(+), 27 deletions(-)
---
diff --git a/src/libide/code/ide-buffer.c b/src/libide/code/ide-buffer.c
index 0c57854be..1d0d53173 100644
--- a/src/libide/code/ide-buffer.c
+++ b/src/libide/code/ide-buffer.c
@@ -2418,7 +2418,11 @@ ide_buffer_set_diagnostics (IdeBuffer      *self,
 
   if (diagnostics)
     {
+      IdeCodeActionProvider *code_action_provider;
       self->diagnostics = g_object_ref (diagnostics);
+      code_action_provider = ide_extension_adapter_get_extension (self->code_action_provider);
+      if (code_action_provider)
+        ide_code_action_provider_set_diagnostics (IDE_CODE_ACTION_PROVIDER (code_action_provider), 
self->diagnostics);
       ide_buffer_apply_diagnostics (self);
     }
 
diff --git a/src/libide/code/ide-code-action-provider.c b/src/libide/code/ide-code-action-provider.c
index a85673170..4770a6f87 100644
--- a/src/libide/code/ide-code-action-provider.c
+++ b/src/libide/code/ide-code-action-provider.c
@@ -58,11 +58,20 @@ ide_code_action_provider_real_query_finish (IdeCodeActionProvider  *self,
   return g_task_propagate_pointer (G_TASK (result), error);
 }
 
+static void
+ide_code_action_provider_real_set_diagnostics (IdeCodeActionProvider  *self,
+                                               IdeDiagnostics         *diags)
+{
+  g_assert (IDE_IS_CODE_ACTION_PROVIDER (self));
+  g_assert (!diags || IDE_IS_DIAGNOSTICS (diags));
+}
+
 static void
 ide_code_action_provider_default_init (IdeCodeActionProviderInterface *iface)
 {
   iface->query_async = ide_code_action_provider_real_query_async;
   iface->query_finish = ide_code_action_provider_real_query_finish;
+  iface->set_diagnostics = ide_code_action_provider_real_set_diagnostics;
 }
 
 void
@@ -114,3 +123,12 @@ ide_code_action_provider_load (IdeCodeActionProvider *self)
   if (IDE_CODE_ACTION_PROVIDER_GET_IFACE (self)->load)
     IDE_CODE_ACTION_PROVIDER_GET_IFACE (self)->load (self);
 }
+
+void
+ide_code_action_provider_set_diagnostics (IdeCodeActionProvider *self,
+                                          IdeDiagnostics        *diags)
+{
+  g_return_if_fail (IDE_IS_CODE_ACTION_PROVIDER (self));
+
+  IDE_CODE_ACTION_PROVIDER_GET_IFACE (self)->set_diagnostics (self, diags);
+}
diff --git a/src/libide/code/ide-code-action-provider.h b/src/libide/code/ide-code-action-provider.h
index 55bd6f87d..7ecbae9b0 100644
--- a/src/libide/code/ide-code-action-provider.h
+++ b/src/libide/code/ide-code-action-provider.h
@@ -28,6 +28,7 @@
 #include <libide-core.h>
 
 #include "ide-code-types.h"
+#include "ide-diagnostics.h"
 
 G_BEGIN_DECLS
 
@@ -49,19 +50,24 @@ struct _IdeCodeActionProviderInterface
   GPtrArray* (*query_finish)       (IdeCodeActionProvider  *self,
                                     GAsyncResult           *result,
                                     GError                **error);
+  void       (*set_diagnostics)    (IdeCodeActionProvider  *self,
+                                    IdeDiagnostics         *diags);
 };
 
 IDE_AVAILABLE_IN_42
-void     ide_code_action_provider_load           (IdeCodeActionProvider *self);
+void       ide_code_action_provider_load            (IdeCodeActionProvider  *self);
 IDE_AVAILABLE_IN_42
-void     ide_code_action_provider_query_async    (IdeCodeActionProvider *self,
-                                                  IdeBuffer             *buffer,
-                                                  GCancellable          *cancellable,
-                                                  GAsyncReadyCallback    callback,
-                                                  gpointer               user_data);
+void       ide_code_action_provider_query_async     (IdeCodeActionProvider  *self,
+                                                     IdeBuffer              *buffer,
+                                                     GCancellable           *cancellable,
+                                                     GAsyncReadyCallback     callback,
+                                                     gpointer                user_data);
 IDE_AVAILABLE_IN_42
-GPtrArray* ide_code_action_provider_query_finish (IdeCodeActionProvider *self,
-                                                  GAsyncResult          *result,
-                                                  GError               **error);
+GPtrArray *ide_code_action_provider_query_finish    (IdeCodeActionProvider  *self,
+                                                     GAsyncResult           *result,
+                                                     GError                **error);
+IDE_AVAILABLE_IN_42
+void       ide_code_action_provider_set_diagnostics (IdeCodeActionProvider  *self,
+                                                     IdeDiagnostics         *diags);
 
 G_END_DECLS
diff --git a/src/libide/lsp/ide-lsp-client.c b/src/libide/lsp/ide-lsp-client.c
index d701f7cdb..43a63ff0b 100644
--- a/src/libide/lsp/ide-lsp-client.c
+++ b/src/libide/lsp/ide-lsp-client.c
@@ -33,6 +33,7 @@
 #include <unistd.h>
 
 #include "ide-lsp-client.h"
+#include "ide-lsp-diagnostic.h"
 #include "ide-lsp-enums.h"
 #include "ide-lsp-workspace-edit.h"
 
@@ -687,7 +688,7 @@ ide_lsp_client_translate_diagnostics (IdeLspClient *self,
     {
       g_autoptr(IdeLocation) begin_loc = NULL;
       g_autoptr(IdeLocation) end_loc = NULL;
-      g_autoptr(IdeDiagnostic) diag = NULL;
+      g_autoptr(IdeLspDiagnostic) diag = NULL;
       g_autoptr(GVariant) range = NULL;
       const gchar *message = NULL;
       const gchar *source = NULL;
@@ -764,10 +765,10 @@ ide_lsp_client_translate_diagnostics (IdeLspClient *self,
             }
         }
 
-      diag = ide_diagnostic_new (severity, message, begin_loc);
+      diag = ide_lsp_diagnostic_new (severity, message, begin_loc, value);
       if (priv->use_markdown_in_diagnostics)
-        ide_diagnostic_set_marked_kind (diag, IDE_MARKED_KIND_MARKDOWN);
-      ide_diagnostic_take_range (diag, ide_range_new (begin_loc, end_loc));
+        ide_diagnostic_set_marked_kind (IDE_DIAGNOSTIC (diag), IDE_MARKED_KIND_MARKDOWN);
+      ide_diagnostic_take_range (IDE_DIAGNOSTIC (diag), ide_range_new (begin_loc, end_loc));
 
       g_ptr_array_add (ar, g_steal_pointer (&diag));
     }
diff --git a/src/libide/lsp/ide-lsp-code-action-provider.c b/src/libide/lsp/ide-lsp-code-action-provider.c
index 7f12aeed3..000f72482 100644
--- a/src/libide/lsp/ide-lsp-code-action-provider.c
+++ b/src/libide/lsp/ide-lsp-code-action-provider.c
@@ -28,21 +28,27 @@
 #include <libide-threading.h>
 
 #include "ide-lsp-code-action.h"
+#include "ide-lsp-diagnostic.h"
 #include "ide-lsp-code-action-provider.h"
 #include "ide-lsp-workspace-edit.h"
 
 typedef struct
 {
   IdeLspClient *client;
+  IdeDiagnostics *diagnostics;
 } IdeLspCodeActionProviderPrivate;
 
 enum {
   PROP_0,
   PROP_CLIENT,
+  PROP_DIAGNOSTICS,
   N_PROPS
 };
 
-static void code_action_provider_iface_init (IdeCodeActionProviderInterface *iface);
+static void code_action_provider_iface_init              (IdeCodeActionProviderInterface *iface);
+static void ide_lsp_code_action_provider_set_diagnostics (IdeCodeActionProvider          
*code_action_provider,
+                                                          IdeDiagnostics                 *diags);
+
 
 G_DEFINE_TYPE_WITH_CODE (IdeLspCodeActionProvider, ide_lsp_code_action_provider, IDE_TYPE_OBJECT,
                          G_ADD_PRIVATE (IdeLspCodeActionProvider)
@@ -68,6 +74,24 @@ ide_lsp_code_action_provider_get_client (IdeLspCodeActionProvider *self)
   return priv->client;
 }
 
+/**
+ * ide_lsp_code_action_provider_get_diagnostics:
+ * @self: a #IdeLspCodeActionProvider
+ *
+ * Gets the diagnostics to use for the code action query.
+ *
+ * Returns: (transfer none) (nullable): An #IdeDiagnostics or %NULL.
+ */
+IdeDiagnostics *
+ide_lsp_code_action_provider_get_diagnostics (IdeLspCodeActionProvider *self)
+{
+  IdeLspCodeActionProviderPrivate *priv = ide_lsp_code_action_provider_get_instance_private (self);
+
+  g_return_val_if_fail (IDE_IS_LSP_CODE_ACTION_PROVIDER (self), NULL);
+
+  return priv->diagnostics;
+}
+
 void
 ide_lsp_code_action_provider_set_client (IdeLspCodeActionProvider *self,
                               IdeLspClient    *client)
@@ -87,6 +111,7 @@ ide_lsp_code_action_provider_finalize (GObject *object)
   IdeLspCodeActionProviderPrivate *priv = ide_lsp_code_action_provider_get_instance_private (self);
 
   g_clear_object (&priv->client);
+  g_clear_object (&priv->diagnostics);
 
   G_OBJECT_CLASS (ide_lsp_code_action_provider_parent_class)->finalize (object);
 }
@@ -105,6 +130,10 @@ ide_lsp_code_action_provider_get_property (GObject    *object,
       g_value_set_object (value, ide_lsp_code_action_provider_get_client (self));
       break;
 
+    case PROP_DIAGNOSTICS:
+      g_value_set_object (value, ide_lsp_code_action_provider_get_diagnostics (self));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -124,6 +153,10 @@ ide_lsp_code_action_provider_set_property (GObject      *object,
       ide_lsp_code_action_provider_set_client (self, g_value_get_object (value));
       break;
 
+    case PROP_DIAGNOSTICS:
+      ide_code_action_provider_set_diagnostics (IDE_CODE_ACTION_PROVIDER (self), g_value_get_object (value));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -145,6 +178,13 @@ ide_lsp_code_action_provider_class_init (IdeLspCodeActionProviderClass *klass)
                          IDE_TYPE_LSP_CLIENT,
                          (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
+  properties [PROP_DIAGNOSTICS] =
+    g_param_spec_object ("diagnostics",
+                         "Diagnostics",
+                         "The diagnostics used to send to the codeAction RPC",
+                         IDE_TYPE_DIAGNOSTICS,
+                         (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
   g_object_class_install_properties (object_class, N_PROPS, properties);
 }
 
@@ -234,10 +274,16 @@ ide_lsp_code_action_provider_query_async (IdeCodeActionProvider *code_action_pro
   IdeLspCodeActionProviderPrivate *priv = ide_lsp_code_action_provider_get_instance_private (self);
   g_autoptr(GVariant) params = NULL;
   g_autoptr(IdeTask) task = NULL;
-  IdeRange* selection = NULL;
-  IdeLocation* start = NULL;
-  IdeLocation* end = NULL;
+  IdeRange *selection = NULL;
+  IdeLocation *start = NULL;
+  IdeLocation *end = NULL;
   g_autofree gchar *uri = NULL;
+  g_autoptr(GVariant) diagnostics = NULL;
+  g_autoptr(GVariant) diags_v = NULL;
+  g_autoptr(GPtrArray) matching = NULL;
+  GVariantDict dict;
+
+  IDE_ENTRY;
 
   g_assert (IDE_IS_LSP_CODE_ACTION_PROVIDER (self));
   g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
@@ -249,6 +295,44 @@ ide_lsp_code_action_provider_query_async (IdeCodeActionProvider *code_action_pro
   selection = ide_buffer_get_selection_range (buffer);
   start = ide_range_get_begin (selection);
   end = ide_range_get_end (selection);
+  matching = g_ptr_array_new_with_free_func ((GDestroyNotify) g_variant_unref);
+
+  if (priv->diagnostics != NULL)
+    {
+      guint n_items = ide_diagnostics_get_size (priv->diagnostics);
+
+      for (guint i = 0; i < n_items; i++)
+        {
+          g_autoptr(IdeDiagnostic) diag = g_list_model_get_item (G_LIST_MODEL (priv->diagnostics), i);
+          g_autoptr(GVariant) var = NULL;
+          IdeLocation *location = NULL;
+          gint line = 0;
+
+          if (!IDE_IS_LSP_DIAGNOSTIC (diag))
+            continue;
+
+          location = ide_diagnostic_get_location (diag);
+          if (!location || !start || !end)
+              continue;
+
+          line = ide_location_get_line (location);
+          if (ide_location_get_line (start) > line || ide_location_get_line (end) < line)
+              continue;
+
+          if (!(var = ide_lsp_diagnostic_dup_raw (IDE_LSP_DIAGNOSTIC (diag))))
+            continue;
+
+          g_ptr_array_add (matching, g_steal_pointer (&var));
+        }
+    }
+
+  diagnostics = g_variant_new_array (G_VARIANT_TYPE_VARDICT,
+                                     (GVariant **)(gpointer)matching->pdata,
+                                     matching->len);
+
+  g_variant_dict_init (&dict, NULL);
+  g_variant_dict_insert_value (&dict, "diagnostics", g_variant_ref (diagnostics));
+  diags_v = g_variant_take_ref (g_variant_dict_end (&dict));
 
   params = JSONRPC_MESSAGE_NEW (
     "textDocument", "{",
@@ -265,7 +349,7 @@ ide_lsp_code_action_provider_query_async (IdeCodeActionProvider *code_action_pro
           "}",
         "}",
     "context", "{",
-      "diagnostics", "[","]",
+      JSONRPC_MESSAGE_PUT_VARIANT (diags_v),
     "}"
   );
 
@@ -275,6 +359,8 @@ ide_lsp_code_action_provider_query_async (IdeCodeActionProvider *code_action_pro
                              cancellable,
                              ide_lsp_code_action_provider_query_call_cb,
                              g_steal_pointer (&task));
+
+  IDE_EXIT;
 }
 
 static GPtrArray*
@@ -288,9 +374,24 @@ ide_lsp_code_action_provider_query_finish (IdeCodeActionProvider  *self,
   return ide_task_propagate_pointer (IDE_TASK (result), error);
 }
 
+static void
+ide_lsp_code_action_provider_set_diagnostics (IdeCodeActionProvider *code_action_provider,
+                                              IdeDiagnostics        *diags)
+{
+  IdeLspCodeActionProvider *self = (IdeLspCodeActionProvider *)code_action_provider;
+  IdeLspCodeActionProviderPrivate *priv = ide_lsp_code_action_provider_get_instance_private (self);
+
+  g_assert (IDE_IS_LSP_CODE_ACTION_PROVIDER (self));
+  g_assert (!diags || IDE_IS_DIAGNOSTICS (diags));
+
+  if (g_set_object (&priv->diagnostics, diags))
+    g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_DIAGNOSTICS]);
+}
+
 static void
 code_action_provider_iface_init (IdeCodeActionProviderInterface *iface)
 {
   iface->query_async = ide_lsp_code_action_provider_query_async;
   iface->query_finish = ide_lsp_code_action_provider_query_finish;
+  iface->set_diagnostics = ide_lsp_code_action_provider_set_diagnostics;
 }
diff --git a/src/libide/lsp/ide-lsp-code-action-provider.h b/src/libide/lsp/ide-lsp-code-action-provider.h
index 2454846bc..7493c5725 100644
--- a/src/libide/lsp/ide-lsp-code-action-provider.h
+++ b/src/libide/lsp/ide-lsp-code-action-provider.h
@@ -41,9 +41,12 @@ struct _IdeLspCodeActionProviderClass
 };
 
 IDE_AVAILABLE_IN_42
-void          ide_lsp_code_action_provider_set_client (IdeLspCodeActionProvider *self,
-                                                       IdeLspClient             *client);
+void            ide_lsp_code_action_provider_set_client      (IdeLspCodeActionProvider *self,
+                                                              IdeLspClient             *client);
 IDE_AVAILABLE_IN_42
-IdeLspClient *ide_lsp_code_action_provider_get_client (IdeLspCodeActionProvider *self);
+IdeLspClient   *ide_lsp_code_action_provider_get_client      (IdeLspCodeActionProvider *self);
+IDE_AVAILABLE_IN_42
+IdeDiagnostics *ide_lsp_code_action_provider_get_diagnostics (IdeLspCodeActionProvider *self);
+
 
 G_END_DECLS
diff --git a/src/libide/lsp/ide-lsp-code-action.c b/src/libide/lsp/ide-lsp-code-action.c
index c00f9b06e..5beb5e56c 100644
--- a/src/libide/lsp/ide-lsp-code-action.c
+++ b/src/libide/lsp/ide-lsp-code-action.c
@@ -319,12 +319,11 @@ ide_lsp_code_action_execute_async(IdeCodeAction       *code_action,
   else
     {
       g_autoptr(GVariant) params = NULL;
-
-      params = JSONRPC_MESSAGE_NEW(
-        "command", JSONRPC_MESSAGE_PUT_STRING(priv->command),
-        "arguments", "{", JSONRPC_MESSAGE_PUT_VARIANT(priv->arguments), "}"
-      );
-
+      GVariantDict dict;
+      g_variant_dict_init (&dict, NULL);
+      g_variant_dict_insert_value (&dict, "arguments", priv->arguments);
+      g_variant_dict_insert (&dict, "command", "s", priv->command);
+      params =  g_variant_take_ref (g_variant_dict_end (&dict));
       ide_lsp_client_call_async(priv->client,
                                 "workspace/executeCommand",
                                 params,
diff --git a/src/libide/lsp/ide-lsp-diagnostic.c b/src/libide/lsp/ide-lsp-diagnostic.c
new file mode 100644
index 000000000..0b2ef79df
--- /dev/null
+++ b/src/libide/lsp/ide-lsp-diagnostic.c
@@ -0,0 +1,152 @@
+/* ide-lsp-diagnostic.c
+ *
+ * Copyright 2022 JCWasmx86 <JCWasmx86 t-online de>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "ide-lsp-diagnostic"
+
+#include "config.h"
+
+#include "ide-lsp-diagnostic.h"
+
+typedef struct
+{
+  GVariant *raw;
+} IdeLspDiagnosticPrivate;
+
+enum {
+  PROP_0,
+  PROP_RAW,
+  N_PROPS
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (IdeLspDiagnostic, ide_lsp_diagnostic, IDE_TYPE_DIAGNOSTIC)
+
+static GParamSpec *properties [N_PROPS];
+
+IdeLspDiagnostic *
+ide_lsp_diagnostic_new (IdeDiagnosticSeverity  severity,
+                        const gchar           *message,
+                        IdeLocation           *location,
+                        GVariant              *raw_value)
+
+{
+  return g_object_new (IDE_TYPE_LSP_DIAGNOSTIC,
+                       "severity", severity,
+                       "location", location,
+                       "text", message,
+                       "raw", raw_value,
+                       NULL);
+}
+
+static void
+ide_lsp_diagnostic_finalize (GObject *object)
+{
+  IdeLspDiagnostic *self = (IdeLspDiagnostic *)object;
+  IdeLspDiagnosticPrivate *priv = ide_lsp_diagnostic_get_instance_private (self);
+
+  g_clear_pointer (&priv->raw, g_variant_unref);
+
+  G_OBJECT_CLASS (ide_lsp_diagnostic_parent_class)->finalize (object);
+}
+
+static void
+ide_lsp_diagnostic_get_property (GObject    *object,
+                                 guint       prop_id,
+                                 GValue     *value,
+                                 GParamSpec *pspec)
+{
+  IdeLspDiagnostic *self = IDE_LSP_DIAGNOSTIC (object);
+  IdeLspDiagnosticPrivate *priv = ide_lsp_diagnostic_get_instance_private (self);
+
+  switch (prop_id)
+    {
+    case PROP_RAW:
+      g_value_set_variant (value, priv->raw);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+ide_lsp_diagnostic_set_property (GObject      *object,
+                                 guint         prop_id,
+                                 const GValue *value,
+                                 GParamSpec   *pspec)
+{
+  IdeLspDiagnostic *self = (IdeLspDiagnostic *)object;
+  IdeLspDiagnosticPrivate *priv = ide_lsp_diagnostic_get_instance_private (self);
+
+  switch (prop_id)
+    {
+    case PROP_RAW:
+      priv->raw = g_value_dup_variant (value);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+ide_lsp_diagnostic_class_init (IdeLspDiagnosticClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->finalize = ide_lsp_diagnostic_finalize;
+  object_class->get_property = ide_lsp_diagnostic_get_property;
+  object_class->set_property = ide_lsp_diagnostic_set_property;
+
+  properties [PROP_RAW] =
+    g_param_spec_variant ("raw",
+                          "Raw",
+                          "Raw diagnostic",
+                          g_variant_type_new ("a{sv}"),
+                          NULL,
+                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+
+  g_object_class_install_properties (object_class, N_PROPS, properties);
+}
+
+static void
+ide_lsp_diagnostic_init (IdeLspDiagnostic *self)
+{
+}
+
+/**
+ * ide_lsp_diagnostic_dup_raw:
+ * @self: an #IdeLspDiagnostic
+ *
+ * Increments the reference count of the underlying diagnostic variant and
+ * returns it.
+ *
+ * Returns: (transfer full): a #GVariant with it's reference count incremented
+ *
+ * Since: 42.0
+ */
+GVariant *
+ide_lsp_diagnostic_dup_raw (IdeLspDiagnostic *self)
+{
+  IdeLspDiagnosticPrivate *priv = ide_lsp_diagnostic_get_instance_private (self);
+
+  g_return_val_if_fail (IDE_IS_LSP_DIAGNOSTIC (self), NULL);
+
+  return g_variant_ref (priv->raw);
+}
diff --git a/src/libide/lsp/ide-lsp-diagnostic.h b/src/libide/lsp/ide-lsp-diagnostic.h
new file mode 100644
index 000000000..ed0f3efde
--- /dev/null
+++ b/src/libide/lsp/ide-lsp-diagnostic.h
@@ -0,0 +1,52 @@
+/* ide-lsp-diagnostic.h
+ *
+ * Copyright 2022 JCWasmx86 <JCWasmx86 t-online de>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#if !defined (IDE_LSP_INSIDE) && !defined (IDE_LSP_COMPILATION)
+# error "Only <libide-lsp.h> can be included directly."
+#endif
+
+#include <libide-code.h>
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_LSP_DIAGNOSTIC (ide_lsp_diagnostic_get_type())
+
+IDE_AVAILABLE_IN_42
+G_DECLARE_DERIVABLE_TYPE (IdeLspDiagnostic, ide_lsp_diagnostic, IDE, LSP_DIAGNOSTIC, IdeDiagnostic)
+
+struct _IdeLspDiagnosticClass
+{
+  IdeDiagnosticClass parent_class;
+
+  /*< private >*/
+  gpointer _reserved[16];
+};
+
+IDE_AVAILABLE_IN_42
+IdeLspDiagnostic *ide_lsp_diagnostic_new     (IdeDiagnosticSeverity  severity,
+                                              const gchar           *message,
+                                              IdeLocation           *location,
+                                              GVariant              *raw_value);
+IDE_AVAILABLE_IN_42
+GVariant         *ide_lsp_diagnostic_dup_raw (IdeLspDiagnostic      *self);
+
+G_END_DECLS
diff --git a/src/libide/lsp/libide-lsp.h b/src/libide/lsp/libide-lsp.h
index 8779ea553..765bd7176 100644
--- a/src/libide/lsp/libide-lsp.h
+++ b/src/libide/lsp/libide-lsp.h
@@ -32,6 +32,7 @@
 #include "ide-lsp-completion-item.h"
 #include "ide-lsp-completion-provider.h"
 #include "ide-lsp-completion-results.h"
+#include "ide-lsp-diagnostic.h"
 #include "ide-lsp-diagnostic-provider.h"
 #include "ide-lsp-enums.h"
 #include "ide-lsp-formatter.h"
diff --git a/src/libide/lsp/meson.build b/src/libide/lsp/meson.build
index 4c665b260..620170d74 100644
--- a/src/libide/lsp/meson.build
+++ b/src/libide/lsp/meson.build
@@ -14,6 +14,7 @@ libide_lsp_public_headers = [
   'ide-lsp-completion-item.h',
   'ide-lsp-completion-provider.h',
   'ide-lsp-completion-results.h',
+  'ide-lsp-diagnostic.h',
   'ide-lsp-diagnostic-provider.h',
   'ide-lsp-formatter.h',
   'ide-lsp-highlighter.h',
@@ -47,6 +48,7 @@ libide_lsp_public_sources = [
   'ide-lsp-completion-item.c',
   'ide-lsp-completion-provider.c',
   'ide-lsp-completion-results.c',
+  'ide-lsp-diagnostic.c',
   'ide-lsp-diagnostic-provider.c',
   'ide-lsp-formatter.c',
   'ide-lsp-highlighter.c',


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