Skip to content

Commit

Permalink
Merge pull request #4671 from unisonweb/cp/format-handlers
Browse files Browse the repository at this point in the history
Fix formatting on handle-with blocks
  • Loading branch information
aryairani committed Feb 6, 2024
2 parents 6f67452 + 4da9d12 commit 4f345fe
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
9 changes: 6 additions & 3 deletions parser-typechecker/src/Unison/Syntax/TermParser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,12 @@ lam p = label "lambda" $ mkLam <$> P.try (some prefixDefinitionName <* reserved
letBlock, handle, ifthen :: (Monad m, Var v) => TermP v m
letBlock = label "let" $ (snd <$> block "let")
handle = label "handle" do
(_spanAnn, b) <- block "handle"
(_spanAnn, handler) <- block "with"
pure $ Term.handle (ann b) handler b
(handleSpan, b) <- block "handle"
(_withSpan, handler) <- block "with"
-- We don't use the annotation span from 'with' here because it will
-- include a dedent if it's at the end of block.
-- Meaning the newline gets overwritten when pretty-printing and it messes things up.
pure $ Term.handle (handleSpan <> ann handler) handler b

checkCasesArities :: (Ord v, Annotated a) => NonEmpty (Int, a) -> P v m (Int, NonEmpty a)
checkCasesArities cases@((i, _) NonEmpty.:| rest) =
Expand Down
13 changes: 13 additions & 0 deletions unison-src/transcripts/formatter.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ ability Thing where
more : Nat -> Text -> Nat
doThing : Nat -> Int
{{ Ability with single constructor }}
structural ability Ask a where
ask : {Ask a} a
-- Regression test for: https://github.com/unisonweb/unison/issues/4666
provide : a -> '{Ask a} r -> r
provide a action =
h = cases
{ask -> resume} -> handle resume a with h
{r} -> r
handle !action with h
{{
A Doc before a type
}}
Expand Down
25 changes: 25 additions & 0 deletions unison-src/transcripts/formatter.output.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ ability Thing where
more : Nat -> Text -> Nat
doThing : Nat -> Int
{{ Ability with single constructor }}
structural ability Ask a where
ask : {Ask a} a
-- Regression test for: https://github.com/unisonweb/unison/issues/4666
provide : a -> '{Ask a} r -> r
provide a action =
h = cases
{ask -> resume} -> handle resume a with h
{r} -> r
handle !action with h
{{
A Doc before a type
}}
Expand Down Expand Up @@ -101,6 +114,18 @@ ability Thing where
more : Nat -> Text ->{Thing} Nat
doThing : Nat ->{Thing} Int
Ask.doc = {{ Ability with single constructor }}
structural ability Ask a where ask : {Ask a} a
-- Regression test for: https://github.com/unisonweb/unison/issues/4666
provide : a -> '{Ask a} r -> r
provide a action =
h = cases
{ ask -> resume } -> handle resume a with h
{ r } -> r
handle !action with h
Optional.doc = {{ A Doc before a type }}
structural type Optional a = More Text | Some | Other a | None Nat
Expand Down

0 comments on commit 4f345fe

Please sign in to comment.