Skip to content

Commit

Permalink
try to fix PackageResolver.opts
Browse files Browse the repository at this point in the history
  • Loading branch information
johnynek committed Jan 31, 2025
1 parent bd9d1a0 commit ff10c6e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
11 changes: 8 additions & 3 deletions core/src/main/scala/org/bykn/bosatsu/library/Command.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ package org.bykn.bosatsu.library
import cats.{Monad, MonoidK}
import cats.data.NonEmptyList
import com.monovore.decline.Opts
import org.bykn.bosatsu.tool.{CliException, CompilerApi, Output, PathGen}
import org.bykn.bosatsu.tool.{
CliException,
CompilerApi,
Output,
PathGen,
PackageResolver
}
import org.bykn.bosatsu.hashing.{Algo, HashValue}
import org.bykn.bosatsu.LocationMap.Colorize
import org.bykn.bosatsu.{Json, PlatformIO}
Expand All @@ -13,7 +19,6 @@ import scala.collection.immutable.SortedMap
import _root_.bosatsu.{TypedAst => proto}

import cats.syntax.all._
import org.bykn.bosatsu.tool.PackageResolver

object Command {
def opts[F[_], P](platformIO: PlatformIO[F, P]): Opts[F[Output[P]]] = {
Expand Down Expand Up @@ -299,7 +304,7 @@ object Command {
): F[Doc] = {
val cas = new Cas(casDir, platformIO)
val inputRes =
PackageResolver.search(NonEmptyList.one(confDir), platformIO)
PackageResolver.LocalRoots[F, P](NonEmptyList.one(confDir), None)
for {
pubPriv <- cas.depsFromCas(conf.publicDeps, conf.privateDeps)
(pubLibs, privLibs) = pubPriv
Expand Down
21 changes: 13 additions & 8 deletions core/src/main/scala/org/bykn/bosatsu/tool/PackageResolver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -212,22 +212,27 @@ object PackageResolver {
roots: NonEmptyList[Path],
platformIO: PlatformIO[IO, Path]
): PackageResolver[IO, Path] =
PackageResolver.LocalRoots(
LocalRoots(
roots,
Some((p, pn) => platformIO.resolveFile(p, pn))
)

def opts[IO[_], Path](
platformIO: PlatformIO[IO, Path]
): Opts[PackageResolver[IO, Path]] =
(packRoot(platformIO) <* Opts.flag(
"search",
help =
"if set, we search the package_roots for imports not explicitly given"
)).orNone
(Opts
.flag(
"search",
help =
"if set, we search the package_roots for imports not explicitly given"
)
.orFalse
.product(packRoot(platformIO)))
.orNone
.map {
case None => PackageResolver.ExplicitOnly()
case Some(roots) => search(roots, platformIO)
case None => ExplicitOnly()
case Some((true, roots)) => search(roots, platformIO)
case Some((false, roots)) => LocalRoots(roots, None)
}

// type-checking and writing protos should be explicit. search option isn't supported
Expand Down

0 comments on commit ff10c6e

Please sign in to comment.