Skip to content

Commit b28e3c6

Browse files
authored
feat: use lsp settings to configure custom biome binary (#19)
* feat: use lsp settings to configure custom biome binary * Add custom binary guide to contributing.md
1 parent 3fe28d4 commit b28e3c6

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed

CONTRIBUTING.md

+18
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,24 @@ just install-tools
3333

3434
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.
3535

36+
### Custom biome binary
37+
38+
The binary used by the extension can be overriden in Zed settings.json using the `lsp` key:
39+
40+
```jsonc
41+
// settings.json
42+
{
43+
"lsp": {
44+
"biome": {
45+
"binary": {
46+
"path": "<path_to_biome_binary>",
47+
"arguments": ["lsp-proxy"]
48+
}
49+
}
50+
}
51+
}
52+
```
53+
3654
#### Logs
3755

3856
Zed will print logs in the following directory: `~/Library/Logs/Zed/Zed.log`

src/biome.rs

+20-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::{env, fs, path::Path};
2+
use zed::settings::LspSettings;
23
use zed_extension_api::{self as zed, serde_json, LanguageServerId, Result};
34

45
const SERVER_PATH: &str = "node_modules/@biomejs/biome/bin/biome";
@@ -86,17 +87,28 @@ impl zed::Extension for BiomeExtension {
8687
worktree: &zed::Worktree,
8788
) -> Result<zed::Command> {
8889
let path = self.server_script_path(language_server_id, worktree)?;
90+
let settings = LspSettings::for_worktree(language_server_id.as_ref(), worktree)?;
91+
92+
let args = vec![
93+
env::current_dir()
94+
.unwrap()
95+
.join(path)
96+
.to_string_lossy()
97+
.to_string(),
98+
"lsp-proxy".to_string(),
99+
];
100+
101+
if let Some(binary) = settings.binary {
102+
return Ok(zed::Command {
103+
command: binary.path.map_or(zed::node_binary_path()?, |path| path),
104+
args: binary.arguments.map_or(args, |args| args),
105+
env: Default::default(),
106+
});
107+
}
89108

90109
Ok(zed::Command {
91110
command: zed::node_binary_path()?,
92-
args: vec![
93-
env::current_dir()
94-
.unwrap()
95-
.join(path)
96-
.to_string_lossy()
97-
.to_string(),
98-
"lsp-proxy".to_string(),
99-
],
111+
args,
100112
env: Default::default(),
101113
})
102114
}

0 commit comments

Comments
 (0)