Introduce LspAdapterDelegate trait, passed to LspDelegates

This commit is contained in:
Max Brunsfeld 2023-06-19 15:56:40 -07:00
parent 05d69c804c
commit 360bbebbd9
13 changed files with 243 additions and 133 deletions

View file

@ -1,14 +1,16 @@
use anyhow::{anyhow, Result};
use async_trait::async_trait;
use futures::StreamExt;
use language::{LanguageServerBinary, LanguageServerName, LspAdapter};
use language::{LanguageServerBinary, LanguageServerName, LspAdapter, LspAdapterDelegate};
use node_runtime::NodeRuntime;
use serde_json::json;
use smol::fs;
use std::ffi::OsString;
use std::path::Path;
use std::{any::Any, path::PathBuf, sync::Arc};
use util::http::HttpClient;
use std::{
any::Any,
ffi::OsString,
path::{Path, PathBuf},
sync::Arc,
};
use util::ResultExt;
fn server_binary_arguments(server_path: &Path) -> Vec<OsString> {
@ -36,7 +38,7 @@ impl LspAdapter for HtmlLspAdapter {
async fn fetch_latest_server_version(
&self,
_: Arc<dyn HttpClient>,
_: &dyn LspAdapterDelegate,
) -> Result<Box<dyn 'static + Any + Send>> {
Ok(Box::new(
self.node
@ -48,8 +50,8 @@ impl LspAdapter for HtmlLspAdapter {
async fn fetch_server_binary(
&self,
version: Box<dyn 'static + Send + Any>,
_: Arc<dyn HttpClient>,
container_dir: PathBuf,
_: &dyn LspAdapterDelegate,
) -> Result<LanguageServerBinary> {
let version = version.downcast::<String>().unwrap();
let server_path = container_dir.join(Self::SERVER_PATH);
@ -69,7 +71,11 @@ impl LspAdapter for HtmlLspAdapter {
})
}
async fn cached_server_binary(&self, container_dir: PathBuf) -> Option<LanguageServerBinary> {
async fn cached_server_binary(
&self,
container_dir: PathBuf,
_: &dyn LspAdapterDelegate,
) -> Option<LanguageServerBinary> {
(|| async move {
let mut last_version_dir = None;
let mut entries = fs::read_dir(&container_dir).await?;