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

Fix format on projects that contain subprojects #2078

Merged
merged 2 commits into from
May 10, 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 @@ -90,7 +90,7 @@ mkPackageInfo mpackageEntry _packageRoot = 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 (\hasJuvixYaml d -> not hasJuvixYaml && not (isHiddenDirectory d)))
where
newJuvixFiles :: [Path Abs File]
newJuvixFiles = [cd <//> f | f <- files, isJuvixFile f]
Expand Down
13 changes: 9 additions & 4 deletions src/Juvix/Data/Effect/Files.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,18 @@ walkDirRel handler topdir = do
walktree curdir = do
let fullDir :: Path Abs Dir = topdir <//> curdir
(subdirs, files) <- listDirRel fullDir
let hasJuvixYaml = juvixYamlFile `elem` files
action <- raise (handler fullDir subdirs files)
case action of
RecurseNever -> return ()
RecurseFilter fi ->
let ds = map (curdir <//>) (filter (fi hasJuvixYaml) subdirs)
in mapM_ walkAvoidLoop ds
RecurseFilter fi -> do
ds <- filterM filterSubdirs subdirs
mapM_ (walkAvoidLoop . (curdir <//>)) ds
where
filterSubdirs :: Path Rel Dir -> Sem (State (HashSet Uid) ': r) Bool
filterSubdirs d = do
hasJuvixYaml <- fileExists' (topdir <//> curdir <//> d <//> juvixYamlFile)
return (fi hasJuvixYaml d)

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

formatPath :: Member ScopeEff r => Path Abs File -> Sem r (NonEmpty AnsiText)
formatPath p = do
Expand Down
16 changes: 16 additions & 0 deletions tests/smoke/Commands/format.smoke.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,22 @@ tests:
contains: 'Foo.juvix'
exit-status: 1

- name: format-ignore-subproject
command:
shell:
- bash
script: |
temp=$(mktemp -d)
trap 'rm -rf -- "$temp"' EXIT
touch $temp/juvix.yaml
cp positive/Format.juvix $temp
mkdir $temp/sub
touch $temp/sub/juvix.yaml
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