fourmolu icon indicating copy to clipboard operation
fourmolu copied to clipboard

Converting multiline haddock module description with markup creates parse error

Open agentultra opened this issue 3 years ago • 3 comments

Is your feature request specific to Fourmolu?

  • [x] Yes, this feature is not relevant to Ormolu

Describe the current + desired formatting

{-|
This example
@
  test
@
-}

Gets translated to

-- |
--This example
--@
--  test
--@

Which will result in a parse error on --@

I'd recommend it translate to

-- |
-- This example
-- @
--  test
-- @

agentultra avatar Jul 08 '22 21:07 agentultra

Thanks for the report! @georgefst, curious what your thoughts are on this. On one hand, it's been bothering me for a while that

-- | a
-- multiline
-- comment

gets converted into

{- | a
 multiline
 comment
-}

with leading spaces, since with single line -- comment style, I don't think of the leading space as part of the comment, but as part of the syntax. But I also get that the GHC parser parses the space as part of the comment content, and we probably don't want to modify what GHC parsed.

brandonchinn178 avatar Jul 09 '22 03:07 brandonchinn178

On one hand, it's been bothering me for a while that

Yeah, it annoys me too. I think we can and should fix it.

But I also get that the GHC parser parses the space as part of the comment content, and we probably don't want to modify what GHC parsed.

I'm pretty sure we already have some sort of ignoreASTChange function somewhere (inherited from Ormolu) for special cases where we know we're technically changing the AST, but nobody's likely to care.

georgefst avatar Jul 10 '22 21:07 georgefst

As for this issue, I think inserting a leading space on all lines (when there isn't one already) would be totally reasonable. Especially since #120.

georgefst avatar Jul 10 '22 21:07 georgefst