[gnome-builder] lsp: add initialization-options property



commit 952e37869455a7bfccf05f3358fd830e1bc99aea
Author: Christian Hergert <chergert redhat com>
Date:   Tue Dec 21 15:49:55 2021 -0800

    lsp: add initialization-options property
    
    This allows the initializationOptions to be passed to the LSP when the
    client is initialized. Set it before calling _start().

 src/libide/lsp/ide-lsp-client.c | 63 +++++++++++++++++++++++++++++
 src/libide/lsp/ide-lsp-client.h | 87 ++++++++++++++++++++++-------------------
 2 files changed, 109 insertions(+), 41 deletions(-)
---
diff --git a/src/libide/lsp/ide-lsp-client.c b/src/libide/lsp/ide-lsp-client.c
index 64004e371..d701f7cdb 100644
--- a/src/libide/lsp/ide-lsp-client.c
+++ b/src/libide/lsp/ide-lsp-client.c
@@ -60,6 +60,7 @@ typedef struct
   GHashTable     *diagnostics_by_file;
   GPtrArray      *languages;
   GVariant       *server_capabilities;
+  GVariant       *initialization_options;
   IdeLspTrace     trace;
   gchar          *root_uri;
   gboolean        initialized;
@@ -95,6 +96,7 @@ enum {
 
 enum {
   PROP_0,
+  PROP_INITIALIZATION_OPTIONS,
   PROP_IO_STREAM,
   PROP_SERVER_CAPABILITIES,
   PROP_TRACE,
@@ -1207,6 +1209,14 @@ ide_lsp_client_class_init (IdeLspClientClass *klass)
   klass->notification = ide_lsp_client_real_notification;
   klass->supports_language = ide_lsp_client_real_supports_language;
 
+  properties [PROP_INITIALIZATION_OPTIONS] =
+    g_param_spec_variant ("initialization-options",
+                          "Initialization Options",
+                          "Initialization Options",
+                          G_VARIANT_TYPE_ANY,
+                          NULL,
+                          (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
+
   properties [PROP_USE_MARKDOWN_IN_DIAGNOSTICS] =
     g_param_spec_boolean ("use-markdown-in-diagnostics",
                           "Use Markdown in Diagnostics",
@@ -1676,6 +1686,9 @@ ide_lsp_client_start (IdeLspClient *self)
       "window", "{",
         "workDoneProgress", JSONRPC_MESSAGE_PUT_BOOLEAN (TRUE),
       "}",
+    "}",
+    "initializationOptions", "{",
+      JSONRPC_MESSAGE_PUT_VARIANT (priv->initialization_options),
     "}"
   );
 
@@ -2159,3 +2172,53 @@ ide_lsp_client_get_server_capabilities (IdeLspClient *self)
 
   return priv->server_capabilities;
 }
+
+/**
+ * ide_lsp_client_set_initialization_options:
+ * @self: a [class@LspClient]
+ * @options: (nullable): a #GVariant or %NULL
+ *
+ * Sets the `initilizationOptions` to send to the language server
+ * when the server is initialized.
+ *
+ * if @options is floating, the floating reference will be taken
+ * when calling this function otherwise the reference count of
+ * @options will be incremented by one.
+ *
+ * Since: 42.0
+ */
+void
+ide_lsp_client_set_initialization_options (IdeLspClient *self,
+                                           GVariant     *options)
+{
+  IdeLspClientPrivate *priv = ide_lsp_client_get_instance_private (self);
+
+  g_return_if_fail (IDE_IS_LSP_CLIENT (self));
+
+  if (options == priv->initialization_options)
+    return;
+
+  g_clear_pointer (&priv->initialization_options, g_variant_unref);
+  if (options)
+    priv->initialization_options = g_variant_ref_sink (options);
+
+  g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_INITIALIZATION_OPTIONS]);
+}
+
+/**
+ * ide_lsp_client_get_initialization_options:
+ * @self: a [class@LspClient]
+ *
+ * Gets the initialization options for the client.
+ *
+ * Returns: (transfer none) (nullable): a [struct@GLib.Variant] or %NULL
+ */
+GVariant *
+ide_lsp_client_get_initialization_options (IdeLspClient *self)
+{
+  IdeLspClientPrivate *priv = ide_lsp_client_get_instance_private (self);
+
+  g_return_val_if_fail (IDE_IS_LSP_CLIENT (self), NULL);
+
+  return priv->initialization_options;
+}
diff --git a/src/libide/lsp/ide-lsp-client.h b/src/libide/lsp/ide-lsp-client.h
index 66a4ea74e..f73f5cb74 100644
--- a/src/libide/lsp/ide-lsp-client.h
+++ b/src/libide/lsp/ide-lsp-client.h
@@ -60,59 +60,64 @@ struct _IdeLspClientClass
 };
 
 IDE_AVAILABLE_IN_3_32
-IdeLspClient *ide_lsp_client_new                      (GIOStream            *io_stream);
+IdeLspClient *ide_lsp_client_new                        (GIOStream            *io_stream);
 IDE_AVAILABLE_IN_3_36
