diff --git a/README.md b/README.md index 79d55b2..38f2dc1 100644 --- a/README.md +++ b/README.md @@ -1,38 +1,73 @@ # 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 +## Language Server -```json +The stable server is used by default. It is provided by the +`@rescript/language-server` package, which the extension installs and updates +automatically. + +Use `settings.version` to pin a specific npm version. If it is omitted, Zed +installs the latest published stable version. + +> [!TIP] To test the experimental language server (ReScript v13), use the +> `rescript lsp` subcommand included with the compiler. Set the binary path and +> arguments as follows: +> +> ```json +> { +> "lsp": { +> "rescript-language-server": { +> "binary": { +> "path": "node_modules/.bin/rescript", +> "arguments": ["lsp", "--stdio"] +> } +> } +> } +> } +> ``` + +### Settings + +```jsonc +{ "lsp": { "rescript-language-server": { + // Pass stable language server configuration through initialization_options + // See https://github.com/rescript-lang/rescript-vscode/blob/441959d1feeaaffc1a589687758b1fbe1f649e72/server/src/config.ts#L5-L29 "initialization_options": { "extensionConfiguration": { - "askToStartBuild": false - } + "askToStartBuild": false, + }, }, "settings": { - "version": "1.71.0-next-441959d.0" - } - } + "version": "1.71.0-next-441959d.0", + // Pass experimental language server configuration 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). - ## 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);