Get it to build with multiple adapters per language! 🎉

Co-Authored-By: Max Brunsfeld <max@zed.dev>
This commit is contained in:
Julia 2023-04-17 16:55:10 -04:00 committed by Max Brunsfeld
parent ba7233f265
commit 6e68ff5a50
5 changed files with 100 additions and 89 deletions

View file

@ -89,23 +89,26 @@ pub fn init(
(
"tsx",
tree_sitter_typescript::language_tsx(),
vec![adapter_arc(typescript::TypeScriptLspAdapter::new(
node_runtime.clone(),
))],
vec![
adapter_arc(typescript::TypeScriptLspAdapter::new(node_runtime.clone())),
adapter_arc(typescript::EsLintLspAdapter::new(node_runtime.clone())),
],
),
(
"typescript",
tree_sitter_typescript::language_typescript(),
vec![adapter_arc(typescript::TypeScriptLspAdapter::new(
node_runtime.clone(),
))],
vec![
adapter_arc(typescript::TypeScriptLspAdapter::new(node_runtime.clone())),
adapter_arc(typescript::EsLintLspAdapter::new(node_runtime.clone())),
],
),
(
"javascript",
tree_sitter_typescript::language_tsx(),
vec![adapter_arc(typescript::TypeScriptLspAdapter::new(
node_runtime.clone(),
))],
vec![
adapter_arc(typescript::TypeScriptLspAdapter::new(node_runtime.clone())),
adapter_arc(typescript::EsLintLspAdapter::new(node_runtime.clone())),
],
),
(
"html",
@ -149,7 +152,7 @@ pub async fn language(
) -> Arc<Language> {
Arc::new(
Language::new(load_config(name), Some(grammar))
.with_lsp_adapters(lsp_adapter)
.with_lsp_adapters(lsp_adapter.into_iter().collect())
.await
.with_queries(load_queries(name))
.unwrap(),

View file

@ -15,7 +15,7 @@ use std::{
use util::http::HttpClient;
use util::ResultExt;
fn server_binary_arguments(server_path: &Path) -> Vec<OsString> {
fn typescript_server_binary_arguments(server_path: &Path) -> Vec<OsString> {
vec![
server_path.into(),
"--stdio".into(),
@ -24,6 +24,10 @@ fn server_binary_arguments(server_path: &Path) -> Vec<OsString> {
]
}
fn eslint_server_binary_arguments(server_path: &Path) -> Vec<OsString> {
vec![server_path.into(), "--stdin".into()]
}
pub struct TypeScriptLspAdapter {
node: Arc<NodeRuntime>,
}
@ -89,7 +93,7 @@ impl LspAdapter for TypeScriptLspAdapter {
Ok(LanguageServerBinary {
path: self.node.binary_path().await?,
arguments: server_binary_arguments(&server_path),
arguments: typescript_server_binary_arguments(&server_path),
})
}
@ -101,12 +105,12 @@ impl LspAdapter for TypeScriptLspAdapter {
if new_server_path.exists() {
Ok(LanguageServerBinary {
path: self.node.binary_path().await?,
arguments: server_binary_arguments(&new_server_path),
arguments: typescript_server_binary_arguments(&new_server_path),
})
} else if old_server_path.exists() {
Ok(LanguageServerBinary {
path: self.node.binary_path().await?,
arguments: server_binary_arguments(&old_server_path),
arguments: typescript_server_binary_arguments(&old_server_path),
})
} else {
Err(anyhow!(
@ -169,7 +173,7 @@ pub struct EsLintLspAdapter {
}
impl EsLintLspAdapter {
const SERVER_PATH: &'static str = "node_modules/typescript-language-server/lib/cli.mjs";
const SERVER_PATH: &'static str = "node_modules/eslint/bin/eslint.js";
pub fn new(node: Arc<NodeRuntime>) -> Self {
EsLintLspAdapter { node }
@ -208,7 +212,7 @@ impl LspAdapter for EsLintLspAdapter {
Ok(LanguageServerBinary {
path: self.node.binary_path().await?,
arguments: server_binary_arguments(&server_path),
arguments: eslint_server_binary_arguments(&server_path),
})
}
@ -218,7 +222,7 @@ impl LspAdapter for EsLintLspAdapter {
if server_path.exists() {
Ok(LanguageServerBinary {
path: self.node.binary_path().await?,
arguments: server_binary_arguments(&server_path),
arguments: eslint_server_binary_arguments(&server_path),
})
} else {
Err(anyhow!(