Allow wasm extensions to do arbitrary file I/O in their own directory to install language servers (#9043)
This PR provides WASM extensions with write access to their own specific working directory under the Zed `extensions` dir. This directory is set as the extensions `current_dir` when they run. Extensions can return relative paths from the `Extension::language_server_command` method, and those relative paths will be interpreted relative to this working dir. With this functionality, most language servers that we currently build into zed can be installed using extensions. Release Notes: - N/A
This commit is contained in:
parent
a550b9cecf
commit
51ebe0eb01
13 changed files with 421 additions and 215 deletions
|
@ -1,4 +1,4 @@
|
|||
use crate::wasm_host::{wit::LanguageServerConfig, WasmExtension};
|
||||
use crate::wasm_host::{wit::LanguageServerConfig, WasmExtension, WasmHost};
|
||||
use anyhow::{anyhow, Result};
|
||||
use async_trait::async_trait;
|
||||
use futures::{Future, FutureExt};
|
||||
|
@ -16,7 +16,7 @@ use wasmtime_wasi::preview2::WasiView as _;
|
|||
pub struct ExtensionLspAdapter {
|
||||
pub(crate) extension: WasmExtension,
|
||||
pub(crate) config: LanguageServerConfig,
|
||||
pub(crate) work_dir: PathBuf,
|
||||
pub(crate) host: Arc<WasmHost>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
|
@ -41,18 +41,23 @@ impl LspAdapter for ExtensionLspAdapter {
|
|||
|extension, store| {
|
||||
async move {
|
||||
let resource = store.data_mut().table().push(delegate)?;
|
||||
extension
|
||||
let command = extension
|
||||
.call_language_server_command(store, &this.config, resource)
|
||||
.await
|
||||
.await?
|
||||
.map_err(|e| anyhow!("{}", e))?;
|
||||
anyhow::Ok(command)
|
||||
}
|
||||
.boxed()
|
||||
}
|
||||
})
|
||||
.await?
|
||||
.map_err(|e| anyhow!("{}", e))?;
|
||||
.await?;
|
||||
|
||||
let path = self
|
||||
.host
|
||||
.path_from_extension(&self.extension.manifest.id, command.command.as_ref());
|
||||
|
||||
Ok(LanguageServerBinary {
|
||||
path: self.work_dir.join(&command.command),
|
||||
path,
|
||||
arguments: command.args.into_iter().map(|arg| arg.into()).collect(),
|
||||
env: Some(command.env.into_iter().collect()),
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue