@@ -12,14 +12,10 @@ let not_supported () =
12
12
@@ Error
13
13
(make_error ~code: InternalError ~message: " Request not supported yet!" () )
14
14
15
- module Action = struct
16
- let destruct = " destruct"
17
- end
18
-
19
15
let initialize_info : InitializeResult.t =
20
16
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 () )
23
19
in
24
20
let textDocumentSync =
25
21
`TextDocumentSyncOptions
@@ -157,49 +153,23 @@ let on_initialize rpc =
157
153
Logger. register_consumer log_consumer;
158
154
initialize_info
159
155
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
-
170
156
let code_action server (params : CodeActionParams.t ) =
171
157
let state : State.t = Server. state server in
172
158
let store = state.store in
173
159
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 ) ->
175
162
Fiber. return (Ok (None , state))
176
163
| Some _
177
- | None -> (
164
+ | None ->
178
165
let open Fiber.Result.O in
179
166
let uri = Uri. t_of_yojson (`String params.textDocument.uri) in
180
167
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)
203
173
204
174
module Formatter = struct
205
175
let jsonrpc_error (e : Fmt.error ) =
0 commit comments