Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add minimal Scala support - tree-sitter, Metals #7933

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ tree-sitter-python = "0.20.2"
tree-sitter-racket = { git = "https://github.com/zed-industries/tree-sitter-racket", rev = "eb010cf2c674c6fd9a6316a84e28ef90190fe51a" }
tree-sitter-ruby = "0.20.0"
tree-sitter-rust = "0.20.3"
tree-sitter-scala = { git = "https://github.com/tree-sitter/tree-sitter-scala.git", rev = "45b5ba0e749a8477a8fd2666f082f352859bdc3c" }
tree-sitter-scheme = { git = "https://github.com/6cdh/tree-sitter-scheme", rev = "af0fd1fa452cb2562dc7b5c8a8c55551c39273b9" }
tree-sitter-svelte = { git = "https://github.com/Himujjal/tree-sitter-svelte", rev = "bd60db7d3d06f89b6ec3b287c9a6e9190b5564bd" }
tree-sitter-toml = { git = "https://github.com/tree-sitter/tree-sitter-toml", rev = "342d9be207c2dba869b9967124c679b5e6fd0ebe" }
Expand Down
1 change: 1 addition & 0 deletions crates/languages/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ tree-sitter-python.workspace = true
tree-sitter-racket.workspace = true
tree-sitter-ruby.workspace = true
tree-sitter-rust.workspace = true
tree-sitter-scala.workspace = true
tree-sitter-scheme.workspace = true
tree-sitter-svelte.workspace = true
tree-sitter-toml.workspace = true
Expand Down
3 changes: 3 additions & 0 deletions crates/languages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ mod purescript;
mod python;
mod ruby;
mod rust;
mod scala;
mod svelte;
mod tailwind;
mod terraform;
Expand Down Expand Up @@ -109,6 +110,7 @@ pub fn init(
("racket", tree_sitter_racket::language()),
("ruby", tree_sitter_ruby::language()),
("rust", tree_sitter_rust::language()),
("scala", tree_sitter_scala::language()),
("scheme", tree_sitter_scheme::language()),
("svelte", tree_sitter_svelte::language()),
("toml", tree_sitter_toml::language()),
Expand Down Expand Up @@ -359,6 +361,7 @@ pub fn init(
))]
);
language!("dart", vec![Arc::new(dart::DartLanguageServer {})]);
language!("scala", vec![Arc::new(scala::MetalsLspAdapter {})]);
}

#[cfg(any(test, feature = "test-support"))]
Expand Down
58 changes: 58 additions & 0 deletions crates/languages/src/scala.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
use anyhow::{anyhow, Result};
use async_trait::async_trait;
pub use language::*;
use lsp::LanguageServerBinary;
use std::{any::Any, path::PathBuf};

pub struct MetalsLspAdapter;

#[async_trait]
impl LspAdapter for MetalsLspAdapter {
fn name(&self) -> LanguageServerName {
LanguageServerName("metals".into())
}

async fn fetch_latest_server_version(
&self,
_: &dyn LspAdapterDelegate,
) -> Result<Box<dyn 'static + Any + Send>> {
Ok(Box::new(()))
}

async fn fetch_server_binary(
&self,
_version: Box<dyn 'static + Send + Any>,
_container_dir: PathBuf,
_: &dyn LspAdapterDelegate,
) -> Result<LanguageServerBinary> {
Err(anyhow!(
"metals must be installed and available in your $PATH"
))
}

async fn cached_server_binary(
&self,
_: PathBuf,
_: &dyn LspAdapterDelegate,
) -> Option<LanguageServerBinary> {
Some(LanguageServerBinary {
path: "metals".into(),
env: None,
arguments: vec![],
})
}

fn can_be_reinstalled(&self) -> bool {
false
}

async fn installation_test_binary(
&self,
_container_dir: PathBuf,
) -> Option<LanguageServerBinary> {
None
}
}

#[cfg(test)]
mod tests {}
3 changes: 3 additions & 0 deletions crates/languages/src/scala/brackets.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
("(" @open ")" @close)
("[" @open "]" @close)
("{" @open "}" @close)
15 changes: 15 additions & 0 deletions crates/languages/src/scala/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name = "Scala"
grammar = "scala"
path_suffixes = ["scala", "sbt", "sc"]
line_comments = ["// "]
autoclose_before = ";:.,=}])"
brackets = [
{ start = "{", end = "}", close = true, newline = true },
{ start = "[", end = "]", close = true, newline = true },
{ start = "(", end = ")", close = true, newline = true },
{ start = "\"", end = "\"", close = true, newline = false, not_in = ["comment", "string"] },
{ start = "'", end = "'", close = true, newline = false, not_in = ["comment", "string"] },
{ start = "`", end = "`", close = true, newline = false, not_in = ["comment", "string"] },
{ start = "/*", end = " */", close = true, newline = false, not_in = ["comment", "string"] }
]
collapsed_placeholder = " /* ... */ "
Loading
Loading