Skip to content

Commit

Permalink
feat: use lsp settings to configure custom biome binary (#19)
Browse files Browse the repository at this point in the history
* feat: use lsp settings to configure custom biome binary

* Add custom binary guide to contributing.md
  • Loading branch information
luckydye authored Jun 6, 2024
1 parent 3fe28d4 commit b28e3c6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
18 changes: 18 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,24 @@ just install-tools

If you make changes to the Rust code and you require to reload the extension, you can open the "Extensions" tab by running the command `zed: extensions`, choose the `"Installed"`, seek the current extension and click the `"Rebuild"` label.

### Custom biome binary

The binary used by the extension can be overriden in Zed settings.json using the `lsp` key:

```jsonc
// settings.json
{
"lsp": {
"biome": {
"binary": {
"path": "<path_to_biome_binary>",
"arguments": ["lsp-proxy"]
}
}
}
}
```

#### Logs

Zed will print logs in the following directory: `~/Library/Logs/Zed/Zed.log`
28 changes: 20 additions & 8 deletions src/biome.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::{env, fs, path::Path};
use zed::settings::LspSettings;
use zed_extension_api::{self as zed, serde_json, LanguageServerId, Result};

const SERVER_PATH: &str = "node_modules/@biomejs/biome/bin/biome";
Expand Down Expand Up @@ -86,17 +87,28 @@ impl zed::Extension for BiomeExtension {
worktree: &zed::Worktree,
) -> Result<zed::Command> {
let path = self.server_script_path(language_server_id, worktree)?;
let settings = LspSettings::for_worktree(language_server_id.as_ref(), worktree)?;

let args = vec![
env::current_dir()
.unwrap()
.join(path)
.to_string_lossy()
.to_string(),
"lsp-proxy".to_string(),
];

if let Some(binary) = settings.binary {
return Ok(zed::Command {
command: binary.path.map_or(zed::node_binary_path()?, |path| path),
args: binary.arguments.map_or(args, |args| args),
env: Default::default(),
});
}

Ok(zed::Command {
command: zed::node_binary_path()?,
args: vec![
env::current_dir()
.unwrap()
.join(path)
.to_string_lossy()
.to_string(),
"lsp-proxy".to_string(),
],
args,
env: Default::default(),
})
}
Expand Down

0 comments on commit b28e3c6

Please sign in to comment.