Skip to content

Commit 75647a6

Browse files
committed
Fix trailing docs with balanceComments
1 parent 2f8af6c commit 75647a6

3 files changed

Lines changed: 32 additions & 9 deletions

File tree

plugins/hls-refactor-plugin/src/Development/IDE/Plugin/CodeAction.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -608,9 +608,10 @@ suggestDeleteUnusedBinding
608608
in ([("Delete ‘" <> name <> "", edits) | not (null edits)])
609609
| otherwise = []
610610
where
611-
hsmodSigs = [L l sig | L l (SigD _ sig) <- hsmodDecls]
611+
hsmodDeclsWithDocs = balanceCommentsList hsmodDecls
612+
hsmodSigs = [L l sig | L l (SigD _ sig) <- hsmodDeclsWithDocs]
612613
relatedRanges indexedContent name =
613-
concatMap (findRelatedSpans indexedContent name . reLoc) hsmodDecls
614+
concatMap (findRelatedSpans indexedContent name . reLoc) hsmodDeclsWithDocs
614615
toRange = realSrcSpanToRange
615616
extendForSpaces = extendToIncludePreviousNewlineIfPossible
616617

plugins/hls-refactor-plugin/src/Development/IDE/Plugin/CodeAction/ExactPrint.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ module Development.IDE.Plugin.CodeAction.ExactPrint (
1313
hideSymbol,
1414
liftParseAST,
1515

16-
wildCardSymbol
16+
wildCardSymbol,
17+
18+
-- * Re-exports
19+
balanceCommentsList,
1720
) where
1821

1922
import Control.Monad

plugins/hls-refactor-plugin/test/Main.hs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2534,21 +2534,40 @@ deleteUnusedDefinitionTests = testGroup "delete unused definition action"
25342534
, "some = ()"
25352535
]
25362536
, knownBrokenForGhcVersions [GHC96, GHC98] "Not implemented for GHC <9.10 (AST changed)" $
2537-
testSession "delete unused top level binding with Haddock comment" $
2537+
testSession "delete unused leading top level binding with Haddock comment" $
25382538
testFor
25392539
[ "{-# OPTIONS_GHC -Wunused-top-binds #-}"
25402540
, "module A (some) where"
25412541
, ""
2542-
, "-- | line docs for f"
2543-
, "f :: Int"
2544-
-- TODO: , "-- ^ trailing docs for f"
2545-
, "f = 1"
2542+
, "-- | line docs for foo"
2543+
, "foo :: Int"
2544+
, "foo = 1"
25462545
, ""
25472546
, "some = ()"
25482547
]
25492548
(5, 0)
25502549
1
2551-
"Delete ‘f’"
2550+
"Delete ‘foo’"
2551+
[ "{-# OPTIONS_GHC -Wunused-top-binds #-}"
2552+
, "module A (some) where"
2553+
, ""
2554+
, "some = ()"
2555+
]
2556+
, knownBrokenForGhcVersions [GHC96, GHC98] "Not implemented for GHC <9.10 (AST changed)" $
2557+
testSession "delete unused trailing top level binding with Haddock comment" $
2558+
testFor
2559+
[ "{-# OPTIONS_GHC -Wunused-top-binds #-}"
2560+
, "module A (some) where"
2561+
, ""
2562+
, "oof = 1"
2563+
, "oof :: Int"
2564+
, "-- ^ trailing docs for oof"
2565+
, ""
2566+
, "some = ()"
2567+
]
2568+
(3, 0)
2569+
1
2570+
"Delete ‘oof’"
25522571
[ "{-# OPTIONS_GHC -Wunused-top-binds #-}"
25532572
, "module A (some) where"
25542573
, ""

0 commit comments

Comments
 (0)