@@ -13,6 +13,7 @@ import Control.Monad.Trans.Class (lift)
13
13
import Control.Monad.Trans.Except (ExceptT , throwE )
14
14
import Control.Monad.Trans.Maybe
15
15
import Data.Aeson
16
+ import Data.Bifunctor (second )
16
17
import Data.Either.Extra (rights )
17
18
import Data.List
18
19
import qualified Data.Map.Strict as Map
@@ -113,14 +114,16 @@ codeAction recorder state plId (CodeActionParams _ _ docId _ context) = pluginRe
113
114
logWith recorder Info (LogImplementedMethods cls implemented)
114
115
pure
115
116
$ concatMap mkAction
116
- $ fmap (filter (\ (bind, _) -> bind `notElem` implemented))
117
+ $ filter ((/=) mempty . snd )
118
+ $ fmap (second (filter (\ (bind, _) -> bind `notElem` implemented)))
119
+ $ (<>) [foo range sigs]
117
120
$ minDefToMethodGroups range sigs
118
121
$ classMinimalDef cls
119
122
where
120
123
range = diag ^. J. range
121
124
122
- mkAction :: [( T. Text , T. Text )] -> [Command |? CodeAction ]
123
- mkAction methodGroup
125
+ mkAction :: Suggestion -> [Command |? CodeAction ]
126
+ mkAction (name, methodGroup)
124
127
= [ mkCodeAction title
125
128
$ mkLspCommand plId codeActionCommandId title
126
129
(Just $ mkCmdParams methodGroup False )
@@ -129,14 +132,8 @@ codeAction recorder state plId (CodeActionParams _ _ docId _ context) = pluginRe
129
132
(Just $ mkCmdParams methodGroup True )
130
133
]
131
134
where
132
- title = mkTitle $ fst <$> methodGroup
133
- titleWithSig = mkTitleWithSig $ fst <$> methodGroup
134
-
135
- mkTitle methodGroup
136
- = " Add placeholders for "
137
- <> mconcat (intersperse " , " (fmap (\ m -> " '" <> m <> " '" ) methodGroup))
138
-
139
- mkTitleWithSig methodGroup = mkTitle methodGroup <> " with signature(s)"
135
+ title = " Add placeholders for " <> name
136
+ titleWithSig = title <> " with signature(s)"
140
137
141
138
mkCmdParams methodGroup withSig =
142
139
[toJSON (AddMinimalMethodsParams uri range (List methodGroup) withSig)]
@@ -211,15 +208,42 @@ isInstanceValBind :: ContextInfo -> Bool
211
208
isInstanceValBind (ValBind InstanceBind _ _) = True
212
209
isInstanceValBind _ = False
213
210
211
+ type MethodSig = T. Text
212
+ type MethodName = T. Text
213
+ type MethodGroup = (MethodName , MethodSig )
214
+ type Suggestion = (T. Text , [MethodGroup ])
215
+
216
+ makeMethodGroup :: InstanceBindTypeSig -> MethodGroup
217
+ makeMethodGroup sig = (name, signature)
218
+ where
219
+ name = T. drop (T. length bindingPrefix) (printOutputable (bindName sig))
220
+ signature = bindRendered sig
221
+
222
+ foo :: Range -> [InstanceBindTypeSig ] -> Suggestion
223
+ foo range sigs = (" all missing methods" , methodGroups)
224
+ where
225
+ methodGroups = [ makeMethodGroup sig
226
+ | sig <- sigs
227
+ , inRange range (getSrcSpan $ bindName sig)
228
+ ]
229
+
230
+
214
231
-- Return (name text, signature text)
215
- minDefToMethodGroups :: Range -> [InstanceBindTypeSig ] -> BooleanFormula Name -> [[( T. Text , T. Text )] ]
216
- minDefToMethodGroups range sigs = go
232
+ minDefToMethodGroups :: Range -> [InstanceBindTypeSig ] -> BooleanFormula Name -> [Suggestion ]
233
+ minDefToMethodGroups range sigs minDef = suggestions
217
234
where
218
- go (Var mn) = [[ (T. pack . occNameString . occName $ mn, bindRendered sig)
235
+ makeSuggestion methodGroup =
236
+ let name = mconcat $ intersperse " ," $ fst <$> methodGroup
237
+ in (name, methodGroup)
238
+
239
+ suggestions = makeSuggestion <$> go minDef
240
+
241
+ go (Var mn) = [[ makeMethodGroup sig
219
242
| sig <- sigs
220
243
, inRange range (getSrcSpan $ bindName sig)
221
244
, printOutputable mn == T. drop (T. length bindingPrefix) (printOutputable (bindName sig))
222
245
]]
223
246
go (Or ms) = concatMap (go . unLoc) ms
224
247
go (And ms) = foldr (liftA2 (<>) ) [[] ] (fmap (go . unLoc) ms)
225
248
go (Parens m) = go (unLoc m)
249
+
0 commit comments