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

@ -6,7 +6,9 @@ use client::http::HttpClient;
use collections::HashMap;
use futures::{future::BoxFuture, io::BufReader, FutureExt, StreamExt};
use gpui::MutableAppContext;
use language::{LanguageRegistry, LanguageServerName, LspAdapter, ServerExecutionKind};
use language::{
LanguageRegistry, LanguageServerBinary, LanguageServerName, LspAdapter, ServerExecutionKind,
};
use serde_json::json;
use settings::{keymap_file_json_schema, settings_file_json_schema};
use smol::fs::{self, File};
@ -20,6 +22,10 @@ use std::{
use theme::ThemeRegistry;
use util::{paths, ResultExt, StaffMode};
fn server_binary_arguments() -> Vec<String> {
vec!["--stdio".into()]
}
pub struct JsonLspAdapter {
languages: Arc<LanguageRegistry>,
themes: Arc<ThemeRegistry>,
@ -41,10 +47,6 @@ impl LspAdapter for JsonLspAdapter {
ServerExecutionKind::Node
}
async fn server_args(&self) -> Vec<String> {
vec!["--stdio".into()]
}
async fn fetch_latest_server_version(
&self,
http: Arc<dyn HttpClient>,
@ -68,7 +70,7 @@ impl LspAdapter for JsonLspAdapter {
version: Box<dyn 'static + Send + Any>,
http: Arc<dyn HttpClient>,
container_dir: PathBuf,
) -> Result<PathBuf> {
) -> Result<LanguageServerBinary> {
let version = version.downcast::<GitHubLspBinaryVersion>().unwrap();
let destination_path = container_dir.join(format!(
"json-language-server-{}-{}",
@ -102,17 +104,23 @@ impl LspAdapter for JsonLspAdapter {
}
}
Ok(destination_path)
Ok(LanguageServerBinary {
path: destination_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 = None;
let mut entries = fs::read_dir(&container_dir).await?;
while let Some(entry) = entries.next().await {
last = Some(entry?.path());
}
last.ok_or_else(|| anyhow!("no cached binary"))
anyhow::Ok(LanguageServerBinary {
path: last.ok_or_else(|| anyhow!("no cached binary"))?,
arguments: server_binary_arguments(),
})
})()
.await
.log_err()