@@ -64,6 +64,9 @@ hareDescriptor plId = PluginDescriptor
64
64
deleteDefCmd
65
65
, PluginCommand " genapplicative" " Generalise a monadic function to use applicative"
66
66
genApplicativeCommand
67
+
68
+ , PluginCommand " casesplit" " Generate a pattern match for a binding under (LINE,COL)"
69
+ Hie. splitCaseCmd
67
70
]
68
71
, pluginCodeActionProvider = Just codeActionProvider
69
72
, pluginDiagnosticProvider = Nothing
@@ -73,29 +76,16 @@ hareDescriptor plId = PluginDescriptor
73
76
74
77
-- ---------------------------------------------------------------------
75
78
76
- customOptions :: Int -> J. Options
77
- customOptions n = J. defaultOptions { J. fieldLabelModifier = J. camelTo2 ' _' . drop n}
78
-
79
- data HarePoint =
80
- HP { hpFile :: Uri
81
- , hpPos :: Position
82
- } deriving (Eq ,Generic ,Show )
83
-
84
- instance FromJSON HarePoint where
85
- parseJSON = genericParseJSON $ customOptions 2
86
- instance ToJSON HarePoint where
87
- toJSON = genericToJSON $ customOptions 2
88
-
89
79
data HarePointWithText =
90
80
HPT { hptFile :: Uri
91
81
, hptPos :: Position
92
82
, hptText :: T. Text
93
83
} deriving (Eq ,Generic ,Show )
94
84
95
85
instance FromJSON HarePointWithText where
96
- parseJSON = genericParseJSON $ customOptions 3
86
+ parseJSON = genericParseJSON $ Hie. customOptions 3
97
87
instance ToJSON HarePointWithText where
98
- toJSON = genericToJSON $ customOptions 3
88
+ toJSON = genericToJSON $ Hie. customOptions 3
99
89
100
90
data HareRange =
101
91
HR { hrFile :: Uri
@@ -104,14 +94,14 @@ data HareRange =
104
94
} deriving (Eq ,Generic ,Show )
105
95
106
96
instance FromJSON HareRange where
107
- parseJSON = genericParseJSON $ customOptions 2
97
+ parseJSON = genericParseJSON $ Hie. customOptions 2
108
98
instance ToJSON HareRange where
109
- toJSON = genericToJSON $ customOptions 2
99
+ toJSON = genericToJSON $ Hie. customOptions 2
110
100
111
101
-- ---------------------------------------------------------------------
112
102
113
- demoteCmd :: CommandFunc HarePoint WorkspaceEdit
114
- demoteCmd = CmdSync $ \ _ (HP uri pos) ->
103
+ demoteCmd :: CommandFunc Hie. HarePoint WorkspaceEdit
104
+ demoteCmd = CmdSync $ \ _ (Hie. HP uri pos) ->
115
105
demoteCmd' uri pos
116
106
117
107
demoteCmd' :: Uri -> Position -> IdeGhcM (IdeResult WorkspaceEdit )
@@ -149,8 +139,8 @@ iftocaseCmd' uri (Range startPos endPos) =
149
139
150
140
-- ---------------------------------------------------------------------
151
141
152
- liftonelevelCmd :: CommandFunc HarePoint WorkspaceEdit
153
- liftonelevelCmd = CmdSync $ \ _ (HP uri pos) ->
142
+ liftonelevelCmd :: CommandFunc Hie. HarePoint WorkspaceEdit
143
+ liftonelevelCmd = CmdSync $ \ _ (Hie. HP uri pos) ->
154
144
liftonelevelCmd' uri pos
155
145
156
146
liftonelevelCmd' :: Uri -> Position -> IdeGhcM (IdeResult WorkspaceEdit )
@@ -162,8 +152,8 @@ liftonelevelCmd' uri pos =
162
152
163
153
-- ---------------------------------------------------------------------
164
154
165
- lifttotoplevelCmd :: CommandFunc HarePoint WorkspaceEdit
166
- lifttotoplevelCmd = CmdSync $ \ _ (HP uri pos) ->
155
+ lifttotoplevelCmd :: CommandFunc Hie. HarePoint WorkspaceEdit
156
+ lifttotoplevelCmd = CmdSync $ \ _ (Hie. HP uri pos) ->
167
157
lifttotoplevelCmd' uri pos
168
158
169
159
lifttotoplevelCmd' :: Uri -> Position -> IdeGhcM (IdeResult WorkspaceEdit )
@@ -188,8 +178,8 @@ renameCmd' uri pos name =
188
178
189
179
-- ---------------------------------------------------------------------
190
180
191
- deleteDefCmd :: CommandFunc HarePoint WorkspaceEdit
192
- deleteDefCmd = CmdSync $ \ _ (HP uri pos) ->
181
+ deleteDefCmd :: CommandFunc Hie. HarePoint WorkspaceEdit
182
+ deleteDefCmd = CmdSync $ \ _ (Hie. HP uri pos) ->
193
183
deleteDefCmd' uri pos
194
184
195
185
deleteDefCmd' :: Uri -> Position -> IdeGhcM (IdeResult WorkspaceEdit )
@@ -201,8 +191,8 @@ deleteDefCmd' uri pos =
201
191
202
192
-- ---------------------------------------------------------------------
203
193
204
- genApplicativeCommand :: CommandFunc HarePoint WorkspaceEdit
205
- genApplicativeCommand = CmdSync $ \ _ (HP uri pos) ->
194
+ genApplicativeCommand :: CommandFunc Hie. HarePoint WorkspaceEdit
195
+ genApplicativeCommand = CmdSync $ \ _ (Hie. HP uri pos) ->
206
196
genApplicativeCommand' uri pos
207
197
208
198
genApplicativeCommand' :: Uri -> Position -> IdeGhcM (IdeResult WorkspaceEdit )
@@ -294,42 +284,48 @@ hoist f a =
294
284
codeActionProvider :: CodeActionProvider
295
285
codeActionProvider pId docId _ _ (J. Range pos _) _ =
296
286
pluginGetFile " HaRe codeActionProvider: " (docId ^. J. uri) $ \ file ->
297
- ifCachedInfo file (IdeResultOk mempty ) $ \ info -> do
298
- let symbols = getArtifactsAtPos pos (defMap info)
299
- debugm $ show $ map (Hie. showName . snd ) symbols
300
- if not (null symbols)
301
- then
302
- let name = Hie. showName $ snd $ head symbols
303
- in IdeResultOk <$> sequence [
287
+ ifCachedInfo file (IdeResultOk mempty ) $ \ info ->
288
+ case getArtifactsAtPos pos (defMap info) of
289
+ [h] -> do
290
+ let name = Hie. showName $ snd h
291
+ debugm $ show name
292
+ IdeResultOk <$> sequence [
304
293
mkLiftOneAction name
305
294
, mkLiftTopAction name
306
295
, mkDemoteAction name
307
296
, mkDeleteAction name
308
297
, mkDuplicateAction name
309
298
]
310
- else return (IdeResultOk [] )
299
+ _ -> case getArtifactsAtPos pos (locMap info) of
300
+ [h] -> do
301
+ let name = Hie. showName $ snd h
302
+ debugm $ show name
303
+ IdeResultOk <$> sequence [
304
+ mkCaseSplitAction name
305
+ ]
306
+ _ -> return $ IdeResultOk []
311
307
312
308
where
313
309
mkLiftOneAction name = do
314
- let args = [J. toJSON $ HP (docId ^. J. uri) pos]
310
+ let args = [J. toJSON $ Hie. HP (docId ^. J. uri) pos]
315
311
title = " Lift " <> name <> " one level"
316
312
liftCmd <- mkLspCommand pId " liftonelevel" title (Just args)
317
313
return $ J. CodeAction title (Just J. CodeActionRefactorExtract ) mempty Nothing (Just liftCmd)
318
314
319
315
mkLiftTopAction name = do
320
- let args = [J. toJSON $ HP (docId ^. J. uri) pos]
316
+ let args = [J. toJSON $ Hie. HP (docId ^. J. uri) pos]
321
317
title = " Lift " <> name <> " to top level"
322
318
liftCmd <- mkLspCommand pId " lifttotoplevel" title (Just args)
323
319
return $ J. CodeAction title (Just J. CodeActionRefactorExtract ) mempty Nothing (Just liftCmd)
324
320
325
321
mkDemoteAction name = do
326
- let args = [J. toJSON $ HP (docId ^. J. uri) pos]
322
+ let args = [J. toJSON $ Hie. HP (docId ^. J. uri) pos]
327
323
title = " Demote " <> name <> " one level"
328
324
demCmd <- mkLspCommand pId " demote" title (Just args)
329
325
return $ J. CodeAction title (Just J. CodeActionRefactorInline ) mempty Nothing (Just demCmd)
330
326
331
327
mkDeleteAction name = do
332
- let args = [J. toJSON $ HP (docId ^. J. uri) pos]
328
+ let args = [J. toJSON $ Hie. HP (docId ^. J. uri) pos]
333
329
title = " Delete definition of " <> name
334
330
delCmd <- mkLspCommand pId " deletedef" title (Just args)
335
331
return $ J. CodeAction title (Just J. CodeActionRefactor ) mempty Nothing (Just delCmd)
@@ -339,3 +335,9 @@ codeActionProvider pId docId _ _ (J.Range pos _) _ =
339
335
title = " Duplicate definition of " <> name
340
336
dupCmd <- mkLspCommand pId " dupdef" title (Just args)
341
337
return $ J. CodeAction title (Just J. CodeActionRefactor ) mempty Nothing (Just dupCmd)
338
+
339
+ mkCaseSplitAction name = do
340
+ let args = [J. toJSON $ Hie. HP (docId ^. J. uri) pos]
341
+ title = " Case split on " <> name
342
+ splCmd <- mkLspCommand pId " casesplit" title (Just args)
343
+ return $ J. CodeAction title (Just J. CodeActionRefactorRewrite ) mempty Nothing (Just splCmd)
0 commit comments