typescript: Make it possible to use local vtsls (#15775)

Related things:
https://github.com/zed-industries/zed/issues/7902
https://github.com/zed-industries/zed/issues/4978

Release Notes:
- Added: positibily to use locally installed vtsls
This commit is contained in:
Konstantin Matsiushonak 2024-08-06 14:37:13 +04:00 committed by GitHub
parent d6e5265e84
commit f4a58e5411
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -5,7 +5,7 @@ use gpui::AsyncAppContext;
use language::{LanguageServerName, LspAdapter, LspAdapterDelegate};
use lsp::{CodeActionKind, LanguageServerBinary};
use node_runtime::NodeRuntime;
use project::project_settings::ProjectSettings;
use project::project_settings::{BinarySettings, ProjectSettings};
use serde_json::{json, Value};
use settings::Settings;
use std::{
@ -69,6 +69,48 @@ impl LspAdapter for VtslsLspAdapter {
}) as Box<_>)
}
async fn check_if_user_installed(
&self,
delegate: &dyn LspAdapterDelegate,
cx: &AsyncAppContext,
) -> Option<LanguageServerBinary> {
let configured_binary = cx.update(|cx| {
ProjectSettings::get_global(cx)
.lsp
.get(SERVER_NAME)
.and_then(|s| s.binary.clone())
});
match configured_binary {
Ok(Some(BinarySettings {
path: Some(path),
arguments,
..
})) => Some(LanguageServerBinary {
path: path.into(),
arguments: arguments
.unwrap_or_default()
.iter()
.map(|arg| arg.into())
.collect(),
env: None,
}),
Ok(Some(BinarySettings {
path_lookup: Some(false),
..
})) => None,
_ => {
let env = delegate.shell_env().await;
let path = delegate.which(SERVER_NAME.as_ref()).await?;
Some(LanguageServerBinary {
path: path.clone(),
arguments: typescript_server_binary_arguments(&path),
env: Some(env),
})
}
}
}
async fn fetch_server_binary(
&self,
latest_version: Box<dyn 'static + Send + Any>,