diff --git a/src/Nixfmt/Predoc.hs b/src/Nixfmt/Predoc.hs index f3b59011..51d06d5e 100644 --- a/src/Nixfmt/Predoc.hs +++ b/src/Nixfmt/Predoc.hs @@ -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] diff --git a/src/Nixfmt/Pretty.hs b/src/Nixfmt/Pretty.hs index 8ca03ac0..7f327288 100644 --- a/src/Nixfmt/Pretty.hs +++ b/src/Nixfmt/Pretty.hs @@ -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 @@ -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, @@ -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 -- `...`