From b9cb94ab03714eb8a367b501fa46e8316e1e2d18 Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Tue, 05 May 2026 00:54:30 +0000 Subject: [PATCH] feat: async import ergonomics --- --- a/crates/jrsonnet-evaluator/src/async_import.rs +++ b/crates/jrsonnet-evaluator/src/async_import.rs @@ -52,10 +52,15 @@ ) -> impl Future, Self::Error>>; } -#[derive(Acyclic)] -struct ResolvedImportResolver { +#[derive(Acyclic, Default)] +pub struct ResolvedImportResolver { resolved: RefCell>, } +impl ResolvedImportResolver { + pub fn new() -> Self { + Self::default() + } +} impl ImportResolver for ResolvedImportResolver { fn load_file_contents(&self, _resolved: &SourcePath) -> crate::Result> { unreachable!("all files should be loaded at this point"); @@ -83,7 +88,11 @@ } #[allow(clippy::future_not_send)] -pub async fn async_import(s: State, handler: H, path: &dyn AsPathLike) -> Result<(), H::Error> +pub async fn async_import( + s: State, + handler: H, + path: &dyn AsPathLike, +) -> Result where H: AsyncImportResolver, { @@ -91,8 +100,9 @@ .downcast_ref::() .expect("for async imports, import_resolver should be set to ResolvedImportResolver"); + let entry = handler.resolve_from_default(path).await?; let mut queue = vec![Job::LoadFile { - path: handler.resolve_from_default(path).await?, + path: entry.clone(), parse: true, }]; while let Some(job) = queue.pop() { @@ -143,13 +153,17 @@ continue; } } - let resolved = handler.resolve_from(&from, &import.path).await?; + let resolved_path = handler.resolve_from(&from, &import.path).await?; + resolved.resolved.borrow_mut().insert( + (from.clone(), import.path.clone()), + (resolved_path.clone(), import.expression), + ); queue.push(Job::LoadFile { - path: resolved, + path: resolved_path, parse: import.expression, }); } } } - Ok(()) + Ok(entry) } -- gitstuff