[gnome-builder: 5/17] make lsp notification generic



commit 6a0dd40e2acbb6a330eb9399edbf2966b17c2ca6
Author: Günther Wagner <info gunibert de>
Date:   Mon May 18 20:03:05 2020 +0200

    make lsp notification generic

 src/libide/lsp/ide-lsp-client.c                   | 50 ++++++++++++++++++++++
 src/plugins/rust-analyzer/rust-analyzer-service.c | 51 -----------------------
 2 files changed, 50 insertions(+), 51 deletions(-)
---
diff --git a/src/libide/lsp/ide-lsp-client.c b/src/libide/lsp/ide-lsp-client.c
index fb4e85605..28385d92f 100644
--- a/src/libide/lsp/ide-lsp-client.c
+++ b/src/libide/lsp/ide-lsp-client.c
@@ -745,6 +745,49 @@ ide_lsp_client_real_notification (IdeLspClient *self,
     {
       if (g_str_equal (method, "textDocument/publishDiagnostics"))
         ide_lsp_client_text_document_publish_diagnostics (self, params);
+      else if (g_str_equal (method, "$/progress"))
+        {
+          const gchar *token = NULL;
+          const gchar *message = NULL;
+          const gchar *title = NULL;
+          const gchar *kind = NULL;
+          IdeContext *context;
+          IdeNotifications *notifications;
+          IdeNotification *notification;
+
+          JSONRPC_MESSAGE_PARSE (params, "token", JSONRPC_MESSAGE_GET_STRING (&token),
+                                         "value", "{",
+                                           "kind", JSONRPC_MESSAGE_GET_STRING (&kind),
+                                         "}");
+          JSONRPC_MESSAGE_PARSE (params, "value", "{",
+                                           "title", JSONRPC_MESSAGE_GET_STRING (&title),
+                                         "}");
+          JSONRPC_MESSAGE_PARSE (params, "value", "{",
+                                           "message", JSONRPC_MESSAGE_GET_STRING (&message),
+                                         "}");
+          context = ide_object_get_context (IDE_OBJECT (self));
+          notifications = ide_object_get_child_typed (IDE_OBJECT (context), IDE_TYPE_NOTIFICATIONS);
+
+          if (g_str_equal (kind, "begin"))
+            {
+              notification = ide_notification_new ();
+              ide_notification_set_id (notification, token);
+              ide_notification_set_has_progress (notification, TRUE);
+              ide_notification_set_progress_is_imprecise (notification, TRUE);
+              ide_notification_set_title (notification, title);
+              ide_notification_set_urgent (notification, TRUE);
+              ide_notification_attach (notification, IDE_OBJECT (context));
+            }
+          else
+            {
+              notification = ide_notifications_find_by_id (notifications, token);
+              if (message != NULL && notification != NULL)
+                ide_notification_set_title (notification, message);
+            }
+
+          if (g_str_equal (kind, "end") && notification != NULL)
+            ide_notification_withdraw_in_seconds (notification, 3);
+        }
     }
 
   IDE_EXIT;
@@ -958,6 +1001,10 @@ ide_lsp_client_handle_call (IdeLspClient  *self,
 
       IDE_RETURN (ret);
     }
+  else if (strcmp (method, "window/workDoneProgress/create") == 0)
+    {
+      IDE_RETURN (TRUE);
+    }
 
   IDE_RETURN (FALSE);
 }
@@ -1429,6 +1476,9 @@ ide_lsp_client_start (IdeLspClient *self)
           "}",
         "}",
       "}",
+      "window", "{",
+        "workDoneProgress", JSONRPC_MESSAGE_PUT_BOOLEAN (TRUE),
+      "}",
     "}"
   );
 
diff --git a/src/plugins/rust-analyzer/rust-analyzer-service.c 
b/src/plugins/rust-analyzer/rust-analyzer-service.c
index 541b091c3..08e5340fa 100644
--- a/src/plugins/rust-analyzer/rust-analyzer-service.c
+++ b/src/plugins/rust-analyzer/rust-analyzer-service.c
@@ -224,56 +224,6 @@ rust_analyzer_service_set_client (RustAnalyzerService *self,
     }
 }
 
-static void
-_handle_notification (IdeLspClient *client,
-                      gchar        *method,
-                      GVariant     *params)
-{
-  g_autoptr(IdeNotification) notification = NULL;
-  IdeNotifications *notifications = NULL;
-  IdeContext *context = NULL;
-  const gchar *message = NULL;
-  const gchar *token = NULL;
-  const gchar *kind = NULL;
-
-  g_return_if_fail (IDE_IS_LSP_CLIENT (client));
-
-  if (!ide_str_equal0 (method, "$/progress"))
-    return;
-
-  JSONRPC_MESSAGE_PARSE (params, "token", JSONRPC_MESSAGE_GET_STRING (&token));
-
-  if (!ide_str_equal0 (token, "rustAnalyzer/startup"))
-    return;
-
-  JSONRPC_MESSAGE_PARSE (params, "value", "{", "kind", JSONRPC_MESSAGE_GET_STRING (&kind), "message", 
JSONRPC_MESSAGE_GET_STRING (&message), "}");
-
-  context = ide_object_get_context (IDE_OBJECT (client));
-  notifications = ide_object_get_child_typed (IDE_OBJECT (context), IDE_TYPE_NOTIFICATIONS);
-  notification = ide_notifications_find_by_id (notifications, "org.gnome-builder.rust-analyzer.startup");
-
-  if (notification == NULL)
-    {
-      notification = ide_notification_new ();
-      ide_notification_set_id (notification, "org.gnome-builder.rust-analyzer.startup");
-      ide_notification_set_title (notification, message);
-      ide_notification_set_has_progress (notification, TRUE);
-      ide_notification_set_progress_is_imprecise (notification, TRUE);
-      ide_notification_set_icon_name (notification, "system-run-symbolic");
-      ide_notification_attach (notification, IDE_OBJECT (context));
-    }
-  else
-    {
-      ide_notification_set_title (notification, message);
-      if (ide_str_equal0 (kind, "end"))
-        {
-          ide_notification_set_has_progress (notification, FALSE);
-          ide_notification_set_icon_name (notification, NULL);
-          ide_notification_withdraw_in_seconds (notification, 3);
-        }
-    }
-}
-
 void
 rust_analyzer_service_lsp_started (IdeSubprocessSupervisor *supervisor,
                                    IdeSubprocess           *subprocess,
@@ -300,7 +250,6 @@ rust_analyzer_service_lsp_started (IdeSubprocessSupervisor *supervisor,
     }
 
   client = ide_lsp_client_new (io_stream);
-  g_signal_connect (client, "notification", G_CALLBACK (_handle_notification), NULL);
   rust_analyzer_service_set_client (self, client);
   ide_object_append (IDE_OBJECT (self), IDE_OBJECT (client));
   ide_lsp_client_add_language (client, "rust");


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