-IdeLspTrace   ide_lsp_client_get_trace                (IdeLspClient         *self);
+IdeLspTrace   ide_lsp_client_get_trace                  (IdeLspClient         *self);
 IDE_AVAILABLE_IN_3_36
-void          ide_lsp_client_set_trace                (IdeLspClient         *self,
-                                                       IdeLspTrace           trace);
+void          ide_lsp_client_set_trace                  (IdeLspClient         *self,
+                                                         IdeLspTrace           trace);
 IDE_AVAILABLE_IN_3_36
-GVariant     *ide_lsp_client_get_server_capabilities  (IdeLspClient         *self);
+GVariant     *ide_lsp_client_get_server_capabilities    (IdeLspClient         *self);
 IDE_AVAILABLE_IN_3_32
-void          ide_lsp_client_add_language             (IdeLspClient         *self,
-                                                       const gchar          *language_id);
+void          ide_lsp_client_add_language               (IdeLspClient         *self,
+                                                         const gchar          *language_id);
 IDE_AVAILABLE_IN_3_38
-void          ide_lsp_client_set_root_uri             (IdeLspClient         *self,
-                                                       const gchar          *root_uri);
+void          ide_lsp_client_set_root_uri               (IdeLspClient         *self,
+                                                         const gchar          *root_uri);
 IDE_AVAILABLE_IN_3_32
-void          ide_lsp_client_start                    (IdeLspClient         *self);
+void          ide_lsp_client_start                      (IdeLspClient         *self);
 IDE_AVAILABLE_IN_3_32
-void          ide_lsp_client_stop                     (IdeLspClient         *self);
+void          ide_lsp_client_stop                       (IdeLspClient         *self);
 IDE_AVAILABLE_IN_3_32
-void          ide_lsp_client_call_async               (IdeLspClient         *self,
-                                                       const gchar          *method,
-                                                       GVariant             *params,
-                                                       GCancellable         *cancellable,
-                                                       GAsyncReadyCallback   callback,
-                                                       gpointer              user_data);
+void          ide_lsp_client_call_async                 (IdeLspClient         *self,
+                                                         const gchar          *method,
+                                                         GVariant             *params,
+                                                         GCancellable         *cancellable,
+                                                         GAsyncReadyCallback   callback,
+                                                         gpointer              user_data);
 IDE_AVAILABLE_IN_3_32
-gboolean      ide_lsp_client_call_finish              (IdeLspClient         *self,
-                                                       GAsyncResult         *result,
-                                                       GVariant            **return_value,
-                                                       GError              **error);
+gboolean      ide_lsp_client_call_finish                (IdeLspClient         *self,
+                                                         GAsyncResult         *result,
+                                                         GVariant            **return_value,
+                                                         GError              **error);
 IDE_AVAILABLE_IN_3_32
-void          ide_lsp_client_send_notification_async  (IdeLspClient         *self,
-                                                       const gchar          *method,
-                                                       GVariant             *params,
-                                                       GCancellable         *cancellable,
-                                                       GAsyncReadyCallback   notificationback,
-                                                       gpointer              user_data);
+void          ide_lsp_client_send_notification_async    (IdeLspClient         *self,
+                                                         const gchar          *method,
+                                                         GVariant             *params,
+                                                         GCancellable         *cancellable,
+                                                         GAsyncReadyCallback   notificationback,
+                                                         gpointer              user_data);
 IDE_AVAILABLE_IN_3_32
-gboolean      ide_lsp_client_send_notification_finish (IdeLspClient         *self,
-                                                       GAsyncResult         *result,
-                                                       GError              **error);
+gboolean      ide_lsp_client_send_notification_finish   (IdeLspClient         *self,
+                                                         GAsyncResult         *result,
+                                                         GError              **error);
 IDE_AVAILABLE_IN_3_32
-void          ide_lsp_client_get_diagnostics_async    (IdeLspClient         *self,
-                                                       GFile                *file,
-                                                       GBytes               *content,
-                                                       const gchar          *lang_id,
-                                                       GCancellable         *cancellable,
-                                                       GAsyncReadyCallback   callback,
-                                                       gpointer              user_data);
+void          ide_lsp_client_get_diagnostics_async      (IdeLspClient         *self,
+                                                         GFile                *file,
+                                                         GBytes               *content,
+                                                         const gchar          *lang_id,
+                                                         GCancellable         *cancellable,
+                                                         GAsyncReadyCallback   callback,
+                                                         gpointer              user_data);
 IDE_AVAILABLE_IN_3_32
-gboolean      ide_lsp_client_get_diagnostics_finish   (IdeLspClient         *self,
-                                                       GAsyncResult         *result,
-                                                       IdeDiagnostics      **diagnostics,
-                                                       GError              **error);
+gboolean      ide_lsp_client_get_diagnostics_finish     (IdeLspClient         *self,
+                                                         GAsyncResult         *result,
+                                                         IdeDiagnostics      **diagnostics,
+                                                         GError              **error);
+IDE_AVAILABLE_IN_42
+void          ide_lsp_client_set_initialization_options (IdeLspClient         *self,
+                                                         GVariant             *options);
+IDE_AVAILABLE_IN_42
+GVariant     *ide_lsp_client_get_initialization_options (IdeLspClient         *self);
 
 G_END_DECLS


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