diff --git a/README.md b/README.md index 4c499ef..aeac283 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/src/purescript.rs b/src/purescript.rs index be12592..bc3e4a9 100644 --- a/src/purescript.rs +++ b/src/purescript.rs @@ -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"; @@ -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 { @@ -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 { let server_path = self.server_script_path(language_server_id)?; Ok(zed::Command { @@ -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()), }) }