@@ -71,6 +71,8 @@ module Language.LSP.Test
71
71
, getCodeActions
72
72
, getAllCodeActions
73
73
, executeCodeAction
74
+ , resolveCodeAction
75
+ , resolveAndExecuteCodeAction
74
76
-- ** Completions
75
77
, getCompletions
76
78
-- ** References
@@ -93,6 +95,7 @@ module Language.LSP.Test
93
95
, applyEdit
94
96
-- ** Code lenses
95
97
, getCodeLenses
98
+ , resolveCodeLens
96
99
-- ** Call hierarchy
97
100
, prepareCallHierarchy
98
101
, incomingCalls
@@ -605,6 +608,22 @@ executeCodeAction action = do
605
608
let req = TRequestMessage " " (IdInt 0 ) SMethod_WorkspaceApplyEdit (ApplyWorkspaceEditParams Nothing e)
606
609
in updateState (FromServerMess SMethod_WorkspaceApplyEdit req)
607
610
611
+ -- | Resolves the provided code action.
612
+ resolveCodeAction :: CodeAction -> Session CodeAction
613
+ resolveCodeAction ca = do
614
+ rsp <- request SMethod_CodeActionResolve ca
615
+ case rsp ^. L. result of
616
+ Right ca -> return ca
617
+ Left error -> throw (UnexpectedResponseError (SomeLspId $ fromJust $ rsp ^. L. id ) error )
618
+
619
+ -- | If a code action contains a _data_ field, resolves, the code action, then
620
+ -- executes it. Otherwise, just executes it.
621
+ resolveAndExecuteCodeAction :: CodeAction -> Session ()
622
+ resolveAndExecuteCodeAction ca@ CodeAction {_data_= Just _} = do
623
+ caRsp <- resolveCodeAction ca
624
+ executeCodeAction caRsp
625
+ resolveAndExecuteCodeAction ca = executeCodeAction ca
626
+
608
627
-- | Adds the current version to the document, as tracked by the session.
609
628
getVersionedDoc :: TextDocumentIdentifier -> Session VersionedTextDocumentIdentifier
610
629
getVersionedDoc (TextDocumentIdentifier uri) = do
@@ -749,6 +768,14 @@ getCodeLenses tId = do
749
768
rsp <- request SMethod_TextDocumentCodeLens (CodeLensParams Nothing Nothing tId)
750
769
pure $ absorbNull $ getResponseResult rsp
751
770
771
+ -- | Resolves the provided code lens.
772
+ resolveCodeLens :: CodeLens -> Session CodeLens
773
+ resolveCodeLens cl = do
774
+ rsp <- request SMethod_CodeLensResolve cl
775
+ case rsp ^. L. result of
776
+ Right cl -> return cl
777
+ Left error -> throw (UnexpectedResponseError (SomeLspId $ fromJust $ rsp ^. L. id ) error )
778
+
752
779
-- | Pass a param and return the response from `prepareCallHierarchy`
753
780
prepareCallHierarchy :: CallHierarchyPrepareParams -> Session [CallHierarchyItem ]
754
781
prepareCallHierarchy = resolveRequestWithListResp SMethod_TextDocumentPrepareCallHierarchy
0 commit comments