Fix another case of non-idempotence with inline comments

This commit is contained in:
Mark Karpov 2020-05-14 12:29:29 +02:00
parent 76c4f523d7
commit b0092e11a1
6 changed files with 27 additions and 9 deletions

View File

@ -0,0 +1,12 @@
showPs env ((n, _, Let _ t v) : bs) =
" " ++ show n ++ " : "
++ showEnv env ({- normalise ctxt env -} t)
++ " = "
++ showEnv env ({- normalise ctxt env -} v)
++ "\n"
++ showPs env bs
showPs env ((n, _, b) : bs) =
" " ++ show n ++ " : "
++ showEnv env ({- normalise ctxt env -} (binderTy b))
++ "\n"
++ showPs env bs

View File

@ -0,0 +1,9 @@
showPs env ((n, _, Let _ t v):bs)
= " " ++ show n ++ " : " ++
showEnv env ({- normalise ctxt env -} t) ++ " = " ++
showEnv env ({- normalise ctxt env -} v) ++
"\n" ++ showPs env bs
showPs env ((n, _, b):bs)
= " " ++ show n ++ " : " ++
showEnv env ({- normalise ctxt env -} (binderTy b)) ++
"\n" ++ showPs env bs

View File

@ -4,12 +4,6 @@ Formatting is not idempotent:
after: "t_impl ppo\n "
Please, consider reporting the bug.
Formatting is not idempotent:
src/Idris/Core/ProofState.hs<rendered>:163:20
before: "++ showEnv env (\n "
after: "++ showEnv\n "
Please, consider reporting the bug.
Formatting is not idempotent:
src/Idris/Core/TT.hs<rendered>:1963:13
before: " text op <> pretty"

View File

@ -14,6 +14,7 @@ where
import Control.Monad
import qualified Data.List.NonEmpty as NE
import Data.Maybe (listToMaybe)
import qualified Data.Text as T
import Ormolu.Parser.CommentStream
import Ormolu.Printer.Internal
@ -66,9 +67,11 @@ spitPrecedingComment ref = do
let p (L l _) = realSrcSpanEnd l <= realSrcSpanStart ref
withPoppedComment p $ \l comment -> do
lineSpans <- thisLineSpans
let ls = srcLocLine . realSrcSpanEnd <$> lineSpans
thisCommentLine = srcLocLine (realSrcSpanStart l)
needsNewline = any (/= thisCommentLine) ls
let thisCommentLine = srcLocLine (realSrcSpanStart l)
needsNewline =
case listToMaybe lineSpans of
Nothing -> False
Just spn -> srcLocLine (realSrcSpanEnd spn) /= thisCommentLine
when (needsNewline || needsNewlineBefore l mlastMark) newline
spitCommentNow l comment
if theSameLinePre l ref