Skip to content

Commit

Permalink
Fix indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
piegamesde committed Feb 25, 2024
1 parent ae62a6a commit 571ed81
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/Nixfmt/Predoc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,15 @@ layoutGreedy tw doc = Text.concat $ evalState (go [Group RegularG doc] []) (0, [
else
go' indents (ci + textOffset)
-- Does not need indent (not at start of line)
(cc, indents) ->
-- Update the current CI→VI mapping, since the *last* token on the line
-- decides the indent for the next line
(cc, (ci, vi):indents) | textVI < vi ->
put (cc + textWidth t, indents) $> [t]
(cc, (ci, vi):indents) | textVI > vi ->
put (cc + textWidth t, (ci, textVI):(ci, vi):indents) $> [t]
(cc, (ci, vi):indents) ->
put (cc + textWidth t, (ci, textVI):indents) $> [t]
(_, _) -> error "unreachable, since indents is guaranteed to not be empty as invariant"
where
-- Start a new line
go' indents i = put (textWidth t, indents) $> [indent i, t]
Expand Down
6 changes: 3 additions & 3 deletions src/Nixfmt/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ instance Pretty Trivium where
| otherwise
= comment "/*" <> hardspace
-- Add an offset to manually indent the comment by one
<> (nest $ offset 1 $ hcat $ map prettyCommentLine c)
<> (offset 3 $ hcat $ map prettyCommentLine c)
<> comment "*/" <> hardline
where
prettyCommentLine :: Text -> Doc
Expand Down Expand Up @@ -120,7 +120,7 @@ instance Pretty Binder where
-- `foo = bar`
pretty (Assignment selectors assign expr semicolon)
= group $ hcat selectors
<> nest (hardspace <> pretty assign <> absorbRHS expr) <> pretty semicolon
<> nest (hardspace <> pretty assign <> nest (absorbRHS expr)) <> pretty semicolon

-- Pretty a set
-- while we already pretty eagerly expand sets with more than one element,
Expand Down Expand Up @@ -204,7 +204,7 @@ instance Pretty ParamAttr where
pretty (ParamAttr name (Just (qmark, def)) maybeComma)
= group $
pretty name <> hardspace
<> nest (pretty qmark <> absorbRHS def)
<> nest (pretty qmark <> nest (absorbRHS def))
<> pretty maybeComma

-- `...`
Expand Down

0 comments on commit 571ed81

Please sign in to comment.