-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Compute new entrypoint root when loading a file in the REPL (#1615)
* Add shelltests for `juvix repl` * repl: Compute entrypoint root when loading a file Previously the REPL would use app root (which could be the current directory or the project root of the initially loaded file). Thus files in a different project could not be loaded. The entrypoint root must be computed each time a new file is `:load`ed. Adds shell-tests for REPL commands * Move preludePath to Juvix.Extra.Paths
- Loading branch information
1 parent
3c9f27d
commit df4036d
Showing
5 changed files
with
212 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
module Root where | ||
|
||
import Control.Exception qualified as IO | ||
import Data.ByteString qualified as ByteString | ||
import Data.Yaml | ||
import Juvix.Compiler.Pipeline | ||
import Juvix.Extra.Paths qualified as Paths | ||
import Juvix.Prelude | ||
|
||
findRoot :: Maybe FilePath -> IO (FilePath, Package) | ||
findRoot minputFile = do | ||
whenJust (takeDirectory <$> minputFile) setCurrentDirectory | ||
r <- IO.try go | ||
case r of | ||
Left (err :: IO.SomeException) -> do | ||
putStrLn "Something went wrong when figuring out the root of the project." | ||
putStrLn (pack (IO.displayException err)) | ||
exitFailure | ||
Right root -> return root | ||
where | ||
possiblePaths :: FilePath -> [FilePath] | ||
possiblePaths start = takeWhile (/= "/") (aux start) | ||
where | ||
aux f = f : aux (takeDirectory f) | ||
|
||
go :: IO (FilePath, Package) | ||
go = do | ||
c <- getCurrentDirectory | ||
l <- findFile (possiblePaths c) Paths.juvixYamlFile | ||
case l of | ||
Nothing -> return (c, emptyPackage) | ||
Just yaml -> do | ||
bs <- ByteString.readFile yaml | ||
let isEmpty = ByteString.null bs | ||
pkg <- | ||
if | ||
| isEmpty -> return emptyPackage | ||
| otherwise -> decodeThrow bs | ||
return (takeDirectory yaml, pkg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.