Skip to content

Commit 4f345fe

Browse files
authored
Merge pull request #4671 from unisonweb/cp/format-handlers
Fix formatting on handle-with blocks
2 parents 6f67452 + 4da9d12 commit 4f345fe

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

parser-typechecker/src/Unison/Syntax/TermParser.hs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,9 +352,12 @@ lam p = label "lambda" $ mkLam <$> P.try (some prefixDefinitionName <* reserved
352352
letBlock, handle, ifthen :: (Monad m, Var v) => TermP v m
353353
letBlock = label "let" $ (snd <$> block "let")
354354
handle = label "handle" do
355-
(_spanAnn, b) <- block "handle"
356-
(_spanAnn, handler) <- block "with"
357-
pure $ Term.handle (ann b) handler b
355+
(handleSpan, b) <- block "handle"
356+
(_withSpan, handler) <- block "with"
357+
-- We don't use the annotation span from 'with' here because it will
358+
-- include a dedent if it's at the end of block.
359+
-- Meaning the newline gets overwritten when pretty-printing and it messes things up.
360+
pure $ Term.handle (handleSpan <> ann handler) handler b
358361

359362
checkCasesArities :: (Ord v, Annotated a) => NonEmpty (Int, a) -> P v m (Int, NonEmpty a)
360363
checkCasesArities cases@((i, _) NonEmpty.:| rest) =

unison-src/transcripts/formatter.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,19 @@ ability Thing where
3838
more : Nat -> Text -> Nat
3939
doThing : Nat -> Int
4040
41+
42+
{{ Ability with single constructor }}
43+
structural ability Ask a where
44+
ask : {Ask a} a
45+
46+
-- Regression test for: https://github.com/unisonweb/unison/issues/4666
47+
provide : a -> '{Ask a} r -> r
48+
provide a action =
49+
h = cases
50+
{ask -> resume} -> handle resume a with h
51+
{r} -> r
52+
handle !action with h
53+
4154
{{
4255
A Doc before a type
4356
}}

unison-src/transcripts/formatter.output.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,19 @@ ability Thing where
3434
more : Nat -> Text -> Nat
3535
doThing : Nat -> Int
3636
37+
38+
{{ Ability with single constructor }}
39+
structural ability Ask a where
40+
ask : {Ask a} a
41+
42+
-- Regression test for: https://github.com/unisonweb/unison/issues/4666
43+
provide : a -> '{Ask a} r -> r
44+
provide a action =
45+
h = cases
46+
{ask -> resume} -> handle resume a with h
47+
{r} -> r
48+
handle !action with h
49+
3750
{{
3851
A Doc before a type
3952
}}
@@ -101,6 +114,18 @@ ability Thing where
101114
more : Nat -> Text ->{Thing} Nat
102115
doThing : Nat ->{Thing} Int
103116
117+
118+
Ask.doc = {{ Ability with single constructor }}
119+
structural ability Ask a where ask : {Ask a} a
120+
121+
-- Regression test for: https://github.com/unisonweb/unison/issues/4666
122+
provide : a -> '{Ask a} r -> r
123+
provide a action =
124+
h = cases
125+
{ ask -> resume } -> handle resume a with h
126+
{ r } -> r
127+
handle !action with h
128+
104129
Optional.doc = {{ A Doc before a type }}
105130
structural type Optional a = More Text | Some | Other a | None Nat
106131

0 commit comments

Comments
 (0)