Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update file walker to use Package.juvix to detect a Juvix package #2502

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ mkPackageInfo mpackageEntry _packageRoot pkg = do
return PackageInfo {..}
where
juvixAccum :: Path Abs Dir -> [Path Rel Dir] -> [Path Rel File] -> [Path Abs File] -> Sem r ([Path Abs File], Recurse Rel)
juvixAccum cd _ files acc = return (newJuvixFiles <> acc, RecurseFilter (\hasJuvixYaml d -> not hasJuvixYaml && not (isHiddenDirectory d)))
juvixAccum cd _ files acc = return (newJuvixFiles <> acc, RecurseFilter (\hasJuvixPackage d -> not hasJuvixPackage && not (isHiddenDirectory d)))
where
newJuvixFiles :: [Path Abs File]
newJuvixFiles = [cd <//> f | f <- files, isJuvixFile f]
Expand Down
10 changes: 8 additions & 2 deletions src/Juvix/Data/Effect/Files.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,14 @@ walkDirRel handler topdir = do
where
filterSubdirs :: Path Rel Dir -> Sem (State (HashSet Uid) ': r) Bool
filterSubdirs d = do
hasJuvixYaml <- fileExists' (topdir <//> curdir <//> d <//> juvixYamlFile)
return (fi hasJuvixYaml d)
hasJuvixPackage <-
orM
( fileExists' . (rootDir <//>) <$> [juvixYamlFile, packageFilePath]
)
return (fi hasJuvixPackage d)
where
rootDir :: Path Abs Dir
rootDir = topdir <//> curdir <//> d

checkLoop :: Path Abs Dir -> Sem (State (HashSet Uid) ': r) Bool
checkLoop dir = do
Expand Down
2 changes: 1 addition & 1 deletion src/Juvix/Formatter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ formatProject p = do
handler cd _ files res = do
let juvixFiles = [cd <//> f | f <- files, isJuvixFile f]
subRes <- mconcat <$> mapM format juvixFiles
return (res <> subRes, RecurseFilter (\hasJuvixYaml d -> not hasJuvixYaml && not (isHiddenDirectory d)))
return (res <> subRes, RecurseFilter (\hasJuvixPackage d -> not hasJuvixPackage && not (isHiddenDirectory d)))

formatPath ::
(Members '[Reader Text, ScopeEff] r) =>
Expand Down
20 changes: 20 additions & 0 deletions tests/smoke/Commands/format.smoke.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,26 @@ tests:
stdout: ''
exit-status: 0

- name: format-ignore-subproject-project-juvix
command:
shell:
- bash
script: |
temp=$(mktemp -d)
trap 'rm -rf -- "$temp"' EXIT
pushd $temp > /dev/null
juvix init -n
popd > /dev/null
cp positive/Format.juvix $temp
mkdir $temp/sub
pushd $temp/sub > /dev/null
juvix init -n
popd > /dev/null
cp positive/Format.juvix $temp/sub
juvix format $temp
stdout: ''
exit-status: 0

- name: format-dir-containing-unformatted-check-no-stdout
command:
shell:
Expand Down