diff --git a/crates/extension/Cargo.toml b/crates/extension/Cargo.toml index d341f8f8700..9171378fffd 100644 --- a/crates/extension/Cargo.toml +++ b/crates/extension/Cargo.toml @@ -32,7 +32,7 @@ semver.workspace = true serde.workspace = true serde_json.workspace = true task.workspace = true -toml.workspace = true +toml = { workspace = true, features = ["display"] } tracing.workspace = true url.workspace = true util.workspace = true diff --git a/crates/extension/src/extension.rs b/crates/extension/src/extension.rs index 81d20ca337d..d1f5979ff9a 100644 --- a/crates/extension/src/extension.rs +++ b/crates/extension/src/extension.rs @@ -3,6 +3,7 @@ pub mod extension_builder; mod extension_events; mod extension_host_proxy; mod extension_manifest; +mod extension_resources; mod types; use std::path::{Path, PathBuf}; @@ -21,6 +22,7 @@ pub use crate::capabilities::*; pub use crate::extension_events::*; pub use crate::extension_host_proxy::*; pub use crate::extension_manifest::*; +pub use crate::extension_resources::*; pub use crate::types::*; /// Initializes the `extension` crate. diff --git a/crates/extension/src/extension_builder.rs b/crates/extension/src/extension_builder.rs index 5d7cd5548a3..433674da310 100644 --- a/crates/extension/src/extension_builder.rs +++ b/crates/extension/src/extension_builder.rs @@ -10,8 +10,6 @@ use futures::{ }; use heck::ToSnakeCase; use http_client::{self, AsyncBody, HttpClient}; -use language::LanguageConfig; -use path::PathExt; use semver::Version; use serde::Deserialize; use std::{ @@ -97,7 +95,9 @@ impl ExtensionBuilder { ) -> Result<()> { let start = std::time::Instant::now(); - populate_defaults(extension_manifest, extension_dir, fs.clone()).await?; + extension_manifest + .populate_defaults(extension_dir, fs.clone()) + .await?; anyhow::ensure!( extension_dir.is_absolute(), @@ -627,136 +627,6 @@ impl ExtensionBuilder { } } -async fn populate_defaults( - manifest: &mut ExtensionManifest, - extension_path: &Path, - fs: Arc, -) -> Result<()> { - // For legacy extensions on the v0 schema (aka, using `extension.json`), clear out any existing - // contents of the computed fields, since we don't care what the existing values are. - if manifest.schema_version.is_v0() { - manifest.languages.clear(); - manifest.grammars.clear(); - manifest.themes.clear(); - } - - let cargo_toml_path = extension_path.join("Cargo.toml"); - if cargo_toml_path.exists() { - manifest.lib.kind = Some(ExtensionLibraryKind::Rust); - } - - let languages_dir = extension_path.join("languages"); - if fs.is_dir(&languages_dir).await { - let mut language_dir_entries = fs - .read_dir(&languages_dir) - .await - .context("listing languages directory")?; - - while let Some(language_dir) = language_dir_entries.next().await { - let language_dir = language_dir?; - let config_path = language_dir.join(LanguageConfig::FILE_NAME); - if fs.is_file(config_path.as_path()).await { - let relative_language_dir = language_dir - .strip_prefix(extension_path)? - .to_rel_path_buf()?; - if !manifest.languages.contains(&relative_language_dir) { - manifest.languages.push(relative_language_dir); - } - } - } - } - - let themes_dir = extension_path.join("themes"); - if fs.is_dir(&themes_dir).await { - let mut theme_dir_entries = fs - .read_dir(&themes_dir) - .await - .context("listing themes directory")?; - - while let Some(theme_path) = theme_dir_entries.next().await { - let theme_path = theme_path?; - if theme_path.extension() == Some("json".as_ref()) { - let relative_theme_path = - theme_path.strip_prefix(extension_path)?.to_rel_path_buf()?; - if !manifest.themes.contains(&relative_theme_path) { - manifest.themes.push(relative_theme_path); - } - } - } - } - - let icon_themes_dir = extension_path.join("icon_themes"); - if fs.is_dir(&icon_themes_dir).await { - let mut icon_theme_dir_entries = fs - .read_dir(&icon_themes_dir) - .await - .context("listing icon themes directory")?; - - while let Some(icon_theme_path) = icon_theme_dir_entries.next().await { - let icon_theme_path = icon_theme_path?; - if icon_theme_path.extension() == Some("json".as_ref()) { - let relative_icon_theme_path = icon_theme_path - .strip_prefix(extension_path)? - .to_rel_path_buf()?; - if !manifest.icon_themes.contains(&relative_icon_theme_path) { - manifest.icon_themes.push(relative_icon_theme_path); - } - } - } - }; - if manifest.snippets.is_none() - && let snippets_json_path = extension_path.join("snippets.json") - && fs.is_file(&snippets_json_path).await - { - manifest.snippets = Some("snippets.json".into()); - } - - // For legacy extensions on the v0 schema (aka, using `extension.json`), we want to populate the grammars in - // the manifest using the contents of the `grammars` directory. - if manifest.schema_version.is_v0() { - let grammars_dir = extension_path.join("grammars"); - if fs.is_dir(&grammars_dir).await { - let mut grammar_dir_entries = fs - .read_dir(&grammars_dir) - .await - .context("listing grammars directory")?; - - while let Some(grammar_path) = grammar_dir_entries.next().await { - let grammar_path = grammar_path?; - if grammar_path.extension() == Some("toml".as_ref()) { - #[derive(Deserialize)] - struct GrammarConfigToml { - pub repository: String, - pub commit: String, - #[serde(default)] - pub path: Option, - } - - let grammar_config = fs.load(&grammar_path).await?; - let grammar_config: GrammarConfigToml = toml::from_str(&grammar_config)?; - - let grammar_name = grammar_path - .file_stem() - .and_then(|stem| stem.to_str()) - .context("no grammar name")?; - if !manifest.grammars.contains_key(grammar_name) { - manifest.grammars.insert( - grammar_name.into(), - GrammarManifestEntry { - repository: grammar_config.repository, - rev: grammar_config.commit, - path: grammar_config.path, - }, - ); - } - } - } - } - } - - Ok(()) -} - /// Returns `true` if the target exists and its last modified time is greater than that /// of each dependency which exists (i.e., dependency paths which do not exist are ignored). /// @@ -814,7 +684,7 @@ mod tests { use crate::{ ExtensionManifest, ExtensionSnippets, - extension_builder::{file_newer_than_deps, installed_wasi_sdk_version, populate_defaults}, + extension_builder::{file_newer_than_deps, installed_wasi_sdk_version}, }; #[test] @@ -904,7 +774,8 @@ mod tests { .await .unwrap(); - populate_defaults(&mut manifest, extension_path, fs.clone()) + manifest + .populate_defaults(extension_path, fs.clone()) .await .unwrap(); @@ -941,7 +812,8 @@ mod tests { .await .unwrap(); - populate_defaults(&mut manifest, extension_path, fs.clone()) + manifest + .populate_defaults(extension_path, fs.clone()) .await .unwrap(); diff --git a/crates/extension/src/extension_manifest.rs b/crates/extension/src/extension_manifest.rs index c2c2ddfa6bd..d3bf270f9b5 100644 --- a/crates/extension/src/extension_manifest.rs +++ b/crates/extension/src/extension_manifest.rs @@ -8,8 +8,10 @@ use anyhow::{Context as _, Result, anyhow, bail}; use cloud_api_types::ExtensionProvides; use collections::{BTreeMap, BTreeSet, HashMap}; use fs::Fs; -use language::LanguageName; +use futures::StreamExt as _; +use language::{LanguageConfig, LanguageName}; use lsp::LanguageServerName; +use path::PathExt as _; use semver::Version; use serde::{Deserialize, Serialize}; use util::paths::PathStyle; @@ -347,6 +349,138 @@ impl ExtensionManifest { anyhow::bail!("No extension manifest found for extension {extension_name}") } } + + /// Fills in the parts of the manifest that are derived from the extension's + /// directory layout (languages, themes, icon themes, snippets, library kind). + pub async fn populate_defaults( + &mut self, + extension_path: &Path, + fs: Arc, + ) -> Result<()> { + // For legacy extensions on the v0 schema (aka, using `extension.json`), clear out any existing + // contents of the computed fields, since we don't care what the existing values are. + if self.schema_version.is_v0() { + self.languages.clear(); + self.grammars.clear(); + self.themes.clear(); + } + + let cargo_toml_path = extension_path.join("Cargo.toml"); + if cargo_toml_path.exists() { + self.lib.kind = Some(ExtensionLibraryKind::Rust); + } + + let languages_dir = extension_path.join("languages"); + if fs.is_dir(&languages_dir).await { + let mut language_dir_entries = fs + .read_dir(&languages_dir) + .await + .context("listing languages directory")?; + + while let Some(language_dir) = language_dir_entries.next().await { + let language_dir = language_dir?; + let config_path = language_dir.join(LanguageConfig::FILE_NAME); + if fs.is_file(config_path.as_path()).await { + let relative_language_dir = language_dir + .strip_prefix(extension_path)? + .to_rel_path_buf()?; + if !self.languages.contains(&relative_language_dir) { + self.languages.push(relative_language_dir); + } + } + } + } + + let themes_dir = extension_path.join("themes"); + if fs.is_dir(&themes_dir).await { + let mut theme_dir_entries = fs + .read_dir(&themes_dir) + .await + .context("listing themes directory")?; + + while let Some(theme_path) = theme_dir_entries.next().await { + let theme_path = theme_path?; + if theme_path.extension() == Some("json".as_ref()) { + let relative_theme_path = + theme_path.strip_prefix(extension_path)?.to_rel_path_buf()?; + if !self.themes.contains(&relative_theme_path) { + self.themes.push(relative_theme_path); + } + } + } + } + + let icon_themes_dir = extension_path.join("icon_themes"); + if fs.is_dir(&icon_themes_dir).await { + let mut icon_theme_dir_entries = fs + .read_dir(&icon_themes_dir) + .await + .context("listing icon themes directory")?; + + while let Some(icon_theme_path) = icon_theme_dir_entries.next().await { + let icon_theme_path = icon_theme_path?; + if icon_theme_path.extension() == Some("json".as_ref()) { + let relative_icon_theme_path = icon_theme_path + .strip_prefix(extension_path)? + .to_rel_path_buf()?; + if !self.icon_themes.contains(&relative_icon_theme_path) { + self.icon_themes.push(relative_icon_theme_path); + } + } + } + }; + if self.snippets.is_none() + && let snippets_json_path = extension_path.join("snippets.json") + && fs.is_file(&snippets_json_path).await + { + self.snippets = Some("snippets.json".into()); + } + + // For legacy extensions on the v0 schema (aka, using `extension.json`), we want to populate the grammars in + // the manifest using the contents of the `grammars` directory. + if self.schema_version.is_v0() { + let grammars_dir = extension_path.join("grammars"); + if fs.is_dir(&grammars_dir).await { + let mut grammar_dir_entries = fs + .read_dir(&grammars_dir) + .await + .context("listing grammars directory")?; + + while let Some(grammar_path) = grammar_dir_entries.next().await { + let grammar_path = grammar_path?; + if grammar_path.extension() == Some("toml".as_ref()) { + #[derive(Deserialize)] + struct GrammarConfigToml { + pub repository: String, + pub commit: String, + #[serde(default)] + pub path: Option, + } + + let grammar_config = fs.load(&grammar_path).await?; + let grammar_config: GrammarConfigToml = toml::from_str(&grammar_config)?; + + let grammar_name = grammar_path + .file_stem() + .and_then(|stem| stem.to_str()) + .context("no grammar name")?; + if !self.grammars.contains_key(grammar_name) { + self.grammars.insert( + grammar_name.into(), + GrammarManifestEntry { + repository: grammar_config.repository, + rev: grammar_config.commit, + path: grammar_config.path, + }, + ); + } + } + } + } + } + + Ok(()) + } } fn manifest_from_old_manifest( diff --git a/crates/extension/src/extension_resources.rs b/crates/extension/src/extension_resources.rs new file mode 100644 index 00000000000..31ae4cf9275 --- /dev/null +++ b/crates/extension/src/extension_resources.rs @@ -0,0 +1,221 @@ +use std::path::{Path, PathBuf}; +use std::sync::Arc; + +use anyhow::{Context as _, Result}; +use fs::{CopyOptions, Fs, copy_recursive}; + +use crate::ExtensionManifest; + +async fn create_dir(fs: &dyn Fs, path: &Path) -> Result<()> { + fs.create_dir(path) + .await + .with_context(|| format!("creating {path:?}")) +} + +pub async fn copy_extension_resources( + manifest: &ExtensionManifest, + extension_path: &Path, + output_dir: &Path, + fs: Arc, +) -> Result<()> { + create_dir(fs.as_ref(), output_dir).await?; + + let manifest_toml = toml::to_string(manifest).context("serializing extension manifest")?; + let manifest_path = output_dir.join("extension.toml"); + fs.write(&manifest_path, manifest_toml.as_bytes()) + .await + .with_context(|| format!("writing {manifest_path:?}"))?; + + if manifest.lib.kind.is_some() { + let source_path = extension_path.join("extension.wasm"); + let output_path = output_dir.join("extension.wasm"); + fs.copy_file( + &source_path, + &output_path, + CopyOptions { + overwrite: true, + ignore_if_exists: false, + }, + ) + .await + .with_context(|| format!("copying {source_path:?} to {output_path:?}"))?; + } + + if !manifest.grammars.is_empty() { + let source_grammars_dir = extension_path.join("grammars"); + let output_grammars_dir = output_dir.join("grammars"); + create_dir(fs.as_ref(), &output_grammars_dir).await?; + futures::future::try_join_all(manifest.grammars.keys().map(|grammar_name| { + let fs = fs.clone(); + let source_grammars_dir = source_grammars_dir.as_path(); + let output_grammars_dir = output_grammars_dir.as_path(); + async move { + let mut grammar_filename = PathBuf::from(grammar_name.as_ref()); + grammar_filename.set_extension("wasm"); + fs.copy_file( + &source_grammars_dir.join(&grammar_filename), + &output_grammars_dir.join(&grammar_filename), + CopyOptions { + overwrite: true, + ignore_if_exists: false, + }, + ) + .await + .with_context(|| format!("copying grammar {grammar_filename:?}")) + } + })) + .await?; + } + + if !manifest.themes.is_empty() { + let output_themes_dir = output_dir.join("themes"); + create_dir(fs.as_ref(), &output_themes_dir).await?; + futures::future::try_join_all(manifest.themes.iter().map(|theme_path| { + let fs = fs.clone(); + let output_themes_dir = output_themes_dir.as_path(); + async move { + let theme_path = theme_path.as_std_path(); + fs.copy_file( + &extension_path.join(theme_path), + &output_themes_dir.join(theme_path.file_name().context("invalid theme path")?), + CopyOptions { + overwrite: true, + ignore_if_exists: false, + }, + ) + .await + .with_context(|| format!("copying theme {theme_path:?}")) + } + })) + .await?; + } + + if !manifest.icon_themes.is_empty() { + let output_icon_themes_dir = output_dir.join("icon_themes"); + create_dir(fs.as_ref(), &output_icon_themes_dir).await?; + futures::future::try_join_all(manifest.icon_themes.iter().map(|icon_theme_path| { + let fs = fs.clone(); + let output_icon_themes_dir = output_icon_themes_dir.as_path(); + async move { + let icon_theme_path = icon_theme_path.as_std_path(); + fs.copy_file( + &extension_path.join(icon_theme_path), + &output_icon_themes_dir.join( + icon_theme_path + .file_name() + .context("invalid icon theme path")?, + ), + CopyOptions { + overwrite: true, + ignore_if_exists: false, + }, + ) + .await + .with_context(|| format!("copying icon theme {icon_theme_path:?}")) + } + })) + .await?; + + let source_icons_dir = extension_path.join("icons"); + let output_icons_dir = output_dir.join("icons"); + create_dir(fs.as_ref(), &output_icons_dir).await?; + copy_recursive( + fs.as_ref(), + &source_icons_dir, + &output_icons_dir, + CopyOptions { + overwrite: true, + ignore_if_exists: false, + }, + ) + .await + .with_context(|| format!("copying {source_icons_dir:?} to {output_icons_dir:?}"))?; + } + + if !manifest.languages.is_empty() { + let output_languages_dir = output_dir.join("languages"); + create_dir(fs.as_ref(), &output_languages_dir).await?; + futures::future::try_join_all(manifest.languages.iter().map(|language_path| { + let fs = fs.clone(); + let output_languages_dir = output_languages_dir.clone(); + async move { + let language_path = language_path.as_std_path(); + let source_path = extension_path.join(language_path); + let output_path = output_languages_dir + .join(language_path.file_name().context("invalid language path")?); + copy_recursive( + fs.as_ref(), + &source_path, + &output_path, + CopyOptions { + overwrite: true, + ignore_if_exists: false, + }, + ) + .await + .with_context(|| format!("copying {source_path:?} to {output_path:?}")) + } + })) + .await?; + } + + if !manifest.debug_adapters.is_empty() { + futures::future::try_join_all(manifest.debug_adapters.iter().map( + |(debug_adapter, entry)| { + let fs = fs.clone(); + let debug_adapter = debug_adapter.clone(); + async move { + let schema_path = + crate::build_debug_adapter_schema_path(&debug_adapter, &entry)?; + let parent = schema_path.parent().with_context(|| { + format!("invalid empty schema path for {debug_adapter}") + })?; + let schema_path = schema_path.as_std_path(); + let source_path = extension_path.join(schema_path); + let output_path = output_dir.join(schema_path); + create_dir(fs.as_ref(), &output_dir.join(parent)).await?; + copy_recursive( + fs.as_ref(), + &source_path, + &output_path, + CopyOptions { + overwrite: true, + ignore_if_exists: false, + }, + ) + .await + .with_context(|| format!("copying {source_path:?} to {output_path:?}")) + } + }, + )) + .await?; + } + + if let Some(snippets) = manifest.snippets.as_ref() { + futures::future::try_join_all(snippets.paths().map(|snippets_path| { + let fs = fs.clone(); + async move { + let parent = snippets_path.parent(); + if let Some(parent) = parent.filter(|p| p.components().next().is_some()) { + create_dir(fs.as_ref(), &output_dir.join(parent)).await?; + } + let source_path = extension_path.join(snippets_path); + let output_path = output_dir.join(snippets_path); + copy_recursive( + fs.as_ref(), + &source_path, + &output_path, + CopyOptions { + overwrite: true, + ignore_if_exists: false, + }, + ) + .await + .with_context(|| format!("copying {source_path:?} to {output_path:?}")) + } + })) + .await?; + } + + Ok(()) +} diff --git a/crates/extension_cli/Cargo.toml b/crates/extension_cli/Cargo.toml index a9ca21d9e4f..9d6832ab06f 100644 --- a/crates/extension_cli/Cargo.toml +++ b/crates/extension_cli/Cargo.toml @@ -33,6 +33,6 @@ task.workspace = true theme_settings.workspace = true thiserror.workspace = true tokio = { workspace = true, features = ["fs", "macros", "parking_lot", "process", "sync", "time"] } -toml = { workspace = true, features = ["display"] } +toml.workspace = true tree-sitter = { workspace = true, features = ["wasm"] } wasmtime.workspace = true diff --git a/crates/extension_cli/src/main.rs b/crates/extension_cli/src/main.rs index b70039ae867..795db2bbb55 100644 --- a/crates/extension_cli/src/main.rs +++ b/crates/extension_cli/src/main.rs @@ -6,14 +6,14 @@ use std::path::{Path, PathBuf}; use std::str::FromStr as _; use std::sync::Arc; -use ::fs::{CopyOptions, Fs, RealFs, RemoveOptions, copy_recursive}; +use ::fs::{Fs, RealFs, RemoveOptions}; use anyhow::{Context as _, Result, anyhow, bail}; use clap::Parser; use cloud_api_types::ExtensionProvides; use extension::build_debug_adapter_schema_path; use extension::extension_builder::CompilationConcurrency; use extension::extension_builder::{CompileExtensionOptions, ExtensionBuilder}; -use extension::{ExtensionManifest, ExtensionSnippets}; +use extension::{ExtensionManifest, ExtensionSnippets, copy_extension_resources}; use http_client::Url; use language::LanguageConfig; use language::QueryFile; @@ -123,10 +123,14 @@ async fn main() -> Result<()> { let cx = TestingContext::new(&manifest, &extension_path); let grammars = test_grammars(&manifest, &extension_path, &mut wasm_store)?; test_languages(&manifest, &extension_path, &grammars, &cx)?; + log::info!("validating themes"); test_themes(&manifest, &extension_path, fs.clone()).await?; + log::info!("validating snippets"); test_snippets(&manifest, &extension_path, fs.clone()).await?; + log::info!("validating debug adapter schemas"); test_debug_adapter_schemas(&manifest, &extension_path, fs.clone()).await?; + log::info!("preparing archive directory"); let archive_dir = output_dir.join("archive"); fs.remove_dir( &archive_dir, @@ -137,10 +141,12 @@ async fn main() -> Result<()> { ) .await .ok(); + log::info!("copying extension resources"); copy_extension_resources(&manifest, &extension_path, &archive_dir, fs.clone()) .await .context("failed to copy extension resources")?; + log::info!("creating archive.tar.gz"); let tar_output = Command::new("tar") .current_dir(&output_dir) .args(["-czvf", "archive.tar.gz", "-C", "archive", "."]) @@ -177,217 +183,7 @@ async fn main() -> Result<()> { fs.write(&output_dir.join("manifest.json"), manifest_json.as_bytes()) .await?; - Ok(()) -} - -async fn copy_extension_resources( - manifest: &ExtensionManifest, - extension_path: &Path, - output_dir: &Path, - fs: Arc, -) -> Result<()> { - fs.create_dir(output_dir) - .await - .context("failed to create output dir")?; - - let manifest_toml = toml::to_string(&manifest).context("failed to serialize manifest")?; - fs.write(&output_dir.join("extension.toml"), manifest_toml.as_bytes()) - .await - .context("failed to write extension.toml")?; - - if manifest.lib.kind.is_some() { - fs.copy_file( - &extension_path.join("extension.wasm"), - &output_dir.join("extension.wasm"), - CopyOptions { - overwrite: true, - ignore_if_exists: false, - }, - ) - .await - .context("failed to copy extension.wasm")?; - } - - if !manifest.grammars.is_empty() { - let source_grammars_dir = extension_path.join("grammars"); - let output_grammars_dir = output_dir.join("grammars"); - fs.create_dir(&output_grammars_dir).await?; - futures::future::try_join_all(manifest.grammars.keys().map(|grammar_name| { - let fs = fs.clone(); - let source_grammars_dir = source_grammars_dir.as_path(); - let output_grammars_dir = output_grammars_dir.as_path(); - async move { - let mut grammar_filename = PathBuf::from(grammar_name.as_ref()); - grammar_filename.set_extension("wasm"); - fs.copy_file( - &source_grammars_dir.join(&grammar_filename), - &output_grammars_dir.join(&grammar_filename), - CopyOptions { - overwrite: true, - ignore_if_exists: false, - }, - ) - .await - .with_context(|| format!("failed to copy grammar '{}'", grammar_filename.display())) - } - })) - .await?; - } - - if !manifest.themes.is_empty() { - let output_themes_dir = output_dir.join("themes"); - fs.create_dir(&output_themes_dir).await?; - futures::future::try_join_all(manifest.themes.iter().map(|theme_path| { - let fs = fs.clone(); - let output_themes_dir = output_themes_dir.as_path(); - async move { - let theme_path = theme_path.as_std_path(); - fs.copy_file( - &extension_path.join(theme_path), - &output_themes_dir.join(theme_path.file_name().context("invalid theme path")?), - CopyOptions { - overwrite: true, - ignore_if_exists: false, - }, - ) - .await - .with_context(|| format!("failed to copy theme '{}'", theme_path.display())) - } - })) - .await?; - } - - if !manifest.icon_themes.is_empty() { - let output_icon_themes_dir = output_dir.join("icon_themes"); - fs.create_dir(&output_icon_themes_dir).await?; - futures::future::try_join_all(manifest.icon_themes.iter().map(|icon_theme_path| { - let fs = fs.clone(); - let output_icon_themes_dir = output_icon_themes_dir.as_path(); - async move { - let icon_theme_path = icon_theme_path.as_std_path(); - fs.copy_file( - &extension_path.join(icon_theme_path), - &output_icon_themes_dir.join( - icon_theme_path - .file_name() - .context("invalid icon theme path")?, - ), - CopyOptions { - overwrite: true, - ignore_if_exists: false, - }, - ) - .await - .with_context(|| { - format!("failed to copy icon theme '{}'", icon_theme_path.display()) - }) - } - })) - .await?; - - let output_icons_dir = output_dir.join("icons"); - fs.create_dir(&output_icons_dir).await?; - copy_recursive( - fs.as_ref(), - &extension_path.join("icons"), - &output_icons_dir, - CopyOptions { - overwrite: true, - ignore_if_exists: false, - }, - ) - .await - .context("failed to copy icons")?; - } - - if !manifest.languages.is_empty() { - let output_languages_dir = output_dir.join("languages"); - fs.create_dir(&output_languages_dir).await?; - futures::future::try_join_all(manifest.languages.iter().map(|language_path| { - let fs = fs.clone(); - let output_languages_dir = output_languages_dir.clone(); - async move { - let language_path = language_path.as_std_path(); - copy_recursive( - fs.as_ref(), - &extension_path.join(language_path), - &output_languages_dir - .join(language_path.file_name().context("invalid language path")?), - CopyOptions { - overwrite: true, - ignore_if_exists: false, - }, - ) - .await - .with_context(|| { - format!("failed to copy language dir '{}'", language_path.display()) - }) - } - })) - .await?; - } - - if !manifest.debug_adapters.is_empty() { - futures::future::try_join_all(manifest.debug_adapters.iter().map( - |(debug_adapter, entry)| { - let fs = fs.clone(); - let debug_adapter = debug_adapter.clone(); - async move { - let schema_path = - extension::build_debug_adapter_schema_path(&debug_adapter, &entry)?; - let parent = schema_path.parent().with_context(|| { - format!("invalid empty schema path for {debug_adapter}") - })?; - let schema_path = schema_path.as_std_path(); - fs.create_dir(&output_dir.join(parent)).await?; - copy_recursive( - fs.as_ref(), - &extension_path.join(schema_path), - &output_dir.join(schema_path), - CopyOptions { - overwrite: true, - ignore_if_exists: false, - }, - ) - .await - .with_context(|| { - format!( - "failed to copy debug adapter schema '{}'", - schema_path.display(), - ) - }) - } - }, - )) - .await?; - } - - if let Some(snippets) = manifest.snippets.as_ref() { - futures::future::try_join_all(snippets.paths().map(|snippets_path| { - let fs = fs.clone(); - async move { - let parent = snippets_path.parent(); - if let Some(parent) = parent.filter(|p| p.components().next().is_some()) { - fs.create_dir(&output_dir.join(parent)).await?; - } - copy_recursive( - fs.as_ref(), - &extension_path.join(&snippets_path), - &output_dir.join(&snippets_path), - CopyOptions { - overwrite: true, - ignore_if_exists: false, - }, - ) - .await - .with_context(|| { - format!("failed to copy snippets from '{}'", snippets_path.display()) - }) - } - })) - .await?; - } - + log::info!("extension packaged successfully"); Ok(()) }