Skip to content

Commit

Permalink
Fix extra whitespace in text rendering of indented empty lines
Browse files Browse the repository at this point in the history
The prettyprinter library takes care avoid adding whitespace to empty
lines when it is rendering indented text.

See:

https://github.com/quchen/prettyprinter/blob/7e32c010ecfaa510c0cbf6ffea04bc7db95d4fcb/prettyprinter/src/Prettyprinter/Internal.hs#L1999

However it only does this for unannotated text.

In our code we were stripping annotations from renderings using
`toTextStream` but we must remove the annotations before calling
`layoutPretty`. That's what this commit does.
  • Loading branch information
paulcadman authored and jonaprieto committed May 19, 2023
1 parent a164083 commit e5e70f1
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/Commands/Dev/Geb/Repl/Format.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ instance HasAnsiBackend ReplMessageDoc where

instance HasTextBackend ReplMessageDoc where
toTextDoc (ReplMessageDoc o) = unAnnotate o
toTextStream (ReplMessageDoc o) = unAnnotateS (layoutPretty defaultLayoutOptions o)
toTextStream (ReplMessageDoc o) = layoutPretty defaultLayoutOptions (unAnnotate o)

stylize :: ReplStyle -> AnsiStyle
stylize = \case
Expand Down
2 changes: 1 addition & 1 deletion src/Juvix/Data/PPOutput.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ instance HasAnsiBackend PPOutput where

instance HasTextBackend PPOutput where
toTextDoc (PPOutput o) = unAnnotate o
toTextStream (PPOutput o) = unAnnotateS (layoutPretty defaultLayoutOptions o)
toTextStream (PPOutput o) = layoutPretty defaultLayoutOptions (unAnnotate o)

ppOutput :: Doc Ann -> AnsiText
ppOutput = AnsiText . PPOutput
2 changes: 1 addition & 1 deletion src/Juvix/Prelude/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ instance HasAnsiBackend AnsiText where

instance HasTextBackend (Doc a) where
toTextDoc = unAnnotate
toTextStream = unAnnotateS . layoutPretty defaultLayoutOptions
toTextStream = layoutPretty defaultLayoutOptions . unAnnotate

instance HasAnsiBackend (Doc Ansi.AnsiStyle) where
toAnsiDoc = id
Expand Down
2 changes: 1 addition & 1 deletion tests/positive/Format.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ module Patterns;
infixr 4 ,;
type × (A : Type) (B : Type) :=
| , : A → B → A × B;

f : Nat × Nat × Nat × Nat -> Nat;
f (a, b, c, d) := a;
end;
Expand Down

0 comments on commit e5e70f1

Please sign in to comment.