Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 52 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
15 changes: 13 additions & 2 deletions src/rescript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ impl zed::Extension for ReScriptExtension {
) -> Result<zed::Command> {
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()?,
Expand Down Expand Up @@ -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<Option<zed::serde_json::Value>> {
match zed::settings::LspSettings::for_worktree(language_server_id.as_ref(), worktree) {
Ok(LspSettings { settings, .. }) => Ok(settings),
Err(_) => Ok(None),
}
}
}

zed::register_extension!(ReScriptExtension);
Loading