Skip to content

Fix regression with multiline record types#160

Merged
brandonchinn178 merged 2 commits intomasterfrom
multiline-deindent
Apr 4, 2022
Merged

Fix regression with multiline record types#160
brandonchinn178 merged 2 commits intomasterfrom
multiline-deindent

Conversation

@brandonchinn178
Copy link
Copy Markdown
Collaborator

@brandonchinn178 brandonchinn178 commented Mar 16, 2022

Partially revert #124 (specifically, the removal of sitcc) to fix #145

Completely separate from whether it looks better or not, that change actually causes inconsistencies with different options. Some examples are below. TL;DR we should revert this for now to fix the inconsistencies, then we can make the trailing comment indentation configurable for aesthetic reasons

Record field inconsistencies

With --indentation=4, --comma-style=trailing and --comma-style=leading will indent the two comments differently:

$ stack exec -- fourmolu --indentation=4 --comma-style=trailing test.hs
newtype App a = App
    { unApp ::
        JobExecutorT
            ( ReaderT
                MyConfig
                (LoggingT IO)
            )
            a,
      -- | asfd
      a :: Int,
      -- | asdf
      b :: Bool
    }

$ stack exec -- fourmolu --indentation=4 --comma-style=leading test.hs
newtype App a = App
    { unApp ::
        JobExecutorT
            ( ReaderT
                MyConfig
                (LoggingT IO)
            )
            a
    , a :: Int
    -- ^ asfd
    , b :: Bool
    -- ^ asdf
    }

But in addition to this, using --indentation=2, it also causes multiline types to be deindented (note JobExecutorT being deindented after unApp with --comma-style=leading):

$ stack exec -- fourmolu --indentation=2 --comma-style=trailing test.hs
newtype App a = App
  { unApp ::
      JobExecutorT
        ( ReaderT
            MyConfig
            (LoggingT IO)
        )
        a,
    -- | asfd
    a :: Int,
    -- | asdf
    b :: Bool
  }

$ stack exec -- fourmolu --indentation=2 --comma-style=leading test.hs
newtype App a = App
  { unApp ::
    JobExecutorT
      ( ReaderT
          MyConfig
          (LoggingT IO)
      )
      a
  , a :: Int
  -- ^ asfd
  , b :: Bool
  -- ^ asdf
  }

@brandonchinn178
Copy link
Copy Markdown
Collaborator Author

@georgefst it would be great to merge this + release 0.5.1 to fix the regression quickly

@georgefst
Copy link
Copy Markdown
Collaborator

I'm reluctant to merge this as-is, since unfortunately while it fixes one regression, in a sense it introduces a new one. I, for one, am already using Fourmolu 0.5 and would rather avoid the churn that this would entail. I also don't quite understand all of your concerns, so I could do with a little explanation.

With --indentation=4, --comma-style=trailing and --comma-style=leading will indent the two comments differently:

I don't really see why this is an issue? Why should different options be consistent in this way?

But in addition to this, using --indentation=2, it also causes multiline types to be deindented

That certainly is problematic.

I haven't tested this extensively, but I think we can keep the best of both worlds if we hack in an indentation decrease by changing line 279 to:

mapM_ (inciBy (-2) . (newline >>) . p_hsDocString Caret False) cd_fld_doc

It also shows up with multiline tuples:

I'm unsure what I'm supposed to be looking at here. I think the first output is a bit ugly, but that isn't affected by removing or re-adding sitcc.

@brandonchinn178
Copy link
Copy Markdown
Collaborator Author

With --indentation=4, --comma-style=trailing and --comma-style=leading will indent the two comments differently:

I don't really see why this is an issue? Why should different options be consistent in this way?

I guess, personally, I would expect that the comments, regardless of being -- | or -- ^, should always be either at the same indentation level as the initial { or indented past {. But I guess I do recognize this is more on the subjective end, so I won't push much more here.

But in addition to this, using --indentation=2, it also causes multiline types to be deindented

That certainly is problematic.

I haven't tested this extensively, but I think we can keep the best of both worlds if we hack in an indentation decrease by changing line 279 to:

mapM_ (inciBy (-2) . (newline >>) . p_hsDocString Caret False) cd_fld_doc

I can try that

It also shows up with multiline tuples:

I'm unsure what I'm supposed to be looking at here. I think the first output is a bit ugly, but that isn't affected by removing or re-adding sitcc.

If you look at the first example, the do block is not indented in the second element of the tuple. it's indented in every other example

@georgefst
Copy link
Copy Markdown
Collaborator

If you look at the first example, the do block is not indented in the second element of the tuple. it's indented in every other example

Sure, but this output isn't affected by the changes in #124. It appears to be a separate issue. Is it a regression? If so, we should try to bisect.

@brandonchinn178
Copy link
Copy Markdown
Collaborator Author

ah you're right... i'm not sure why i connected that issue to this. i'll move that discussion to a separate branch

@brandonchinn178
Copy link
Copy Markdown
Collaborator Author

@georgefst Fixed! Tested that the below does not reformat with --indentation=2 --comma-style=leading

newtype App a = App
  { unApp ::
      JobExecutorT
        ( ReaderT
            MyConfig
            (LoggingT IO)
        )
        a
  , a :: Int
  -- ^ asfd
  , b :: Bool
  -- ^ asdf
  }

I didn't add this as a test yet, because I'm not sure what we want to do about testing (did you get my latest email?). I'm personally of the mindset that data/examples/ should ONLY contain ormolu test cases, and any test cases fourmolu adds should be in a separate directory like data/examples-fourmolu/, to make it clear what tests are upstream and what tests we added.

@brandonchinn178 brandonchinn178 changed the title Fix regression with multiline expressions Fix regression with multiline record types Apr 4, 2022
@brandonchinn178
Copy link
Copy Markdown
Collaborator Author

@georgefst Thanks! I'll be making a release shortly

@brandonchinn178 brandonchinn178 merged commit 45d1b8d into master Apr 4, 2022
@brandonchinn178 brandonchinn178 deleted the multiline-deindent branch April 4, 2022 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression: fourmolu-0.5.0.0 deindents multiline types in record fields

2 participants