Skip to content

Commit

Permalink
Merge pull request #19 from mprihoda/wip/metals-config
Browse files Browse the repository at this point in the history
Metals configuration enhancements
  • Loading branch information
tgodzik authored Aug 27, 2024
2 parents 737bb5a + 76a0720 commit b8ae0d4
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ Cargo.lock
*.pdb
.DS_Store
*.wasm

# Ignore build-generated grammars folder
grammars
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,27 @@ as inlay hints:
}
}
```

You can also set [Metals initialization options](https://scalameta.org/metals/docs/integrations/new-editor/#initializationoptions) and
[Metals server properties](https://scalameta.org/metals/docs/integrations/new-editor#metals-server-properties) in your zed settings.json
in `lsp.metals.binary.arguments` and `lsp.metals.initialization_options`, respectively.

For example, to [enable HTTP server](https://scalameta.org/metals/docs/integrations/new-editor#metals-http-client) (running on http://localhost:5031 by default)
for executing client commands, which currently are not supported by zed directly, you can use:

``` json
{
"lsp": {
"metals": {
"binary": {
"arguments": [
"-Dmetals.http=on"
]
},
"initialization_options": {
"isHttpEnabled": true
}
}
}
}
```
2 changes: 1 addition & 1 deletion extension.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ language = "Scala"

[grammars.scala]
repository = "https://github.com/tree-sitter/tree-sitter-scala"
commit = "45b5ba0e749a8477a8fd2666f082f352859bdc3c"
commit = "d9017869dda79cefe2dc9d23c6125eda0a2d5d22"
23 changes: 22 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,34 @@ impl zed::Extension for ScalaExtension {
.which("metals")
.ok_or_else(|| "Metals must be installed via coursier. Please install coursier (https://get-coursier.io/), and then run `cs install metals`.".to_string())?;

let arguments = LspSettings::for_worktree("metals", worktree)
.map(|lsp_settings| {
lsp_settings
.binary
.and_then(|binary| binary.arguments)
// If no arguments are provided, default to enabling the HTTP server.
.unwrap_or(vec!["-Dmetals.http=on".to_string()])
})
.unwrap_or_default();

Ok(zed::Command {
command: path,
args: vec![],
args: arguments,
env: worktree.shell_env(),
})
}

fn language_server_initialization_options(
&mut self,
_language_server_id: &zed_extension_api::LanguageServerId,
worktree: &zed_extension_api::Worktree,
) -> Result<Option<serde_json::Value>> {
let initialization_options = LspSettings::for_worktree("metals", worktree)
.map(|lsp_settings| lsp_settings.initialization_options.clone());

initialization_options
}

fn language_server_workspace_configuration(
&mut self,
_language_server_id: &zed::LanguageServerId,
Expand Down

0 comments on commit b8ae0d4

Please sign in to comment.