@@ -12,14 +12,10 @@ let not_supported () =
1212 @@ Error
1313 (make_error ~code: InternalError ~message: " Request not supported yet!" () )
1414
15- module Action = struct
16- let destruct = " destruct"
17- end
18-
1915let initialize_info : InitializeResult.t =
2016 let codeActionProvider =
21- `CodeActionOptions
22- (CodeActionOptions. create ~code ActionKinds:[ Other Action. destruct ] () )
17+ let codeActionKinds = [ CodeActionKind. Other Destruct_lsp. action_kind ] in
18+ `CodeActionOptions (CodeActionOptions. create ~code ActionKinds () )
2319 in
2420 let textDocumentSync =
2521 `TextDocumentSyncOptions
@@ -157,49 +153,23 @@ let on_initialize rpc =
157153 Logger. register_consumer log_consumer;
158154 initialize_info
159155
160- let code_action_of_case_analysis uri (loc , newText ) =
161- let edit : WorkspaceEdit.t =
162- let textedit : TextEdit.t = { range = Range. of_loc loc; newText } in
163- let uri = Uri. to_string uri in
164- WorkspaceEdit. create ~changes: [ (uri, [ textedit ]) ] ()
165- in
166- let title = String. capitalize_ascii Action. destruct in
167- CodeAction. create ~title ~kind: (CodeActionKind. Other Action. destruct) ~edit
168- ~is Preferred:false ()
169-
170156let code_action server (params : CodeActionParams.t ) =
171157 let state : State.t = Server. state server in
172158 let store = state.store in
173159 match params.context.only with
174- | Some set when not (List. mem (CodeActionKind. Other Action. destruct) ~set ) ->
160+ | Some set
161+ when not (List. mem (CodeActionKind. Other Destruct_lsp. action_kind) ~set ) ->
175162 Fiber. return (Ok (None , state))
176163 | Some _
177- | None -> (
164+ | None ->
178165 let open Fiber.Result.O in
179166 let uri = Uri. t_of_yojson (`String params.textDocument.uri) in
180167 let * doc = Fiber. return (Document_store. get store uri) in
181- match Document. kind doc with
182- | Intf -> Fiber. return (Ok (None , state))
183- | Impl ->
184- let command =
185- let start = Position. logical params.range.start in
186- let finish = Position. logical params.range.end_ in
187- Query_protocol. Case_analysis (start, finish)
188- in
189- let + result =
190- let open Fiber.O in
191- let + res = Document. dispatch doc command in
192- match res with
193- | Ok res ->
194- Ok (Some [ `CodeAction (code_action_of_case_analysis uri res) ])
195- | Error
196- ( Destruct. Wrong_parent _ | Query_commands. No_nodes
197- | Destruct. Not_allowed _ | Destruct. Useless_refine
198- | Destruct. Nothing_to_do ) ->
199- Ok (Some [] )
200- | Error exn -> raise exn
201- in
202- (result, state) )
168+ let + action = Destruct_lsp. code_action doc params in
169+ let action =
170+ Option. map action ~f: (fun destruct -> [ `CodeAction destruct ])
171+ in
172+ (action, state)
203173
204174module Formatter = struct
205175 let jsonrpc_error (e : Fmt.error ) =
0 commit comments