From 993e4c7aba4ed915776ca2d5cf58a40761ec0af5 Mon Sep 17 00:00:00 2001 From: Travis Brown Date: Tue, 27 Jul 2021 18:59:56 +0200 Subject: [PATCH] Support resolution relative to a path with specified caches (#286) --- .../org/dhallj/imports/ResolveImports.scala | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/modules/imports/src/main/scala/org/dhallj/imports/ResolveImports.scala b/modules/imports/src/main/scala/org/dhallj/imports/ResolveImports.scala index d746bb72..13d3a30d 100644 --- a/modules/imports/src/main/scala/org/dhallj/imports/ResolveImports.scala +++ b/modules/imports/src/main/scala/org/dhallj/imports/ResolveImports.scala @@ -8,7 +8,7 @@ import org.http4s.client.Client object Resolver { def resolve[F[_] <: AnyRef](expr: Expr)(implicit Client: Client[F], F: Async[F]): F[Expr] = - F.flatMap(ResolveImportsVisitor[F](cwd))(expr.accept(_)) + resolveRelativeTo[F](cwd)(expr) def resolveRelativeTo[F[_] <: AnyRef](relativeTo: Path)( expr: Expr @@ -19,12 +19,23 @@ object Resolver { semanticCache: ImportCache[F], semiSemanticCache: ImportCache[F] )(expr: Expr)(implicit Client: Client[F], F: Async[F]): F[Expr] = - expr.accept(ResolveImportsVisitor[F](semanticCache, semiSemanticCache, cwd)) + resolveRelativeTo[F](semanticCache, semiSemanticCache)(cwd)(expr) + + def resolveRelativeTo[F[_] <: AnyRef]( + semanticCache: ImportCache[F], + semiSemanticCache: ImportCache[F] + )(relativeTo: Path)(expr: Expr)(implicit Client: Client[F], F: Async[F]): F[Expr] = + expr.accept(ResolveImportsVisitor[F](semanticCache, semiSemanticCache, relativeTo)) def resolve[F[_] <: AnyRef]( semanticCache: ImportCache[F] )(expr: Expr)(implicit Client: Client[F], F: Async[F]): F[Expr] = - expr.accept(ResolveImportsVisitor[F](semanticCache, new ImportCache.NoopImportCache[F], cwd)) + resolveRelativeTo[F](semanticCache)(cwd)(expr) + + def resolveRelativeTo[F[_] <: AnyRef]( + semanticCache: ImportCache[F] + )(relativeTo: Path)(expr: Expr)(implicit Client: Client[F], F: Async[F]): F[Expr] = + expr.accept(ResolveImportsVisitor[F](semanticCache, new ImportCache.NoopImportCache[F], relativeTo)) private def cwd: Path = Paths.get(".")