-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #256 from rgrinberg/destruct-own-module
Move destruct to own module
- Loading branch information
Showing
3 changed files
with
52 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
open Import | ||
|
||
let action_kind = "destruct" | ||
|
||
let code_action_of_case_analysis uri (loc, newText) = | ||
let edit : WorkspaceEdit.t = | ||
let textedit : TextEdit.t = { range = Range.of_loc loc; newText } in | ||
let uri = Uri.to_string uri in | ||
WorkspaceEdit.create ~changes:[ (uri, [ textedit ]) ] () | ||
in | ||
let title = String.capitalize_ascii action_kind in | ||
CodeAction.create ~title ~kind:(CodeActionKind.Other action_kind) ~edit | ||
~isPreferred:false () | ||
|
||
let code_action doc (params : CodeActionParams.t) = | ||
let uri = Uri.t_of_yojson (`String params.textDocument.uri) in | ||
match Document.kind doc with | ||
| Intf -> Fiber.return (Ok None) | ||
| Impl -> ( | ||
let command = | ||
let start = Position.logical params.range.start in | ||
let finish = Position.logical params.range.end_ in | ||
Query_protocol.Case_analysis (start, finish) | ||
in | ||
let open Fiber.O in | ||
let+ res = Document.dispatch doc command in | ||
match res with | ||
| Ok res -> Ok (Some (code_action_of_case_analysis uri res)) | ||
| Error | ||
( Destruct.Wrong_parent _ | Query_commands.No_nodes | ||
| Destruct.Not_allowed _ | Destruct.Useless_refine | ||
| Destruct.Nothing_to_do ) -> | ||
Ok None | ||
| Error exn -> Error (Jsonrpc.Response.Error.of_exn exn) ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
open Import | ||
|
||
val action_kind : string | ||
|
||
val code_action : | ||
Document.t | ||
-> CodeActionParams.t | ||
-> (CodeAction.t option, Jsonrpc.Response.Error.t) Fiber.Result.t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters