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

Inline comment after last data constructor disapearing fixed #427

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/Language/Haskell/Stylish/Step/Data.hs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,10 @@ step cfg = makeStep "Data" \ls m -> Editor.apply (changes m) ls
ldecl <- GHC.hsmodDecls $ GHC.unLoc m
GHC.TyClD _ tycld <- pure $ GHC.unLoc ldecl
loc <- maybeToList $ GHC.srcSpanToRealSrcSpan $ GHC.getLocA ldecl
let lastInlineComment = GHC.ann $ GHC.getLoc ldecl
case tycld of
GHC.DataDecl {..} -> pure $ MkDataDecl
{ dataComments = epAnnComments tcdDExt
{ dataComments = epAnnComments lastInlineComment <> epAnnComments tcdDExt
, dataLoc = loc
, dataDeclName = tcdLName
, dataTypeVars = tcdTyVars
Expand Down
19 changes: 19 additions & 0 deletions tests/Language/Haskell/Stylish/Step/Data/Tests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ tests = testGroup "Language.Haskell.Stylish.Step.Data.Tests"
, testCase "case 64" case64
, testCase "case 65" case65
, testCase "case 66 (issue #411)" case66
, testCase "case 67 (issue #425)" case67
]

case00 :: Assertion
Expand Down Expand Up @@ -1381,6 +1382,24 @@ case66 = assertSnippet (step indentIndentStyle) input input
, " deriving (Eq, Show)"
]

-- | Inline comment after the last record field
--
-- Regression test for https://github.com/haskell/stylish-haskell/issues/425
case67 :: Assertion
case67 = assertSnippet (step indentIndentStyle) input input
where
input =
[ "data Foo"
, " = Foo -- ^ foo"
, " | Bar -- ^ bar"
, " | Baz -- ^ baz"
, ""
, "data Foo'"
, " = Foo' Int -- ^ foo"
, " | Bar' Int -- ^ bar"
, " | Baz' Int -- ^ baz"
]

sameSameStyle :: Config
sameSameStyle = Config SameLine SameLine 2 2 False True SameLine False True NoMaxColumns

Expand Down