Skip to content

Commit e74ac28

Browse files
committed
Update code action title and comment template
1 parent 7f56977 commit e74ac28

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

plugins/hls-haddock-comments-plugin/src/Ide/Plugin/HaddockComments.hs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ codeActionProvider _lspFuncs ideState _pId (TextDocumentIdentifier uri) range Co
4141
let locDecls = hsmodDecls . unLoc . pm_parsed_source <$> pm
4242
anns = relativiseApiAnns <$> (pm_parsed_source <$> pm) <*> (pm_annotations <$> pm)
4343
edits = [runGenComments gen locDecls anns range | noErr, gen <- genList]
44-
return $ Right $ List [CACodeAction $ toAction "Generate haddock comments" uri edit | (Just edit) <- edits]
44+
return $ Right $ List [CACodeAction $ toAction title uri edit | (Just (title, edit)) <- edits]
4545

4646
genList :: [GenComments]
4747
genList =
@@ -52,57 +52,62 @@ genList =
5252
-----------------------------------------------------------------------------
5353
data GenComments = forall a.
5454
GenComments
55-
{ fromDecl :: HsDecl GhcPs -> Maybe a,
55+
{ title :: T.Text,
56+
fromDecl :: HsDecl GhcPs -> Maybe a,
5657
collectKeys :: a -> [AnnKey],
57-
fresh :: Annotation -> Bool,
58+
isFresh :: Annotation -> Bool,
5859
updateAnn :: Annotation -> Annotation
5960
}
6061

61-
runGenComments :: GenComments -> Maybe [LHsDecl GhcPs] -> Maybe Anns -> Range -> Maybe TextEdit
62+
runGenComments :: GenComments -> Maybe [LHsDecl GhcPs] -> Maybe Anns -> Range -> Maybe (T.Text, TextEdit)
6263
runGenComments GenComments {..} mLocDecls mAnns range
6364
| Just locDecls <- mLocDecls,
6465
Just anns <- mAnns,
6566
[(locDecl, src, x)] <- [(locDecl, l, x) | locDecl@(L l (fromDecl -> Just x)) <- locDecls, inRange range l],
6667
annKeys <- collectKeys x,
6768
not $ null annKeys,
68-
and $ maybe False fresh . flip Map.lookup anns <$> annKeys,
69+
and $ maybe False isFresh . flip Map.lookup anns <$> annKeys,
6970
anns' <- foldr (Map.adjust updateAnn) anns annKeys,
7071
Just range' <- calcRange src range,
7172
result <- T.strip . T.pack $ exactPrint locDecl anns' =
72-
Just $ TextEdit range' result
73+
Just (title, TextEdit range' result)
7374
| otherwise = Nothing
7475

7576
-----------------------------------------------------------------------------
7677

7778
genForSig :: GenComments
7879
genForSig = GenComments {..}
7980
where
81+
title = "Generate signature comments"
82+
8083
fromDecl (SigD _ (TypeSig _ _ (HsWC _ (HsIB _ x)))) = Just x
8184
fromDecl _ = Nothing
8285
updateAnn x = x {annEntryDelta = DP (0, 1), annsDP = dp}
8386

84-
fresh Ann {annsDP}
87+
isFresh Ann {annsDP}
8588
| null [() | (AnnComment _, _) <- annsDP] = True
8689
| otherwise = False
8790

8891
collectKeys = keyFromTyVar 0
8992

90-
comment = mkComment "-- ^ ____" noSrcSpan
93+
comment = mkComment "-- ^ " noSrcSpan
9194
dp = [(AnnComment comment, DP (0, 1)), (G AnnRarrow, DP (1, 2))]
9295

9396
genForRecord :: GenComments
9497
genForRecord = GenComments {..}
9598
where
99+
title = "Generate fields comments"
100+
96101
fromDecl (TyClD _ DataDecl {tcdDataDefn = HsDataDefn {dd_cons = cons}}) = Just [x | (L _ ConDeclH98 {con_args = x}) <- cons]
97102
fromDecl _ = Nothing
98103

99104
updateAnn x = x {annEntryDelta = DP (1, -7), annPriorComments = [(comment, DP (1, -7))]}
100105

101-
fresh Ann {annPriorComments} = null annPriorComments
106+
isFresh Ann {annPriorComments} = null annPriorComments
102107

103108
collectKeys = keyFromCon
104109

105-
comment = mkComment "-- | ____" noSrcSpan
110+
comment = mkComment "-- | " noSrcSpan
106111

107112
-----------------------------------------------------------------------------
108113

0 commit comments

Comments
 (0)