[gnome-builder] plugins/rust-analyzer: make procMacro feature optional



commit 21416b8d726487a9dcaa6adbab9be79d888acdf0
Author: Christian Hergert <chergert redhat com>
Date:   Mon Sep 5 21:50:12 2022 -0700

    plugins/rust-analyzer: make procMacro feature optional
    
    This allows disabling the feature in preferences.

 src/plugins/rust-analyzer/gbp-rust-analyzer-service.c  |  9 ++++++++-
 .../org.gnome.builder.rust-analyzer.gschema.xml        |  3 +++
 src/plugins/rust-analyzer/tweaks.ui                    | 18 ++++++++++++++++++
 3 files changed, 29 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 3e8c5e805..7fe0374ed 100644
--- a/src/plugins/rust-analyzer/gbp-rust-analyzer-service.c
+++ b/src/plugins/rust-analyzer/gbp-rust-analyzer-service.c
@@ -110,6 +110,10 @@ gbp_rust_analyzer_service_configure_client (IdeLspService *service,
 {
   GbpRustAnalyzerService *self = (GbpRustAnalyzerService *)service;
   g_autoptr(GVariant) params = NULL;
+  g_auto(GStrv) features = NULL;
+  struct {
+    guint proc_macro : 1;
+  } feat;
 
   IDE_ENTRY;
 
@@ -120,6 +124,9 @@ gbp_rust_analyzer_service_configure_client (IdeLspService *service,
 
   ide_lsp_client_add_language (client, "rust");
 
+  features = g_settings_get_strv (self->settings, "features");
+  feat.proc_macro = g_strv_contains ((const char * const *)features, "procMacro");
+
   /* Opt-in for experimental proc-macro feature to make gtk-rs more
    * useful for GNOME developers.
    *
@@ -127,7 +134,7 @@ gbp_rust_analyzer_service_configure_client (IdeLspService *service,
    */
   params = JSONRPC_MESSAGE_NEW (
     "procMacro", "{",
-      "enable", JSONRPC_MESSAGE_PUT_BOOLEAN (TRUE),
+      "enable", JSONRPC_MESSAGE_PUT_BOOLEAN (feat.proc_macro),
     "}"
   );
 
diff --git a/src/plugins/rust-analyzer/org.gnome.builder.rust-analyzer.gschema.xml 
b/src/plugins/rust-analyzer/org.gnome.builder.rust-analyzer.gschema.xml
index f9c6549a5..1066c0d5e 100644
--- a/src/plugins/rust-analyzer/org.gnome.builder.rust-analyzer.gschema.xml
+++ b/src/plugins/rust-analyzer/org.gnome.builder.rust-analyzer.gschema.xml
@@ -8,5 +8,8 @@
       </choices>
       <default>'check'</default>
     </key>
+    <key name="features" type="as">
+      <default>['procMacro']</default>
+    </key>
   </schema>
 </schemalist>
diff --git a/src/plugins/rust-analyzer/tweaks.ui b/src/plugins/rust-analyzer/tweaks.ui
index 2bf53fd14..272fe7f25 100644
--- a/src/plugins/rust-analyzer/tweaks.ui
+++ b/src/plugins/rust-analyzer/tweaks.ui
@@ -40,6 +40,24 @@
                         </child>
                       </object>
                     </child>
+                    <child>
+                      <object class="IdeTweaksGroup" id="rust_analyzer_features_group">
+                        <property name="title" translatable="yes">Features</property>
+                        <child>
+                          <object class="IdeTweaksRadio">
+                            <property name="title" translatable="yes">Proc Macros</property>
+                            <property name="subtitle" translatable="yes">Enables the expirimental Proc 
Macros feature of rust-analyzer</property>
+                            <property name="value">'procMacro'</property>
+                            <property name="binding">
+                              <object class="IdeTweaksSetting">
+                                <property name="schema-id">org.gnome.builder.rust-analyzer</property>
+                                <property name="schema-key">features</property>
+                              </object>
+                            </property>
+                          </object>
+                        </child>
+                      </object>
+                    </child>
                   </object>
                 </child>
               </object>


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