@@ -41,7 +41,7 @@ codeActionProvider _lspFuncs ideState _pId (TextDocumentIdentifier uri) range Co
41
41
let locDecls = hsmodDecls . unLoc . pm_parsed_source <$> pm
42
42
anns = relativiseApiAnns <$> (pm_parsed_source <$> pm) <*> (pm_annotations <$> pm)
43
43
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]
45
45
46
46
genList :: [GenComments ]
47
47
genList =
@@ -52,57 +52,62 @@ genList =
52
52
-----------------------------------------------------------------------------
53
53
data GenComments = forall a .
54
54
GenComments
55
- { fromDecl :: HsDecl GhcPs -> Maybe a ,
55
+ { title :: T. Text ,
56
+ fromDecl :: HsDecl GhcPs -> Maybe a ,
56
57
collectKeys :: a -> [AnnKey ],
57
- fresh :: Annotation -> Bool ,
58
+ isFresh :: Annotation -> Bool ,
58
59
updateAnn :: Annotation -> Annotation
59
60
}
60
61
61
- runGenComments :: GenComments -> Maybe [LHsDecl GhcPs ] -> Maybe Anns -> Range -> Maybe TextEdit
62
+ runGenComments :: GenComments -> Maybe [LHsDecl GhcPs ] -> Maybe Anns -> Range -> Maybe ( T. Text , TextEdit )
62
63
runGenComments GenComments {.. } mLocDecls mAnns range
63
64
| Just locDecls <- mLocDecls,
64
65
Just anns <- mAnns,
65
66
[(locDecl, src, x)] <- [(locDecl, l, x) | locDecl@ (L l (fromDecl -> Just x)) <- locDecls, inRange range l],
66
67
annKeys <- collectKeys x,
67
68
not $ null annKeys,
68
- and $ maybe False fresh . flip Map. lookup anns <$> annKeys,
69
+ and $ maybe False isFresh . flip Map. lookup anns <$> annKeys,
69
70
anns' <- foldr (Map. adjust updateAnn) anns annKeys,
70
71
Just range' <- calcRange src range,
71
72
result <- T. strip . T. pack $ exactPrint locDecl anns' =
72
- Just $ TextEdit range' result
73
+ Just (title, TextEdit range' result)
73
74
| otherwise = Nothing
74
75
75
76
-----------------------------------------------------------------------------
76
77
77
78
genForSig :: GenComments
78
79
genForSig = GenComments {.. }
79
80
where
81
+ title = " Generate signature comments"
82
+
80
83
fromDecl (SigD _ (TypeSig _ _ (HsWC _ (HsIB _ x)))) = Just x
81
84
fromDecl _ = Nothing
82
85
updateAnn x = x {annEntryDelta = DP (0 , 1 ), annsDP = dp}
83
86
84
- fresh Ann {annsDP}
87
+ isFresh Ann {annsDP}
85
88
| null [() | (AnnComment _, _) <- annsDP] = True
86
89
| otherwise = False
87
90
88
91
collectKeys = keyFromTyVar 0
89
92
90
- comment = mkComment " -- ^ ____ " noSrcSpan
93
+ comment = mkComment " -- ^ " noSrcSpan
91
94
dp = [(AnnComment comment, DP (0 , 1 )), (G AnnRarrow , DP (1 , 2 ))]
92
95
93
96
genForRecord :: GenComments
94
97
genForRecord = GenComments {.. }
95
98
where
99
+ title = " Generate fields comments"
100
+
96
101
fromDecl (TyClD _ DataDecl {tcdDataDefn = HsDataDefn {dd_cons = cons}}) = Just [x | (L _ ConDeclH98 {con_args = x}) <- cons]
97
102
fromDecl _ = Nothing
98
103
99
104
updateAnn x = x {annEntryDelta = DP (1 , - 7 ), annPriorComments = [(comment, DP (1 , - 7 ))]}
100
105
101
- fresh Ann {annPriorComments} = null annPriorComments
106
+ isFresh Ann {annPriorComments} = null annPriorComments
102
107
103
108
collectKeys = keyFromCon
104
109
105
- comment = mkComment " -- | ____ " noSrcSpan
110
+ comment = mkComment " -- | " noSrcSpan
106
111
107
112
-----------------------------------------------------------------------------
108
113
0 commit comments