More work on transitioning to async, need to figure out when to stop

This commit is contained in:
Isaac Clayton 2022-07-04 17:40:08 +02:00
parent feb6cf6789
commit f4b4212932
8 changed files with 109 additions and 113 deletions

View file

@ -19,31 +19,32 @@ impl JsonLspAdapter {
"node_modules/vscode-json-languageserver/bin/vscode-json-languageserver";
}
#[async_trait]
impl LspAdapter for JsonLspAdapter {
fn name(&self) -> LanguageServerName {
async fn name(&self) -> LanguageServerName {
LanguageServerName("vscode-json-languageserver".into())
}
fn server_args(&self) -> Vec<String> {
async fn server_args(&self) -> Vec<String> {
vec!["--stdio".into()]
}
fn fetch_latest_server_version(
async fn fetch_latest_server_version(
&self,
_: Arc<dyn HttpClient>,
) -> BoxFuture<'static, Result<Box<dyn 'static + Any + Send>>> {
) -> Result<Box<dyn 'static + Any + Send>> {
async move {
Ok(Box::new(npm_package_latest_version("vscode-json-languageserver").await?) as Box<_>)
}
.boxed()
}
fn fetch_server_binary(
async fn fetch_server_binary(
&self,
version: Box<dyn 'static + Send + Any>,
_: Arc<dyn HttpClient>,
container_dir: Arc<Path>,
) -> BoxFuture<'static, Result<PathBuf>> {
container_dir: PathBuf,
) -> Result<PathBuf> {
let version = version.downcast::<String>().unwrap();
async move {
let version_dir = container_dir.join(version.as_str());
@ -76,10 +77,7 @@ impl LspAdapter for JsonLspAdapter {
.boxed()
}
fn cached_server_binary(
&self,
container_dir: Arc<Path>,
) -> BoxFuture<'static, Option<PathBuf>> {
async fn cached_server_binary(&self, container_dir: PathBuf) -> Option<PathBuf> {
async move {
let mut last_version_dir = None;
let mut entries = fs::read_dir(&container_dir).await?;
@ -104,13 +102,13 @@ impl LspAdapter for JsonLspAdapter {
.boxed()
}
fn initialization_options(&self) -> Option<serde_json::Value> {
async fn initialization_options(&self) -> Option<serde_json::Value> {
Some(json!({
"provideFormatter": true
}))
}
fn id_for_language(&self, name: &str) -> Option<String> {
async fn id_for_language(&self, name: &str) -> Option<String> {
if name == "JSON" {
Some("jsonc".into())
} else {