Initial impl of NodeRuntime
w/JSON borked and a deadlock :)
Co-Authored-By: Antonio Scandurra <me@as-cii.com>
This commit is contained in:
parent
1a2e509e35
commit
c72d33e029
20 changed files with 435 additions and 375 deletions
|
@ -1,25 +1,36 @@
|
|||
use super::node_runtime::NodeRuntime;
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use async_trait::async_trait;
|
||||
use client::http::HttpClient;
|
||||
use futures::{future::BoxFuture, FutureExt, StreamExt};
|
||||
use gpui::MutableAppContext;
|
||||
use language::{LanguageServerBinary, LanguageServerName, LspAdapter, ServerExecutionKind};
|
||||
use language::{LanguageServerBinary, LanguageServerName, LspAdapter};
|
||||
use serde_json::Value;
|
||||
use settings::Settings;
|
||||
use smol::fs;
|
||||
use std::{any::Any, future, path::PathBuf, sync::Arc};
|
||||
use std::{
|
||||
any::Any,
|
||||
ffi::OsString,
|
||||
future,
|
||||
path::{Path, PathBuf},
|
||||
sync::Arc,
|
||||
};
|
||||
use util::ResultExt;
|
||||
|
||||
use super::installation::{npm_install_packages, npm_package_latest_version};
|
||||
|
||||
fn server_binary_arguments() -> Vec<String> {
|
||||
vec!["--stdio".into()]
|
||||
fn server_binary_arguments(server_path: &Path) -> Vec<OsString> {
|
||||
vec![server_path.into(), "--stdio".into()]
|
||||
}
|
||||
|
||||
pub struct YamlLspAdapter;
|
||||
pub struct YamlLspAdapter {
|
||||
node: Arc<NodeRuntime>,
|
||||
}
|
||||
|
||||
impl YamlLspAdapter {
|
||||
const BIN_PATH: &'static str = "node_modules/yaml-language-server/bin/yaml-language-server";
|
||||
const SERVER_PATH: &'static str = "node_modules/yaml-language-server/bin/yaml-language-server";
|
||||
|
||||
pub fn new(node: Arc<NodeRuntime>) -> Self {
|
||||
YamlLspAdapter { node }
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
|
@ -28,21 +39,21 @@ impl LspAdapter for YamlLspAdapter {
|
|||
LanguageServerName("yaml-language-server".into())
|
||||
}
|
||||
|
||||
async fn server_execution_kind(&self) -> ServerExecutionKind {
|
||||
ServerExecutionKind::Node
|
||||
}
|
||||
|
||||
async fn fetch_latest_server_version(
|
||||
&self,
|
||||
http: Arc<dyn HttpClient>,
|
||||
_: Arc<dyn HttpClient>,
|
||||
) -> Result<Box<dyn 'static + Any + Send>> {
|
||||
Ok(Box::new(npm_package_latest_version(http, "yaml-language-server").await?) as Box<_>)
|
||||
Ok(Box::new(
|
||||
self.node
|
||||
.npm_package_latest_version("yaml-language-server")
|
||||
.await?,
|
||||
) as Box<_>)
|
||||
}
|
||||
|
||||
async fn fetch_server_binary(
|
||||
&self,
|
||||
version: Box<dyn 'static + Send + Any>,
|
||||
http: Arc<dyn HttpClient>,
|
||||
_: Arc<dyn HttpClient>,
|
||||
container_dir: PathBuf,
|
||||
) -> Result<LanguageServerBinary> {
|
||||
let version = version.downcast::<String>().unwrap();
|
||||
|
@ -50,15 +61,12 @@ impl LspAdapter for YamlLspAdapter {
|
|||
fs::create_dir_all(&version_dir)
|
||||
.await
|
||||
.context("failed to create version directory")?;
|
||||
let binary_path = version_dir.join(Self::BIN_PATH);
|
||||
let server_path = version_dir.join(Self::SERVER_PATH);
|
||||
|
||||
if fs::metadata(&binary_path).await.is_err() {
|
||||
npm_install_packages(
|
||||
http,
|
||||
[("yaml-language-server", version.as_str())],
|
||||
&version_dir,
|
||||
)
|
||||
.await?;
|
||||
if fs::metadata(&server_path).await.is_err() {
|
||||
self.node
|
||||
.npm_install_packages([("yaml-language-server", version.as_str())], &version_dir)
|
||||
.await?;
|
||||
|
||||
if let Some(mut entries) = fs::read_dir(&container_dir).await.log_err() {
|
||||
while let Some(entry) = entries.next().await {
|
||||
|
@ -73,8 +81,8 @@ impl LspAdapter for YamlLspAdapter {
|
|||
}
|
||||
|
||||
Ok(LanguageServerBinary {
|
||||
path: binary_path,
|
||||
arguments: server_binary_arguments(),
|
||||
path: self.node.binary_path().await?,
|
||||
arguments: server_binary_arguments(&server_path),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -89,11 +97,11 @@ 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() {
|
||||
let server_path = last_version_dir.join(Self::SERVER_PATH);
|
||||
if server_path.exists() {
|
||||
Ok(LanguageServerBinary {
|
||||
path: bin_path,
|
||||
arguments: server_binary_arguments(),
|
||||
path: self.node.binary_path().await?,
|
||||
arguments: server_binary_arguments(&server_path),
|
||||
})
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue