Skip to content
Merged
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
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,28 @@

A [PureScript](https://www.purescript.org/) extension for [Zed](https://zed.dev).

## Configuration

### Environment Variables

You can specify arguments as well as environment variables to pass to the language server by configuring the `lsp` settings in your Zed settings. This can be helpful for Nix setups or other environments where you need to customize the `PATH` or other variables so that the language server can find the purescript binary to invoke for the LSP support.

Example configuration in your `settings.json`:

```json
{
"lsp": {
"purescript-language-server": {
"binary": {
"env": {
"PATH": "/nix/store/gw58kr741a9ddmv3xn47llc7i07jbbvr-purescript-0.15.15/bin"
}
}
}
}
}
```

## Development

To develop this extension, see the [Developing Extensions](https://zed.dev/docs/extensions/developing-extensions) section of the Zed docs.
11 changes: 7 additions & 4 deletions src/purescript.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::{env, fs};
use zed_extension_api::{self as zed, serde_json, Result};
use zed_extension_api::{self as zed, serde_json, settings::LspSettings, Result};

const SERVER_PATH: &str = "node_modules/.bin/purescript-language-server";
const PACKAGE_NAME: &str = "purescript-language-server";
Expand All @@ -10,7 +10,7 @@ struct PurescriptExtension {

impl PurescriptExtension {
fn server_exists(&self) -> bool {
fs::metadata(SERVER_PATH).map_or(false, |stat| stat.is_file())
fs::metadata(SERVER_PATH).is_ok_and(|stat| stat.is_file())
}

fn server_script_path(&mut self, language_server_id: &zed::LanguageServerId) -> Result<String> {
Expand Down Expand Up @@ -64,7 +64,7 @@ impl zed::Extension for PurescriptExtension {
fn language_server_command(
&mut self,
language_server_id: &zed::LanguageServerId,
_worktree: &zed::Worktree,
worktree: &zed::Worktree,
) -> Result<zed::Command> {
let server_path = self.server_script_path(language_server_id)?;
Ok(zed::Command {
Expand All @@ -77,7 +77,10 @@ impl zed::Extension for PurescriptExtension {
.to_string(),
"--stdio".to_string(),
],
env: Default::default(),
env: LspSettings::for_worktree(language_server_id.as_ref(), worktree)
.ok()
.and_then(|settings| settings.binary.and_then(|settings| settings.env))
.map_or_else(Default::default, |binary| binary.into_iter().collect()),
})
}

Expand Down