diff --git a/docs/src/languages/ruby.md b/docs/src/languages/ruby.md index 6bd8b1ac444085f470d544cc9ead76963f44c9aa..4bb88b96b7020526d21dc7ff66af1297556c3c03 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 ### 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 + } + } + } + } +} +``` diff --git a/extensions/ruby/src/ruby.rs b/extensions/ruby/src/ruby.rs index 6956230455d0bcb418cca0c1a4e02541db245728..b42ea0450b022d2ee7e57dae6fb172d7a55d9920 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> { - 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))) } }