diff --git a/app/App.hs b/app/App.hs index 50b5f73f8b..ab97f16eb8 100644 --- a/app/App.hs +++ b/app/App.hs @@ -188,6 +188,9 @@ getEntryPointStdin' RunAppIOArgs {..} = do | otherwise -> return Nothing set entryPointStdin estdin <$> entryPointFromGlobalOptionsNoFile root opts +askPackageDotJuvixPath :: (Members '[App] r) => Sem r (Path Abs File) +askPackageDotJuvixPath = mkPackagePath . (^. rootRootDir) <$> askRoot + fromRightGenericError :: (Members '[App] r, ToGenericError err, Typeable err) => Either err a -> Sem r a fromRightGenericError = fromRightJuvixError . mapLeft JuvixError diff --git a/app/Commands/Format.hs b/app/Commands/Format.hs index 55d7bab957..7242695c62 100644 --- a/app/Commands/Format.hs +++ b/app/Commands/Format.hs @@ -49,15 +49,22 @@ targetFromOptions opts = do -- | Formats the project on the root formatProject :: forall r. - (Members '[App, EmbedIO, TaggedLock, Logger, Files, Output FormattedFileInfo] r) => + (Members '[App, EmbedIO, TaggedLock, Logger, ScopeEff, Files, Output FormattedFileInfo] r) => Sem r FormatResult formatProject = silenceProgressLog . runPipelineOptions . runPipelineSetup $ do res :: [(ImportNode, PipelineResult ModuleInfo)] <- processProject - res' :: [(ImportNode, SourceCode)] <- forM res $ \(node, nfo) -> do - pkgId :: PackageId <- (^. entryPointPackageId) <$> ask - src <- runReader pkgId (formatModuleInfo node nfo) + pkgId :: PackageId <- (^. entryPointPackageId) <$> ask + res' :: [(ImportNode, SourceCode)] <- runReader pkgId $ forM res $ \(node, nfo) -> do + src <- formatModuleInfo node nfo return (node, src) - formatProjectSourceCode res' + formatRes <- formatProjectSourceCode res' + formatPkgRes <- formatPackageDotJuvix + return (formatRes <> formatPkgRes) + +formatPackageDotJuvix :: forall r. (Members '[App, Files, Logger, Output FormattedFileInfo, ScopeEff] r) => Sem r FormatResult +formatPackageDotJuvix = do + pkgDotJuvix <- askPackageDotJuvixPath + ifM (fileExists' pkgDotJuvix) (format pkgDotJuvix) (return mempty) runCommand :: forall r. (Members AppEffects r) => FormatOptions -> Sem r () runCommand opts = do diff --git a/examples/demo/Package.juvix b/examples/demo/Package.juvix index 39e428effd..c2c5c16d72 100644 --- a/examples/demo/Package.juvix +++ b/examples/demo/Package.juvix @@ -5,5 +5,5 @@ import PackageDescription.V2 open; package : Package := defaultPackage@{ name := "Demo"; - version := mkVersion 0 1 0 + version := mkVersion 0 1 0; }; diff --git a/examples/midsquare/Package.juvix b/examples/midsquare/Package.juvix index 191f097606..c42c892687 100644 --- a/examples/midsquare/Package.juvix +++ b/examples/midsquare/Package.juvix @@ -5,5 +5,5 @@ import PackageDescription.V2 open; package : Package := defaultPackage@{ name := "midsquare"; - version := mkVersion 0 1 0 + version := mkVersion 0 1 0; }; diff --git a/examples/milestone/Bank/Package.juvix b/examples/milestone/Bank/Package.juvix index 83819477c1..59d4367449 100644 --- a/examples/milestone/Bank/Package.juvix +++ b/examples/milestone/Bank/Package.juvix @@ -4,5 +4,5 @@ import PackageDescription.V2 open; package : Package := defaultPackage@{ - name := "bank" + name := "bank"; }; diff --git a/examples/milestone/Collatz/Package.juvix b/examples/milestone/Collatz/Package.juvix index 10d24fc716..412c73ee52 100644 --- a/examples/milestone/Collatz/Package.juvix +++ b/examples/milestone/Collatz/Package.juvix @@ -6,5 +6,5 @@ package : Package := defaultPackage@{ name := "Collatz"; version := mkVersion 0 1 0; - main := just "Collatz.juvix" + main := just "Collatz.juvix"; }; diff --git a/examples/milestone/Fibonacci/Package.juvix b/examples/milestone/Fibonacci/Package.juvix index 7624e50fb5..9f6702d860 100644 --- a/examples/milestone/Fibonacci/Package.juvix +++ b/examples/milestone/Fibonacci/Package.juvix @@ -6,5 +6,5 @@ package : Package := defaultPackage@{ name := "Fibonacci"; version := mkVersion 0 1 0; - main := just "Fibonacci.juvix" + main := just "Fibonacci.juvix"; }; diff --git a/examples/milestone/Hanoi/Package.juvix b/examples/milestone/Hanoi/Package.juvix index 9bb7f6f53e..f59eac7ef5 100644 --- a/examples/milestone/Hanoi/Package.juvix +++ b/examples/milestone/Hanoi/Package.juvix @@ -6,5 +6,5 @@ package : Package := defaultPackage@{ name := "Hanoi"; version := mkVersion 0 1 0; - main := just "Hanoi.juvix" + main := just "Hanoi.juvix"; }; diff --git a/examples/milestone/HelloWorld/Package.juvix b/examples/milestone/HelloWorld/Package.juvix index ec3f84f5c8..22bff8557e 100644 --- a/examples/milestone/HelloWorld/Package.juvix +++ b/examples/milestone/HelloWorld/Package.juvix @@ -6,5 +6,5 @@ package : Package := defaultPackage@{ name := "HelloWorld"; version := mkVersion 0 1 0; - main := just "HelloWorld.juvix" + main := just "HelloWorld.juvix"; }; diff --git a/examples/milestone/PascalsTriangle/Package.juvix b/examples/milestone/PascalsTriangle/Package.juvix index c6370e1474..ea7baddbf7 100644 --- a/examples/milestone/PascalsTriangle/Package.juvix +++ b/examples/milestone/PascalsTriangle/Package.juvix @@ -6,5 +6,5 @@ package : Package := defaultPackage@{ name := "PascalsTriangle"; version := mkVersion 0 1 0; - main := just "PascalsTriangle.juvix" + main := just "PascalsTriangle.juvix"; }; diff --git a/examples/milestone/TicTacToe/Package.juvix b/examples/milestone/TicTacToe/Package.juvix index edbcb64f7f..70a86b22bb 100644 --- a/examples/milestone/TicTacToe/Package.juvix +++ b/examples/milestone/TicTacToe/Package.juvix @@ -6,5 +6,5 @@ package : Package := defaultPackage@{ name := "TicTacToe"; version := mkVersion 0 1 0; - main := just "CLI/TicTacToe.juvix" + main := just "CLI/TicTacToe.juvix"; }; diff --git a/examples/milestone/Tutorial/Package.juvix b/examples/milestone/Tutorial/Package.juvix index e670c512c8..04e141d84c 100644 --- a/examples/milestone/Tutorial/Package.juvix +++ b/examples/milestone/Tutorial/Package.juvix @@ -5,5 +5,5 @@ import PackageDescription.V2 open; package : Package := defaultPackage@{ name := "Tutorial"; - version := mkVersion 0 1 0 + version := mkVersion 0 1 0; }; diff --git a/src/Juvix/Formatter.hs b/src/Juvix/Formatter.hs index e96c5b16e3..19e6fcffab 100644 --- a/src/Juvix/Formatter.hs +++ b/src/Juvix/Formatter.hs @@ -94,7 +94,7 @@ format p = do -- contents of a file) for every processed file. -- -- NB: This function does not traverse into Juvix sub-projects, i.e into --- subdirectories that contain a juvix.yaml file. +-- subdirectories that contain a Package.juvix file. formatProjectSourceCode :: forall r. (Members '[Output FormattedFileInfo] r) => @@ -178,12 +178,11 @@ formatResultSourceCode filepath src = do mkResult :: FormatResult -> Sem r FormatResult mkResult res = do output - ( FormattedFileInfo - { _formattedFileInfoPath = filepath, - _formattedFileInfoContents = src ^. sourceCodeFormatted, - _formattedFileInfoContentsModified = res == FormatResultNotFormatted - } - ) + FormattedFileInfo + { _formattedFileInfoPath = filepath, + _formattedFileInfoContents = src ^. sourceCodeFormatted, + _formattedFileInfoContentsModified = res == FormatResultNotFormatted + } return res formatScoperResult' :: diff --git a/tests/positive/Internal/Positivity2/Package.juvix b/tests/positive/Internal/Positivity2/Package.juvix index 52600bdb7c..66f492f7fa 100644 --- a/tests/positive/Internal/Positivity2/Package.juvix +++ b/tests/positive/Internal/Positivity2/Package.juvix @@ -5,5 +5,5 @@ import PackageDescription.V2 open; package : Package := defaultPackage@{ name := "positivity2"; - dependencies := [] + dependencies := []; }; diff --git a/tests/positive/PackageLoader/PackageJuvixEmptyDependencies/Package.juvix b/tests/positive/PackageLoader/PackageJuvixEmptyDependencies/Package.juvix index 8e5ddde7ca..024c37b80c 100644 --- a/tests/positive/PackageLoader/PackageJuvixEmptyDependencies/Package.juvix +++ b/tests/positive/PackageLoader/PackageJuvixEmptyDependencies/Package.juvix @@ -6,5 +6,5 @@ import PackageDescription.V1 open; package : Package := defaultPackage@{ name := "package-juvix"; - dependencies := [] + dependencies := []; }; diff --git a/tests/positive/PackageLoader/YamlEmptyDependencies/Package.juvix b/tests/positive/PackageLoader/YamlEmptyDependencies/Package.juvix index 20d310a375..0cbdc856d7 100644 --- a/tests/positive/PackageLoader/YamlEmptyDependencies/Package.juvix +++ b/tests/positive/PackageLoader/YamlEmptyDependencies/Package.juvix @@ -5,5 +5,5 @@ import PackageDescription.V1 open; package : Package := defaultPackage@{ name := "abc"; - dependencies := [] + dependencies := []; }; diff --git a/tests/positive/PackageLoaderV2/PackageJuvixEmptyDependencies/Package.juvix b/tests/positive/PackageLoaderV2/PackageJuvixEmptyDependencies/Package.juvix index 4da6bc3104..96cac83f54 100644 --- a/tests/positive/PackageLoaderV2/PackageJuvixEmptyDependencies/Package.juvix +++ b/tests/positive/PackageLoaderV2/PackageJuvixEmptyDependencies/Package.juvix @@ -5,5 +5,5 @@ import PackageDescription.V2 open; package : Package := defaultPackage@{ name := "package-juvix"; - dependencies := [] + dependencies := []; }; diff --git a/tests/positive/issue3068/Package.juvix b/tests/positive/issue3068/Package.juvix index d5fc44153a..1ef1dae07a 100644 --- a/tests/positive/issue3068/Package.juvix +++ b/tests/positive/issue3068/Package.juvix @@ -5,5 +5,5 @@ import PackageDescription.V2 open; package : Package := defaultPackage@{ name := "issue3068"; - dependencies := [] + dependencies := []; }; diff --git a/tests/smoke/Commands/format.smoke.yaml b/tests/smoke/Commands/format.smoke.yaml index 1f604f29a1..61fc9e407f 100644 --- a/tests/smoke/Commands/format.smoke.yaml +++ b/tests/smoke/Commands/format.smoke.yaml @@ -168,6 +168,22 @@ tests: stderr: '' exit-status: 1 + - name: format-project-package-dot-juvix + command: + shell: + - bash + script: | + temp=$(mktemp -d) + trap 'rm -rf -- "$temp"' EXIT + cd $temp + juvix init + echo "" >> Package.juvix + juvix format + stderr: '' + stdout: + contains: 'Package.juvix' + exit-status: 1 + - name: format-project-containing-unformatted-from-subdir command: shell: