Skip to content

Feature request: support multiline comments in indented contexts #65

@brandon-leapyear

Description

@brandon-leapyear

Related to #63

This PR solves the above issue by fixing a bug in detecting whether a comment is indented or not. When this bug is fixed, fourmolu will always use single line comments for indented haddocks, e.g.

class Foo a where
  -- | asdf
  -- asdf
  foo :: a

{-| asdf
    asdf
-}
bar :: Int

It would be nice if these haddocks could use the same style as non-indented functions, e.g.

class Foo a where
  {-| asdf
     asdf
  -}
  foo :: a

{-| asdf
    asdf
-}
bar :: Int

This seems to mostly be a one-line change:

    getPrinterOpt poHaddockStyle >>= \case
      HaddockSingleLine -> pure True
-     -- Use multiple single-line comments when the whole comment is indented
-     HaddockMultiLine -> maybe False ((> 1) . srcSpanStartCol) <$> getSrcSpan l
+     HaddockMultiLine -> pure False

but this fails when checking if the AST is the same as before, because of whitespace differences in the comment, e.g.

-- from
HsDocString " A multiline\n comment here"

-- to
HsDocString " A multiline\n   comment here\n  "

One possible solution is to also trim leading whitespace when doing the AST check (but not when printing out the haddock in p_hsDocString)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions