Commit 6a0dd40e authored by Günther Wagner's avatar Günther Wagner

make lsp notification generic

parent 2ff8efd0
...@@ -745,6 +745,49 @@ ide_lsp_client_real_notification (IdeLspClient *self, ...@@ -745,6 +745,49 @@ ide_lsp_client_real_notification (IdeLspClient *self,
{ {
if (g_str_equal (method, "textDocument/publishDiagnostics")) if (g_str_equal (method, "textDocument/publishDiagnostics"))
ide_lsp_client_text_document_publish_diagnostics (self, params); 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; IDE_EXIT;
...@@ -958,6 +1001,10 @@ ide_lsp_client_handle_call (IdeLspClient *self, ...@@ -958,6 +1001,10 @@ ide_lsp_client_handle_call (IdeLspClient *self,
IDE_RETURN (ret); IDE_RETURN (ret);
} }
else if (strcmp (method, "window/workDoneProgress/create") == 0)
{
IDE_RETURN (TRUE);
}
IDE_RETURN (FALSE); IDE_RETURN (FALSE);
} }
...@@ -1429,6 +1476,9 @@ ide_lsp_client_start (IdeLspClient *self) ...@@ -1429,6 +1476,9 @@ ide_lsp_client_start (IdeLspClient *self)
"}", "}",
"}", "}",
"}", "}",
"window", "{",
"workDoneProgress", JSONRPC_MESSAGE_PUT_BOOLEAN (TRUE),
"}",
"}" "}"
); );
......
...@@ -224,56 +224,6 @@ rust_analyzer_service_set_client (RustAnalyzerService *self, ...@@ -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 void
rust_analyzer_service_lsp_started (IdeSubprocessSupervisor *supervisor, rust_analyzer_service_lsp_started (IdeSubprocessSupervisor *supervisor,
IdeSubprocess *subprocess, IdeSubprocess *subprocess,
...@@ -300,7 +250,6 @@ rust_analyzer_service_lsp_started (IdeSubprocessSupervisor *supervisor, ...@@ -300,7 +250,6 @@ rust_analyzer_service_lsp_started (IdeSubprocessSupervisor *supervisor,
} }
client = ide_lsp_client_new (io_stream); client = ide_lsp_client_new (io_stream);
g_signal_connect (client, "notification", G_CALLBACK (_handle_notification), NULL);
rust_analyzer_service_set_client (self, client); rust_analyzer_service_set_client (self, client);
ide_object_append (IDE_OBJECT (self), IDE_OBJECT (client)); ide_object_append (IDE_OBJECT (self), IDE_OBJECT (client));
ide_lsp_client_add_language (client, "rust"); ide_lsp_client_add_language (client, "rust");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment