[gnome-builder/gnome-builder-43] plugins/rust-analyzer: add a couple rust-analyzer options



commit 599e88932fca8447e4fdfb3f590a0c6f892a1503
Author: Christian Hergert <chergert redhat com>
Date:   Tue Sep 20 14:47:34 2022 -0700

    plugins/rust-analyzer: add a couple rust-analyzer options
    
    Adds some radio rows to preferences to toggle on/off rust-analyzer
    features. In the long run, we'll likely need something significantly more
    tweakable for this stuff, since there isn't really a way to pass these
    objects along to the user to tweak advanced LSP features.
    
    Fixes #1795 by way of enabling the nightly option.

 .../rust-analyzer/gbp-rust-analyzer-service.c      | 16 ++++++++++++-
 .../org.gnome.builder.rust-analyzer.gschema.xml    |  2 +-
 src/plugins/rust-analyzer/tweaks.ui                | 28 +++++++++++++++++++++-
 3 files changed, 43 insertions(+), 3 deletions(-)
---
diff --git a/src/plugins/rust-analyzer/gbp-rust-analyzer-service.c 
b/src/plugins/rust-analyzer/gbp-rust-analyzer-service.c
index 7fe0374ed..3b60aed1d 100644
--- a/src/plugins/rust-analyzer/gbp-rust-analyzer-service.c
+++ b/src/plugins/rust-analyzer/gbp-rust-analyzer-service.c
@@ -112,7 +112,9 @@ gbp_rust_analyzer_service_configure_client (IdeLspService *service,
   g_autoptr(GVariant) params = NULL;
   g_auto(GStrv) features = NULL;
   struct {
+    guint build_scripts : 1;
     guint proc_macro : 1;
+    guint range_formatting : 1;
   } feat;
 
   IDE_ENTRY;
@@ -125,7 +127,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");
+  feat.build_scripts = g_strv_contains ((const char * const *)features, "cargo.buildScripts.enable");
+  feat.proc_macro = g_strv_contains ((const char * const *)features, "procMacro.enable");
+  feat.range_formatting = g_strv_contains ((const char * const *)features, "rustfmt.rangeFormatting.enable");
 
   /* Opt-in for experimental proc-macro feature to make gtk-rs more
    * useful for GNOME developers.
@@ -133,8 +137,18 @@ gbp_rust_analyzer_service_configure_client (IdeLspService *service,
    * See: https://rust-analyzer.github.io/manual.html#configuration
    */
   params = JSONRPC_MESSAGE_NEW (
+    "cargo", "{",
+      "buildScripts", "{",
+        "enable", JSONRPC_MESSAGE_PUT_BOOLEAN (feat.build_scripts),
+      "}",
+    "}",
     "procMacro", "{",
       "enable", JSONRPC_MESSAGE_PUT_BOOLEAN (feat.proc_macro),
+    "}",
+    "rustfmt", "{",
+      "rangeFormatting", "{",
+        "enable", JSONRPC_MESSAGE_PUT_BOOLEAN (feat.range_formatting),
+      "}",
     "}"
   );
 
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 1066c0d5e..0ad81a20c 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
@@ -9,7 +9,7 @@
       <default>'check'</default>
     </key>
     <key name="features" type="as">
-      <default>['procMacro']</default>
+      <default>['procMacro.enable', 'cargo.buildScripts.enable']</default>
     </key>
   </schema>
 </schemalist>
diff --git a/src/plugins/rust-analyzer/tweaks.ui b/src/plugins/rust-analyzer/tweaks.ui
index 4a52e2f04..4781a5588 100644
--- a/src/plugins/rust-analyzer/tweaks.ui
+++ b/src/plugins/rust-analyzer/tweaks.ui
@@ -47,7 +47,33 @@
                           <object class="IdeTweaksRadio">
                             <property name="title" translatable="yes">Proc Macros</property>
                             <property name="subtitle" translatable="yes">Enables the experimental Proc 
Macros feature of rust-analyzer</property>
-                            <property name="value">'procMacro'</property>
+                            <property name="value">'procMacro.enable'</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>
+                        <child>
+                          <object class="IdeTweaksRadio">
+                            <property name="title" translatable="yes">Cargo Build Scripts</property>
+                            <property name="subtitle" translatable="yes">Run build scripts (build.rs) for 
more precise code analysis</property>
+                            <property name="value">'cargo.buildScripts.enable'</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>
+                        <child>
+                          <object class="IdeTweaksRadio">
+                            <property name="title" translatable="yes">Rustfmt Range Formatting</property>
+                            <property name="subtitle" translatable="yes">Enables the use of rustfmt’s 
unstable range formatting command. The rustfmt option is unstable and only available on nightly builds of the 
Rust SDK.</property>
+                            <property name="value">'rustfmt.rangeFormatting.enable'</property>
                             <property name="binding">
                               <object class="IdeTweaksSetting">
                                 <property name="schema-id">org.gnome.builder.rust-analyzer</property>


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