Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
ruby: Pass initialization options to LSPs (#12012)
Vitaly Slobodin2f4890ae395f
diff --git a/docs/src/languages/ruby.md b/docs/src/languages/ruby.mdindex 6bd8b1ac444..4bb88b96b70 100644--- a/docs/src/languages/ruby.md+++ b/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### ConfigurationSolargraph 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+ }+ }+ }+ }+}+```diff --git a/extensions/ruby/src/ruby.rs b/extensions/ruby/src/ruby.rsindex 6956230455d..b42ea0450b0 100644--- a/extensions/ruby/src/ruby.rs+++ b/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)))}}