Skip to content

Commit 8174604

Browse files
committed
refactor code action edit
1 parent 3eb0e28 commit 8174604

File tree

2 files changed

+20
-112
lines changed

2 files changed

+20
-112
lines changed

analysis/src/CodeActions.ml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,16 @@ let stringifyCodeActions codeActions =
77

88
let make ~title ~kind ~edit ~command =
99
{Protocol.title; codeActionKind = kind; edit; command}
10+
11+
let makeEdit edits uri =
12+
Protocol.
13+
{
14+
documentChanges =
15+
[
16+
{
17+
textDocument =
18+
{version = None; uri = uri |> Uri.fromPath |> Uri.toString};
19+
edits;
20+
};
21+
];
22+
}

analysis/src/Xform.ml

Lines changed: 7 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -113,22 +113,7 @@ module IfThenElse = struct
113113
let codeAction =
114114
CodeActions.make ~title:"Replace with switch" ~kind:RefactorRewrite
115115
~command:None
116-
~edit:
117-
(Some
118-
Protocol.
119-
{
120-
documentChanges =
121-
[
122-
{
123-
textDocument =
124-
{
125-
version = None;
126-
uri = path |> Uri.fromPath |> Uri.toString;
127-
};
128-
edits = [{newText; range}];
129-
};
130-
];
131-
})
116+
~edit:(Some (CodeActions.makeEdit [{newText; range}] path))
132117
in
133118
codeActions := codeAction :: !codeActions
134119
end
@@ -193,22 +178,7 @@ module AddBracesToFn = struct
193178
let codeAction =
194179
CodeActions.make ~title:"Add braces to function" ~kind:RefactorRewrite
195180
~command:None
196-
~edit:
197-
(Some
198-
Protocol.
199-
{
200-
documentChanges =
201-
[
202-
{
203-
textDocument =
204-
{
205-
version = None;
206-
uri = path |> Uri.fromPath |> Uri.toString;
207-
};
208-
edits = [{newText; range}];
209-
};
210-
];
211-
})
181+
~edit:(Some (CodeActions.makeEdit [{newText; range}] path))
212182
in
213183
codeActions := codeAction :: !codeActions
214184
end
@@ -282,22 +252,7 @@ module AddTypeAnnotation = struct
282252
let codeAction =
283253
CodeActions.make ~title:"Add type annotation" ~kind:RefactorRewrite
284254
~command:None
285-
~edit:
286-
(Some
287-
Protocol.
288-
{
289-
documentChanges =
290-
[
291-
{
292-
textDocument =
293-
{
294-
version = None;
295-
uri = path |> Uri.fromPath |> Uri.toString;
296-
};
297-
edits = [{newText; range}];
298-
};
299-
];
300-
})
255+
~edit:(Some (CodeActions.makeEdit [{newText; range}] path))
301256
in
302257
codeActions := codeAction :: !codeActions
303258
| _ -> ()))
@@ -434,22 +389,7 @@ module ExhaustiveSwitch = struct
434389
let codeAction =
435390
CodeActions.make ~command:None ~title:"Exhaustive switch"
436391
~kind:RefactorRewrite
437-
~edit:
438-
(Some
439-
Protocol.
440-
{
441-
documentChanges =
442-
[
443-
{
444-
textDocument =
445-
{
446-
version = None;
447-
uri = path |> Uri.fromPath |> Uri.toString;
448-
};
449-
edits = [{newText; range}];
450-
};
451-
];
452-
})
392+
~edit:(Some (CodeActions.makeEdit [{newText; range}] path))
453393
in
454394
codeActions := codeAction :: !codeActions))
455395
| Some (Switch {switchExpr; completionExpr; pos}) -> (
@@ -476,22 +416,7 @@ module ExhaustiveSwitch = struct
476416
let codeAction =
477417
CodeActions.make ~title:"Exhaustive switch" ~command:None
478418
~kind:RefactorRewrite (* ~uri:path ~newText ~range *)
479-
~edit:
480-
(Some
481-
Protocol.
482-
{
483-
documentChanges =
484-
[
485-
{
486-
textDocument =
487-
{
488-
version = None;
489-
uri = path |> Uri.fromPath |> Uri.toString;
490-
};
491-
edits = [{newText; range}];
492-
};
493-
];
494-
})
419+
~edit:(Some (CodeActions.makeEdit [{newText; range}] path))
495420
in
496421
codeActions := codeAction :: !codeActions))
497422
end
@@ -589,22 +514,7 @@ module AddDocTemplate = struct
589514
let codeAction =
590515
CodeActions.make ~title:"Add Documentation template"
591516
~kind:RefactorRewrite ~command:None
592-
~edit:
593-
(Some
594-
Protocol.
595-
{
596-
documentChanges =
597-
[
598-
{
599-
textDocument =
600-
{
601-
version = None;
602-
uri = path |> Uri.fromPath |> Uri.toString;
603-
};
604-
edits = [{newText; range}];
605-
};
606-
];
607-
})
517+
~edit:(Some (CodeActions.makeEdit [{newText; range}] path))
608518
in
609519
codeActions := codeAction :: !codeActions
610520
| None -> ())
@@ -690,22 +600,7 @@ module AddDocTemplate = struct
690600
let codeAction =
691601
CodeActions.make ~title:"Add Documentation template"
692602
~kind:RefactorRewrite ~command:None
693-
~edit:
694-
(Some
695-
Protocol.
696-
{
697-
documentChanges =
698-
[
699-
{
700-
textDocument =
701-
{
702-
version = None;
703-
uri = path |> Uri.fromPath |> Uri.toString;
704-
};
705-
edits = [{newText; range}];
706-
};
707-
];
708-
})
603+
~edit:(Some (CodeActions.makeEdit [{newText; range}] path))
709604
in
710605
codeActions := codeAction :: !codeActions
711606
| None -> ())

0 commit comments

Comments
 (0)