Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ormolu drops a Haddock section header in module export #901

Open
ocharles opened this issue Jun 22, 2022 · 6 comments
Open

Ormolu drops a Haddock section header in module export #901

ocharles opened this issue Jun 22, 2022 · 6 comments
Labels
bug-upstream Something upstream is not working.

Comments

@ocharles
Copy link

Describe the bug

The following code

module Beckhoff.ADS
  ( -- $intro
    -- * Connections
    ConnectInfo(..)
  ) where

becomes

module Beckhoff.ADS
  ( -- $intro
    ConnectInfo (..),
  )
where

Note that * Connections is no longer in the result.

To Reproduce
Try formatting the "before" code in https://ormolu-live.tweag.io/.

Expected behavior
Both $intro and * Connections are present in the formatted result.

Environment
Ormolu live

@ocharles
Copy link
Author

I note that

module Beckhoff.ADS
  ( -- $intro

    -- * Connections
    ConnectInfo(..)
  ) where

works, so I do have a workaround.

@mrkkrp mrkkrp added the bug Something isn't working label Jun 23, 2022
@amesgen
Copy link
Member

amesgen commented Jun 23, 2022

Hmm, I think that Ormolu's output is actually "Haddock-preserving" here.

Consider these rendered Haddock outputs

Source Rendered Haddock
module MyLib
  ( -- $intro
    -- * Connections
    Foo (..)
  ) where

data Foo = Foo

and

module MyLib
  ( -- $intro
    Foo (..)
  ) where

data Foo = Foo

2022-06-23_16-43

module MyLib
  ( -- $intro

    -- * Foo
    Foo (..)
  ) where

data Foo = Foo

2022-06-23_16-45

So while I agree it is surprising, maybe Ormolu's behavior is actually helpful as it only mirrors the Haddock behavior of removing everything after -- $intro in the same comment?

@ocharles
Copy link
Author

Ah, interesting. That said, I do find Ormolu makes it easy to now just lose the comment entirely if you're not careful reading the diff

@amesgen
Copy link
Member

amesgen commented Jun 25, 2022

That said, I do find Ormolu makes it easy to now just lose the comment entirely if you're not careful reading the diff

Agreed; so we basically have two options:

  • Consider this to be an upstream (Haddock/GHC parser) issue.

  • Change our approach to format Haddock snippets.

    Right now, Haddock comments occur in two places in the GHC AST:

    1. In the list of "ordinary" comments, e.g.
      (L
       (Anchor
        { <input>:(2,5)-(3,20) }
        (UnchangedAnchor))
       (EpaComment
        (EpaDocCommentNamed
         "intro\n * Connections")
        { <input>:2:3 }))       
    2. As a special AST construct, e.g.
      (L
       (SrcSpanAnn (EpAnnNotUsed) { <input>:(2,5)-(3,20) })
       (IEDocNamed
        (NoExtField)
        "intro"))

    Right now, Ormolu uses the second way to print Haddock constructs, so this would require changing our way of formatting Haddock comments.

@mrkkrp mrkkrp self-assigned this Feb 22, 2023
@mrkkrp mrkkrp added this to the 0.5.4.0 milestone Feb 22, 2023
@mrkkrp
Copy link
Member

mrkkrp commented Feb 22, 2023

All that said, this looks fishy to me. It is true that in the original input -- * Connections is not a valid Haddock according to GHC, but I think we must be missing something in Ormolu when we print ordinary multiline comments, because the beginning of such a comment -- $intro is printed, but its continuation * Connections is not. I'm going to look into this.

@mrkkrp mrkkrp added bug-upstream Something upstream is not working. and removed bug Something isn't working labels Feb 22, 2023
@mrkkrp mrkkrp removed this from the 0.5.4.0 milestone Feb 22, 2023
@mrkkrp mrkkrp removed their assignment Feb 22, 2023
@mrkkrp
Copy link
Member

mrkkrp commented Feb 22, 2023

Okay, now I see what @amesgen meant. Somewhat surprisingly -- $intro ends up in two different places, as a Haddock and as an annotation. We use the first but in there it is truncated and does not include -- * Connections. I reported this issue upstream: https://gitlab.haskell.org/ghc/ghc/-/issues/23028.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug-upstream Something upstream is not working.
Projects
None yet
Development

No branches or pull requests

3 participants