diff --git a/README.md b/README.md index 79d55b2..e2f2942 100644 --- a/README.md +++ b/README.md @@ -1,38 +1,81 @@ # rescript-zed -ReScript support for [Zed](https://zed.dev) editor. +ReScript support for the [Zed](https://zed.dev) editor. This extension plugs in the following projects: -- [tree-sitter-rescript](https://github.com/rescript-lang/tree-sitter-rescript) parser -- [@rescript/language-server](https://github.com/rescript-lang/rescript-vscode) LSP +- [tree-sitter-rescript](https://github.com/rescript-lang/tree-sitter-rescript) + parser +- [@rescript/language-server](https://www.npmjs.com/package/@rescript/language-server) + LSP -## Settings +## Installing the language server -```json +The stable server is the default language server used by this extension. It uses +the pre-v2 versions of `@rescript/language-server`, and the extension installs +and updates that package automatically. + +Use `settings.version` when you need to pin a specific npm version. If it is +omitted, Zed installs the latest published stable version. + +> [!NOTE] +> The experimental server is the v2 language server published to npm under the +> `dev` tag. Pin the package to the current `dev` version. See the version +> history on +> [npm](https://www.npmjs.com/package/@rescript/language-server?activeTab=versions). + +> [!TIP] +> You can install the language server globally with +> `npm i -g @rescript/language-server@dev` and set the binary path. +> +> ```json +> { +> "lsp": { +> "rescript-language-server": { +> "binary": { +> "path": "rescript-language-server" +> } +> } +> } +> } +> ``` + +### Settings + +```jsonc +{ "lsp": { "rescript-language-server": { + // Server configuration for pre-v2 should be passed through initialization_options "initialization_options": { "extensionConfiguration": { - "askToStartBuild": false - } + "askToStartBuild": false, + }, }, "settings": { - "version": "1.71.0-next-441959d.0" - } - } + "version": "1.71.0-next-441959d.0", + // Server configuration for v2 should be passed through settings.rescript + "rescript": { + "hover": { + "supportMarkdownLinks": true, + }, + }, + }, + }, }, +} ``` -`initialization_options` are passed to the language server when it is started. They can be used to configure the language server. See [extensionConfiguration](https://github.com/rescript-lang/rescript-vscode/blob/441959d1feeaaffc1a589687758b1fbe1f649e72/server/src/config.ts#L5-L29) - -`settings` are specific to the Zed extension. -With `version` you can point to a specific npm version of the [@rescript/language-server](https://www.npmjs.com/package/@rescript/language-server?activeTab=versions). +`initialization_options` are passed to the language server (pre-v2) when it is started. +They can be used to configure the language server. See +[extensionConfiguration](https://github.com/rescript-lang/rescript-vscode/blob/441959d1feeaaffc1a589687758b1fbe1f649e72/server/src/config.ts#L5-L29) ## Developing -See [CONTRIBUTING.md](CONTRIBUTING.md) for instructions on how to develop this extension locally. +See [CONTRIBUTING.md](CONTRIBUTING.md) for instructions on how to develop this +extension locally. ## Acknowledgements -This project was originally created by [humaans](https://github.com/humaans/). We're grateful for their initial work in bringing ReScript support to Zed. +This project was originally created by [humaans](https://github.com/humaans/). +We're grateful for their initial work in bringing ReScript support to Zed. diff --git a/src/rescript.rs b/src/rescript.rs index 9234f4e..3724675 100644 --- a/src/rescript.rs +++ b/src/rescript.rs @@ -118,8 +118,8 @@ impl zed::Extension for ReScriptExtension { ) -> Result { let server_path = self.server_script_path(server_id, worktree)?; - let current_dir = env::current_dir() - .map_err(|e| format!("failed to get current directory: {e}"))?; + let current_dir = + env::current_dir().map_err(|e| format!("failed to get current directory: {e}"))?; Ok(zed::Command { command: zed::node_binary_path()?, @@ -151,6 +151,17 @@ impl zed::Extension for ReScriptExtension { } }))) } + + fn language_server_workspace_configuration( + &mut self, + language_server_id: &zed::LanguageServerId, + worktree: &zed::Worktree, + ) -> Result> { + match zed::settings::LspSettings::for_worktree(language_server_id.as_ref(), worktree) { + Ok(LspSettings { settings, .. }) => Ok(settings), + Err(_) => Ok(None), + } + } } zed::register_extension!(ReScriptExtension);