Remove server_args from LspAdapter

Prepare to remove concept of a runtime from greater server startup code,
which is important for future language server extensibility

Co-Authored-By: Antonio Scandurra <me@as-cii.com>
This commit is contained in:
Julia 2023-03-24 10:40:50 -04:00
parent ed442cfc8c
commit 1a2e509e35
14 changed files with 204 additions and 146 deletions

View file

@ -3,7 +3,7 @@ use async_trait::async_trait;
use client::http::HttpClient;
use futures::{future::BoxFuture, FutureExt, StreamExt};
use gpui::MutableAppContext;
use language::{LanguageServerName, LspAdapter, ServerExecutionKind};
use language::{LanguageServerBinary, LanguageServerName, LspAdapter, ServerExecutionKind};
use serde_json::Value;
use settings::Settings;
use smol::fs;
@ -12,6 +12,10 @@ use util::ResultExt;
use super::installation::{npm_install_packages, npm_package_latest_version};
fn server_binary_arguments() -> Vec<String> {
vec!["--stdio".into()]
}
pub struct YamlLspAdapter;
impl YamlLspAdapter {
@ -28,10 +32,6 @@ impl LspAdapter for YamlLspAdapter {
ServerExecutionKind::Node
}
async fn server_args(&self) -> Vec<String> {
vec!["--stdio".into()]
}
async fn fetch_latest_server_version(
&self,
http: Arc<dyn HttpClient>,
@ -44,7 +44,7 @@ impl LspAdapter for YamlLspAdapter {
version: Box<dyn 'static + Send + Any>,
http: Arc<dyn HttpClient>,
container_dir: PathBuf,
) -> Result<PathBuf> {
) -> Result<LanguageServerBinary> {
let version = version.downcast::<String>().unwrap();
let version_dir = container_dir.join(version.as_str());
fs::create_dir_all(&version_dir)
@ -72,10 +72,13 @@ impl LspAdapter for YamlLspAdapter {
}
}
Ok(binary_path)
Ok(LanguageServerBinary {
path: binary_path,
arguments: server_binary_arguments(),
})
}
async fn cached_server_binary(&self, container_dir: PathBuf) -> Option<PathBuf> {
async fn cached_server_binary(&self, container_dir: PathBuf) -> Option<LanguageServerBinary> {
(|| async move {
let mut last_version_dir = None;
let mut entries = fs::read_dir(&container_dir).await?;
@ -88,7 +91,10 @@ impl LspAdapter for YamlLspAdapter {
let last_version_dir = last_version_dir.ok_or_else(|| anyhow!("no cached binary"))?;
let bin_path = last_version_dir.join(Self::BIN_PATH);
if bin_path.exists() {
Ok(bin_path)
Ok(LanguageServerBinary {
path: bin_path,
arguments: server_binary_arguments(),
})
} else {
Err(anyhow!(
"missing executable in directory {:?}",