Compare commits

...

2 Commits

Author SHA1 Message Date
Max Brunsfeld
ec9dbd728a Add 'include' field to extension manifest, for copying files when packaging 2024-11-08 17:13:29 -08:00
Max Brunsfeld
1435900029 Let extensions access their own source code 2024-11-08 17:13:29 -08:00
5 changed files with 36 additions and 1 deletions

View File

@@ -82,6 +82,9 @@ pub struct ExtensionManifest {
pub indexed_docs_providers: BTreeMap<Arc<str>, IndexedDocsProviderEntry>,
#[serde(default)]
pub snippets: Option<PathBuf>,
#[serde(default)]
pub include: Vec<String>,
}
#[derive(Clone, Default, PartialEq, Eq, Debug, Deserialize, Serialize)]
@@ -214,5 +217,6 @@ fn manifest_from_old_manifest(
slash_commands: BTreeMap::default(),
indexed_docs_providers: BTreeMap::default(),
snippets: None,
include: Vec::new(),
}
}

View File

@@ -191,6 +191,22 @@ async fn copy_extension_resources(
}
}
if !manifest.include.is_empty() {
for include_path in &manifest.include {
copy_recursive(
fs.as_ref(),
&extension_path.join(&include_path),
&output_dir.join(&include_path),
CopyOptions {
overwrite: true,
ignore_if_exists: false,
},
)
.await
.with_context(|| format!("failed to copy included path '{}'", include_path))?;
}
}
Ok(())
}

View File

@@ -303,7 +303,7 @@ impl ExtensionStore {
let mut this = Self {
registration_hooks: extension_api.clone(),
extension_index: Default::default(),
installed_dir,
installed_dir: installed_dir.clone(),
index_path,
builder: Arc::new(ExtensionBuilder::new(builder_client, build_dir)),
outstanding_operations: Default::default(),
@@ -314,6 +314,7 @@ impl ExtensionStore {
http_client.clone(),
node_runtime,
extension_api,
installed_dir,
work_dir,
cx,
),

View File

@@ -37,6 +37,7 @@ pub struct WasmHost {
pub registration_hooks: Arc<dyn ExtensionRegistrationHooks>,
fs: Arc<dyn Fs>,
pub work_dir: PathBuf,
installed_dir: PathBuf,
_main_thread_message_task: Task<()>,
main_thread_message_tx: mpsc::UnboundedSender<MainThreadCall>,
}
@@ -82,6 +83,7 @@ impl WasmHost {
http_client: Arc<dyn HttpClient>,
node_runtime: NodeRuntime,
registration_hooks: Arc<dyn ExtensionRegistrationHooks>,
installed_dir: PathBuf,
work_dir: PathBuf,
cx: &mut AppContext,
) -> Arc<Self> {
@@ -95,6 +97,7 @@ impl WasmHost {
engine: wasm_engine(),
fs,
work_dir,
installed_dir,
http_client,
node_runtime,
registration_hooks,
@@ -160,6 +163,7 @@ impl WasmHost {
async fn build_wasi_ctx(&self, manifest: &Arc<ExtensionManifest>) -> Result<wasi::WasiCtx> {
let extension_work_dir = self.work_dir.join(manifest.id.as_ref());
let extension_src_dir = self.installed_dir.join(manifest.id.as_ref());
self.fs
.create_dir(&extension_work_dir)
.await
@@ -177,8 +181,15 @@ impl WasmHost {
dir_perms,
file_perms,
)?
.preopened_dir(
&extension_src_dir,
extension_src_dir.to_string_lossy(),
dir_perms,
file_perms,
)?
.env("PWD", extension_work_dir.to_string_lossy())
.env("RUST_BACKTRACE", "full")
.env("ZED_EXTENSION_SRC_DIR", extension_src_dir.to_string_lossy())
.build())
}

View File

@@ -166,6 +166,7 @@ async fn test_extension_store(cx: &mut TestAppContext) {
slash_commands: BTreeMap::default(),
indexed_docs_providers: BTreeMap::default(),
snippets: None,
include: Vec::new(),
}),
dev: false,
},
@@ -193,6 +194,7 @@ async fn test_extension_store(cx: &mut TestAppContext) {
slash_commands: BTreeMap::default(),
indexed_docs_providers: BTreeMap::default(),
snippets: None,
include: Vec::new(),
}),
dev: false,
},
@@ -365,6 +367,7 @@ async fn test_extension_store(cx: &mut TestAppContext) {
slash_commands: BTreeMap::default(),
indexed_docs_providers: BTreeMap::default(),
snippets: None,
include: Vec::new(),
}),
dev: false,
},