Skip to content

Commit 33963f2

Browse files
424evermaxdeviant
andauthored
Allow passing workspace configuration to the Language Server (#13)
This PR adds the ability to configure kotlin-language-server. --------- Co-authored-by: Marshall Bowers <[email protected]>
1 parent e98f432 commit 33963f2

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,30 @@
11
# zed-kotlin
22

33
Kotlin language support for [Zed](https://github.com/zed-industries/zed).
4+
5+
## Configuration
6+
7+
Workspace configuration options can be passed to the language server via lsp
8+
settings in `settings.json`.
9+
10+
The following example changes the JVM target from `default` (which is 1.8) to
11+
`17`:
12+
13+
```json
14+
{
15+
"lsp": {
16+
"kotlin-language-server": {
17+
"settings": {
18+
"compiler": {
19+
"jvm": {
20+
"target": "17"
21+
}
22+
}
23+
}
24+
}
25+
}
26+
}
27+
```
28+
29+
The full list of workspace configuration options can be found
30+
[here](https://github.com/fwcd/kotlin-language-server/blob/main/server/src/main/kotlin/org/javacs/kt/Configuration.kt).

src/kotlin.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::fs;
2+
use zed::serde_json;
23
use zed::LanguageServerId;
3-
use zed_extension_api::{self as zed, Result};
4+
use zed_extension_api::{self as zed, settings::LspSettings, Result};
45

56
struct KotlinExtension {
67
cached_binary_path: Option<String>,
@@ -83,6 +84,21 @@ impl zed::Extension for KotlinExtension {
8384
env: Default::default(),
8485
})
8586
}
87+
88+
fn language_server_workspace_configuration(
89+
&mut self,
90+
_language_server_id: &LanguageServerId,
91+
worktree: &zed_extension_api::Worktree,
92+
) -> Result<Option<serde_json::Value>> {
93+
let settings = LspSettings::for_worktree("kotlin-language-server", worktree)
94+
.ok()
95+
.and_then(|lsp_settings| lsp_settings.settings.clone())
96+
.unwrap_or_default();
97+
98+
Ok(Some(serde_json::json!({
99+
"kotlin": settings
100+
})))
101+
}
86102
}
87103

88104
zed::register_extension!(KotlinExtension);

0 commit comments

Comments
 (0)