Skip to content

Commit bd01ab3

Browse files
committed
Refactor HaRe mkCodeActions
1 parent 9f6fc95 commit bd01ab3

File tree

1 file changed

+23
-46
lines changed
  • src/Haskell/Ide/Engine/Plugin

1 file changed

+23
-46
lines changed

src/Haskell/Ide/Engine/Plugin/HaRe.hs

Lines changed: 23 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -359,60 +359,37 @@ hoist f a =
359359
codeActionProvider :: CodeActionProvider
360360
codeActionProvider pId docId _ _ (J.Range pos _) _ =
361361
pluginGetFile "HaRe codeActionProvider: " (docId ^. J.uri) $ \file ->
362-
ifCachedInfo file (IdeResultOk mempty) $ \info ->
362+
ifCachedInfo file (IdeResultOk mempty) $ \info -> do
363363
case getArtifactsAtPos pos (defMap info) of
364-
[h] -> do
364+
[h] ->
365365
let name = Hie.showName $ snd h
366-
debugm $ show name
367-
IdeResultOk <$> sequence [
368-
mkLiftOneAction name
369-
, mkLiftTopAction name
370-
, mkDemoteAction name
371-
, mkDeleteAction name
372-
, mkDuplicateAction name
366+
in IdeResultOk <$> sequence [
367+
mkAction "liftonelevel"
368+
J.CodeActionRefactorExtract $ "Lift " <> name <> " one level"
369+
, mkAction "lifttotoplevel"
370+
J.CodeActionRefactorExtract $"Lift " <> name <> " to top level"
371+
, mkAction "demote"
372+
J.CodeActionRefactorInline $ "Demote " <> name <> " one level"
373+
, mkAction "deletedef"
374+
J.CodeActionRefactor $ "Delete definition of " <> name
375+
, mkHptAction "dupdef"
376+
J.CodeActionRefactor "Duplicate definition of " name
373377
]
374378
_ -> case getArtifactsAtPos pos (locMap info) of
375-
[h] -> do
379+
[h] ->
376380
let name = Hie.showName $ snd h
377-
debugm $ show name
378-
IdeResultOk <$> sequence [
379-
mkCaseSplitAction name
381+
in IdeResultOk <$> sequence [
382+
mkAction "casesplit"
383+
J.CodeActionRefactorRewrite $ "Case split on " <> name
380384
]
381385
_ -> return $ IdeResultOk []
382386

383387
where
384-
mkLiftOneAction name = do
388+
mkAction aId kind title = do
385389
let args = [J.toJSON $ HP (docId ^. J.uri) pos]
386-
title = "Lift " <> name <> " one level"
387-
liftCmd <- mkLspCommand pId "liftonelevel" title (Just args)
388-
return $ J.CodeAction title (Just J.CodeActionRefactorExtract) mempty Nothing (Just liftCmd)
389-
390-
mkLiftTopAction name = do
391-
let args = [J.toJSON $ HP (docId ^. J.uri) pos]
392-
title = "Lift " <> name <> " to top level"
393-
liftCmd <- mkLspCommand pId "lifttotoplevel" title (Just args)
394-
return $ J.CodeAction title (Just J.CodeActionRefactorExtract) mempty Nothing (Just liftCmd)
395-
396-
mkDemoteAction name = do
397-
let args = [J.toJSON $ HP (docId ^. J.uri) pos]
398-
title = "Demote " <> name <> " one level"
399-
demCmd <- mkLspCommand pId "demote" title (Just args)
400-
return $ J.CodeAction title (Just J.CodeActionRefactorInline) mempty Nothing (Just demCmd)
401-
402-
mkDeleteAction name = do
403-
let args = [J.toJSON $ HP (docId ^. J.uri) pos]
404-
title = "Delete definition of " <> name
405-
delCmd <- mkLspCommand pId "deletedef" title (Just args)
406-
return $ J.CodeAction title (Just J.CodeActionRefactor) mempty Nothing (Just delCmd)
407-
408-
mkDuplicateAction name = do
390+
cmd <- mkLspCommand pId aId title (Just args)
391+
return $ J.CodeAction title (Just kind) mempty Nothing (Just cmd)
392+
mkHptAction aId kind title name = do
409393
let args = [J.toJSON $ HPT (docId ^. J.uri) pos (name <> "'")]
410-
title = "Duplicate definition of " <> name
411-
dupCmd <- mkLspCommand pId "dupdef" title (Just args)
412-
return $ J.CodeAction title (Just J.CodeActionRefactor) mempty Nothing (Just dupCmd)
413-
414-
mkCaseSplitAction name = do
415-
let args = [J.toJSON $ HP (docId ^. J.uri) pos]
416-
title = "Case split on " <> name
417-
splCmd <- mkLspCommand pId "casesplit" title (Just args)
418-
return $ J.CodeAction title (Just J.CodeActionRefactorRewrite) mempty Nothing (Just splCmd)
394+
cmd <- mkLspCommand pId aId title (Just args)
395+
return $ J.CodeAction (title <> name) (Just kind) mempty Nothing (Just cmd)

0 commit comments

Comments
 (0)