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
75 changes: 59 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
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