Async runtime working but is blocking

This commit is contained in:
Isaac Clayton 2022-06-08 09:49:25 +02:00
parent 8bce35d1e9
commit d7b97b25b8
2 changed files with 48 additions and 56 deletions

View file

@ -61,21 +61,20 @@ impl LspAdapter for PluginLspAdapter {
&self, &self,
_: Arc<dyn HttpClient>, _: Arc<dyn HttpClient>,
) -> BoxFuture<'static, Result<Box<dyn 'static + Send + Any>>> { ) -> BoxFuture<'static, Result<Box<dyn 'static + Send + Any>>> {
todo!() let versions: Result<Option<String>> = call_block!(self, "fetch_latest_server_version", ());
// async move { async move {
// let versions: Result<String, String> = self // let versions: Result<Option<String>> = self
// .runtime // .runtime
// .lock() // .lock()
// .call::<_, Option<String>>("fetch_latest_server_version", ()) // .call::<_, Option<String>>("fetch_latest_server_version", ())
// .await?; // .await;
// versions.map(|(language_version, server_version)| {
// Box::new(Versions { versions
// language_version, .map_err(|e| anyhow!("{}", e))?
// server_version, .ok_or_else(|| anyhow!("Could not fetch latest server version"))
// }) as Box<_> .map(|v| Box::new(v) as Box<_>)
// }) }
// } .boxed()
// .boxed()
} }
fn fetch_server_binary( fn fetch_server_binary(
@ -84,37 +83,30 @@ impl LspAdapter for PluginLspAdapter {
_: Arc<dyn HttpClient>, _: Arc<dyn HttpClient>,
container_dir: PathBuf, container_dir: PathBuf,
) -> BoxFuture<'static, Result<PathBuf>> { ) -> BoxFuture<'static, Result<PathBuf>> {
todo!() let version = version.downcast::<String>().unwrap();
// let version = version.downcast::<String>().unwrap(); let mut runtime = self.runtime.lock();
let result = (|| {
let handle = runtime.attach_path(&container_dir)?;
let result: Option<PathBuf> =
call_block!(self, "fetch_server_binary", (container_dir, version))?;
runtime.remove_resource(handle)?;
result.ok_or_else(|| anyhow!("Could not load cached server binary"))
})();
// async move { async move { result }.boxed()
// let runtime = self.runtime.clone();
// let handle = runtime.lock().attach_path(&container_dir).unwrap();
// let result = runtime
// .lock()
// .call::<_, Option<PathBuf>>("fetch_server_binary", container_dir)
// .await
// .unwrap()
// .ok_or_else(|| anyhow!("Could not load cached server binary"));
// // runtime.remove_resource(handle).ok();
// result
// }
// .boxed()
} }
fn cached_server_binary(&self, container_dir: PathBuf) -> BoxFuture<'static, Option<PathBuf>> { fn cached_server_binary(&self, container_dir: PathBuf) -> BoxFuture<'static, Option<PathBuf>> {
todo!() let mut runtime = self.runtime.lock();
// let runtime = self.runtime.clone(); let result: Option<PathBuf> = (|| {
// async move { let handle = runtime.attach_path(&container_dir).ok()?;
// let handle = runtime.lock().attach_path(&container_dir).ok()?; let result: Option<PathBuf> =
// let result = runtime call_block!(self, "cached_server_binary", container_dir).ok()?;
// .lock() runtime.remove_resource(handle).ok()?;
// .call::<_, Option<PathBuf>>("cached_server_binary", container_dir); result
// let result = result.await; })();
// runtime.lock().remove_resource(handle).ok()?;
// result.ok()? async move { result }.boxed()
// }
// .boxed()
} }
fn process_diagnostics(&self, _: &mut lsp::PublishDiagnosticsParams) {} fn process_diagnostics(&self, _: &mut lsp::PublishDiagnosticsParams) {}

View file

@ -41,24 +41,24 @@ pub fn server_args() -> Vec<String> {
vec!["--stdio".into()] vec!["--stdio".into()]
} }
// #[bind] #[bind]
// pub fn fetch_latest_server_version() -> Option<String> { pub fn fetch_latest_server_version() -> Option<String> {
// #[derive(Deserialize)] #[derive(Deserialize)]
// struct NpmInfo { struct NpmInfo {
// versions: Vec<String>, versions: Vec<String>,
// } }
// let output = command("npm info vscode-json-languageserver --json")?; let output = command("npm info vscode-json-languageserver --json")?;
// if !output.status.success() { if !output.status.success() {
// return None; return None;
// } }
// let mut info: NpmInfo = serde_json::from_slice(&output.stdout)?; let mut info: NpmInfo = serde_json::from_slice(&output.stdout)?;
// info.versions.pop() info.versions.pop()
// } }
// #[bind] // #[bind]
// pub fn fetch_server_binary(container_dir: PathBuf, version: String) -> Result<PathBuf, String> { // pub fn fetch_server_binary(container_dir: PathBuf, version: String) -> Option<PathBuf> {
// let version_dir = container_dir.join(version.as_str()); // let version_dir = container_dir.join(version.as_str());
// fs::create_dir_all(&version_dir) // fs::create_dir_all(&version_dir)
// .or_or_else(|| "failed to create version directory".to_string())?; // .or_or_else(|| "failed to create version directory".to_string())?;