[gnome-builder] plugins/rust-analyzer: plumb settings to rust-analyzer
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] plugins/rust-analyzer: plumb settings to rust-analyzer
- Date: Tue, 6 Sep 2022 01:53:05 +0000 (UTC)
commit 831ae20570cecfb28913649aad59bdf4fcbc3a04
Author: Christian Hergert <chergert redhat com>
Date: Mon Sep 5 18:42:57 2022 -0700
plugins/rust-analyzer: plumb settings to rust-analyzer
.../rust-analyzer/gbp-rust-analyzer-service.c | 126 ++++++++++++++++++++-
1 file changed, 125 insertions(+), 1 deletion(-)
---
diff --git a/src/plugins/rust-analyzer/gbp-rust-analyzer-service.c
b/src/plugins/rust-analyzer/gbp-rust-analyzer-service.c
index de3c477f3..3e8c5e805 100644
--- a/src/plugins/rust-analyzer/gbp-rust-analyzer-service.c
+++ b/src/plugins/rust-analyzer/gbp-rust-analyzer-service.c
@@ -31,21 +31,124 @@
struct _GbpRustAnalyzerService
{
IdeLspService parent_instance;
+ GSettings *settings;
+ IdeLspClient *client;
};
G_DEFINE_FINAL_TYPE (GbpRustAnalyzerService, gbp_rust_analyzer_service, IDE_TYPE_LSP_SERVICE)
+static void
+gbp_rust_analyzer_service_settings_changed_cb (GbpRustAnalyzerService *self,
+ const char *key,
+ GSettings *settings)
+{
+ IDE_ENTRY;
+
+ g_assert (GBP_RUST_ANALYZER_SERVICE (self));
+ g_assert (G_IS_SETTINGS (settings));
+
+ if (self->client != NULL)
+ {
+ g_autoptr(GVariant) params = JSONRPC_MESSAGE_NEW ("settings", "");
+ ide_lsp_client_send_notification_async (self->client,
+ "workspace/didChangeConfiguration",
+ params,
+ NULL, NULL, NULL);
+ }
+
+ IDE_EXIT;
+}
+
+static void
+gbp_rust_analyzer_service_initialized_cb (GbpRustAnalyzerService *self,
+ IdeLspClient *client)
+{
+ g_autoptr(GVariant) params = NULL;
+
+ IDE_ENTRY;
+
+ g_assert (GBP_RUST_ANALYZER_SERVICE (self));
+ g_assert (IDE_IS_LSP_CLIENT (client));
+
+ params = JSONRPC_MESSAGE_NEW ("settings", "");
+
+ ide_lsp_client_send_notification_async (client,
+ "workspace/didChangeConfiguration",
+ params,
+ NULL, NULL, NULL);
+
+ IDE_EXIT;
+}
+
+static GVariant *
+gbp_rust_analyzer_service_load_configuration_cb (GbpRustAnalyzerService *self,
+ IdeLspClient *client)
+{
+ g_autoptr(GVariant) ret = NULL;
+ g_autofree char *command = NULL;
+
+ IDE_ENTRY;
+
+ g_assert (IDE_IS_LSP_CLIENT (client));
+ g_assert (GBP_RUST_ANALYZER_SERVICE (self));
+
+ command = g_settings_get_string (self->settings, "cargo-command");
+
+ ret = JSONRPC_MESSAGE_NEW_ARRAY ("{",
+ "checkOnSave", "{",
+ "enable", JSONRPC_MESSAGE_PUT_BOOLEAN (command[0] != 0),
+ "command", JSONRPC_MESSAGE_PUT_STRING (command),
+ "}",
+ "}");
+
+ IDE_RETURN (g_steal_pointer (&ret));
+}
+
static void
gbp_rust_analyzer_service_configure_client (IdeLspService *service,
IdeLspClient *client)
{
+ GbpRustAnalyzerService *self = (GbpRustAnalyzerService *)service;
+ g_autoptr(GVariant) params = NULL;
+
IDE_ENTRY;
- g_assert (GBP_IS_RUST_ANALYZER_SERVICE (service));
+ g_assert (GBP_IS_RUST_ANALYZER_SERVICE (self));
g_assert (IDE_IS_LSP_CLIENT (client));
+ g_set_object (&self->client, client);
+
ide_lsp_client_add_language (client, "rust");
+ /* Opt-in for experimental proc-macro feature to make gtk-rs more
+ * useful for GNOME developers.
+ *
+ * See: https://rust-analyzer.github.io/manual.html#configuration
+ */
+ params = JSONRPC_MESSAGE_NEW (
+ "procMacro", "{",
+ "enable", JSONRPC_MESSAGE_PUT_BOOLEAN (TRUE),
+ "}"
+ );
+
+ ide_lsp_client_set_initialization_options (client, params);
+
+ g_object_set (client,
+ "use-markdown-in-diagnostics", TRUE,
+ NULL);
+
+ g_signal_connect_object (client,
+ "load-configuration",
+ G_CALLBACK (gbp_rust_analyzer_service_load_configuration_cb),
+ self,
+ G_CONNECT_SWAPPED);
+
+ g_signal_connect_object (client,
+ "initialized",
+ G_CALLBACK (gbp_rust_analyzer_service_initialized_cb),
+ self,
+ G_CONNECT_SWAPPED);
+
IDE_EXIT;
}
@@ -63,11 +166,25 @@ gbp_rust_analyzer_service_configure_launcher (IdeLspService *service,
IDE_EXIT;
}
+static void
+gbp_rust_analyzer_service_dispose (GObject *object)
+{
+ GbpRustAnalyzerService *self = (GbpRustAnalyzerService *)object;
+
+ g_clear_object (&self->settings);
+ g_clear_object (&self->client);
+
+ G_OBJECT_CLASS (gbp_rust_analyzer_service_parent_class)->dispose (object);
+}
+
static void
gbp_rust_analyzer_service_class_init (GbpRustAnalyzerServiceClass *klass)
{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
IdeLspServiceClass *lsp_service_class = IDE_LSP_SERVICE_CLASS (klass);
+ object_class->dispose = gbp_rust_analyzer_service_dispose;
+
lsp_service_class->configure_client = gbp_rust_analyzer_service_configure_client;
lsp_service_class->configure_launcher = gbp_rust_analyzer_service_configure_launcher;
}
@@ -76,4 +193,11 @@ static void
gbp_rust_analyzer_service_init (GbpRustAnalyzerService *self)
{
ide_lsp_service_set_program (IDE_LSP_SERVICE (self), "rust-analyzer");
+
+ self->settings = g_settings_new ("org.gnome.builder.rust-analyzer");
+ g_signal_connect_object (self->settings,
+ "changed",
+ G_CALLBACK (gbp_rust_analyzer_service_settings_changed_cb),
+ self,
+ G_CONNECT_SWAPPED);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]