ruby: Pass initialization options to LSPs (#12012)

Vitaly Slobodin created

This pull request adds ability to pass `initialization_options` to both
`solargraph` and `ruby-lsp` language servers. Additionally it updates
the documentation to reflect that and the recently added `ruby-lsp`
server.

Release Notes:

- Pass `initialization_options` to Ruby LSP servers.

Change summary

docs/src/languages/ruby.md  | 30 ++++++++++++++++++++++++++++--
extensions/ruby/src/ruby.rs | 21 ++++++++-------------
2 files changed, 36 insertions(+), 15 deletions(-)

Detailed changes

docs/src/languages/ruby.md 🔗

@@ -1,9 +1,9 @@
 # Ruby
 
 - Tree Sitter: [tree-sitter-ruby](https://github.com/tree-sitter/tree-sitter-ruby)
-- Language Server: [solargraph](https://github.com/castwide/solargraph)
+- Language Servers: [solargraph](https://github.com/castwide/solargraph), [ruby-lsp](https://github.com/Shopify/ruby-lsp)
 
-### Setup
+### Setting up `solargraph`
 
 Zed currently doesn't install Solargraph automatically. To use Solargraph, you need to install the gem. Zed just looks for an executable called `solargraph` on your `PATH`.
 
@@ -37,3 +37,29 @@ Solargraph has formatting and diagnostics disabled by default. We can tell Zed t
 ### Configuration
 
 Solargraph reads its configuration from a file called `.solargraph.yml` in the root of your project. For more information about this file, see the [Solargraph configuration documentation](https://solargraph.org/guides/configuration).
+
+### Setting up `ruby-lsp`
+
+Zed currently doesn't install Ruby LSP automatically. To use Ruby LSP, you need to install the gem. Zed just looks for an executable called `ruby-lsp` on your `PATH`.
+
+You can install the gem manually with the following command:
+
+```shell
+gem install ruby-lsp
+```
+
+Ruby LSP uses pull-based diagnostics which Zed doesn't support yet. We can tell Zed to disable it by adding the following to your `settings.json`:
+
+```json
+{
+  "lsp": {
+    "ruby-lsp": {
+      "initialization_options": {
+        "enabledFeatures": {
+          "diagnostics": false
+        }
+      }
+    }
+  }
+}
+```

extensions/ruby/src/ruby.rs 🔗

@@ -1,7 +1,7 @@
 mod language_servers;
 
 use zed::lsp::{Completion, Symbol};
-use zed::serde_json::json;
+use zed::settings::LspSettings;
 use zed::{serde_json, CodeLabel, LanguageServerId};
 use zed_extension_api::{self as zed, Result};
 
@@ -77,20 +77,15 @@ impl zed::Extension for RubyExtension {
     fn language_server_initialization_options(
         &mut self,
         language_server_id: &LanguageServerId,
-        _worktree: &zed::Worktree,
+        worktree: &zed::Worktree,
     ) -> Result<Option<serde_json::Value>> {
-        match language_server_id.as_ref() {
-            // We disable diagnostics because ruby-lsp uses pull-based diagnostics,
-            // which Zed doesn't support yet.
-            RubyLsp::LANGUAGE_SERVER_ID => Ok(Some(json!({
-                "enabledFeatures": {
-                  "diagnostics": false
-                },
-                "experimentalFeaturesEnabled": true
-            }))),
+        let initialization_options =
+            LspSettings::for_worktree(language_server_id.as_ref(), worktree)
+                .ok()
+                .and_then(|lsp_settings| lsp_settings.initialization_options.clone())
+                .unwrap_or_default();
 
-            _ => Ok(None),
-        }
+        Ok(Some(serde_json::json!(initialization_options)))
     }
 }