[gnome-builder] lsp: allow clients to reply to workspace/configuration



commit 1e4b762ef3282f0a6c24113f42e8d8c7cb2bd212
Author: Christian Hergert <chergert redhat com>
Date:   Wed Dec 4 15:46:26 2019 -0800

    lsp: allow clients to reply to workspace/configuration
    
    If a workspace/configuration call is made by the language
    server to our IdeLspClient, we want to reply with something
    useful to the peer.
    
    Since this content can be different for every LSP, we'll defer
    to the plugin to provide the content. Some params we'll want to
    make easier for the plugin to determine, but this seems like the
    quickest first step to make that possible. We can add additional
    abstractions for the others later.
    
    Related #1074

 src/libide/lsp/ide-lsp-client.c | 60 ++++++++++++++++++++++++++++++++++++++++-
 src/libide/lsp/ide-lsp-client.h | 19 ++++++-------
 2 files changed, 69 insertions(+), 10 deletions(-)
---
diff --git a/src/libide/lsp/ide-lsp-client.c b/src/libide/lsp/ide-lsp-client.c
index e4b48075c..cca22c10e 100644
--- a/src/libide/lsp/ide-lsp-client.c
+++ b/src/libide/lsp/ide-lsp-client.c
@@ -71,8 +71,9 @@ enum {
 };
 
 enum {
-  PUBLISHED_DIAGNOSTICS,
+  LOAD_CONFIGURATION,
   NOTIFICATION,
+  PUBLISHED_DIAGNOSTICS,
   SUPPORTS_LANGUAGE,
   N_SIGNALS
 };
@@ -696,6 +697,36 @@ ide_lsp_client_send_notification (IdeLspClient  *self,
   IDE_EXIT;
 }
 
+static gboolean
+ide_lsp_client_handle_call (IdeLspClient  *self,
+                            const gchar   *method,
+                            GVariant      *id,
+                            GVariant      *params,
+                            JsonrpcClient *client)
+{
+  IDE_ENTRY;
+
+  g_assert (IDE_IS_LSP_CLIENT (self));
+  g_assert (method != NULL);
+  g_assert (id != NULL);
+  g_assert (JSONRPC_IS_CLIENT (client));
+
+  if (strcmp (method, "workspace/configuration") == 0)
+    {
+      g_autoptr(GVariant) config = NULL;
+
+      g_signal_emit (self, signals [LOAD_CONFIGURATION], 0, &config);
+
+      if (config != NULL)
+        {
+          jsonrpc_client_reply_async (client, id, config, NULL, NULL, NULL);
+          IDE_RETURN (TRUE);
+        }
+    }
+
+  IDE_RETURN (FALSE);
+}
+
 static void
 ide_lsp_client_finalize (GObject *object)
 {
@@ -824,6 +855,27 @@ ide_lsp_client_class_init (IdeLspClientClass *klass)
 
   g_object_class_install_properties (object_class, N_PROPS, properties);
 
+  /**
+   * IdeLspClient::load-configuration:
+   * @self: a #IdeLspClient
+   *
+   * Loads the configuration object to reply to a workspace/configuration
+   * request from the peer.
+   *
+   * Returns: (transfer full): a #GVariant containing the result or %NULL
+   *   to proceed to the next signal handler.
+   *
+   * Since: 3.36
+   */
+  signals [LOAD_CONFIGURATION] =
+    g_signal_new ("load-configuration",
+                  G_TYPE_FROM_CLASS (klass),
+                  G_SIGNAL_RUN_LAST,
+                  G_STRUCT_OFFSET (IdeLspClientClass, load_configuration),
+                  g_signal_accumulator_first_wins, NULL,
+                  NULL,
+                  G_TYPE_VARIANT, 0);
+
   signals [NOTIFICATION] =
     g_signal_new ("notification",
                   G_TYPE_FROM_CLASS (klass),
@@ -1078,6 +1130,12 @@ ide_lsp_client_start (IdeLspClient *self)
                            self,
                            G_CONNECT_SWAPPED);
 
+  g_signal_connect_object (priv->rpc_client,
+                           "handle-call",
+                           G_CALLBACK (ide_lsp_client_handle_call),
+                           self,
+                           G_CONNECT_SWAPPED);
+
   jsonrpc_client_call_async (priv->rpc_client,
                              "initialize",
                              params,
diff --git a/src/libide/lsp/ide-lsp-client.h b/src/libide/lsp/ide-lsp-client.h
index 626d6bca3..27e1c4515 100644
--- a/src/libide/lsp/ide-lsp-client.h
+++ b/src/libide/lsp/ide-lsp-client.h
@@ -44,17 +44,18 @@ struct _IdeLspClientClass
 {
   IdeObjectClass parent_class;
 
-  void     (*notification)          (IdeLspClient   *self,
-                                     const gchar    *method,
-                                     GVariant       *params);
-  gboolean (*supports_language)     (IdeLspClient   *self,
-                                     const gchar    *language_id);
-  void     (*published_diagnostics) (IdeLspClient   *self,
-                                     GFile           *file,
-                                     IdeDiagnostics  *diagnostics);
+  void      (*notification)          (IdeLspClient   *self,
+                                      const gchar    *method,
+                                      GVariant       *params);
+  gboolean  (*supports_language)     (IdeLspClient   *self,
+                                      const gchar    *language_id);
+  void      (*published_diagnostics) (IdeLspClient   *self,
+                                      GFile          *file,
+                                      IdeDiagnostics *diagnostics);
+  GVariant *(*load_configuration)    (IdeLspClient   *self);
 
   /*< private >*/
-  gpointer _reserved[16];
+  gpointer _reserved[15];
 };
 
 IDE_AVAILABLE_IN_3_32


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