Skip to content

Commit 18b41c6

Browse files
committed
update CHANGELOG.md and fix tests
1 parent 13688ed commit 18b41c6

File tree

5 files changed

+60
-21
lines changed

5 files changed

+60
-21
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#### :rocket: New Feature
2121

2222
- Add support for the rewatch build system for incremental compilation. https://github.com/rescript-lang/rescript-vscode/pull/965
23+
- Code Actions: open Implementation/Interface/Compiled Js and create Interface file. https://github.com/rescript-lang/rescript-vscode/pull/767
2324

2425
## 1.50.0
2526

@@ -208,7 +209,6 @@
208209
#### :rocket: New Feature
209210

210211
- Docstring template Code Action. https://github.com/rescript-lang/rescript-vscode/pull/764
211-
- Code Actions: open Implementation/Interface/Compiled and create Interface file. https://github.com/rescript-lang/rescript-vscode/pull/767
212212
- Improve unlabelled argument names in completion function templates. https://github.com/rescript-lang/rescript-vscode/pull/754
213213
- Add `Some(fieldName)` case when completing in a pattern with an option on a record field. https://github.com/rescript-lang/rescript-vscode/pull/766
214214

analysis/src/Commands.ml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,14 @@ let test ~path =
449449
(Protocol.stringifyRange range)
450450
indent indent newText))
451451
| None -> ())
452+
| "c-a" ->
453+
let hint = String.sub rest 3 (String.length rest - 3) in
454+
print_endline
455+
("Codemod AddMissingCases" ^ path ^ " " ^ string_of_int line ^ ":"
456+
^ string_of_int col);
457+
Codemod.transform ~path ~pos:(line, col) ~debug:true
458+
~typ:AddMissingCases ~hint
459+
|> print_endline
452460
| "dia" -> diagnosticSyntax ~path
453461
| "hin" ->
454462
(* Get all inlay Hint between line 1 and n.

analysis/src/Xform.ml

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -432,8 +432,24 @@ module ExhaustiveSwitch = struct
432432
printExpr ~range {expr with pexp_desc = Pexp_match (expr, cases)}
433433
in
434434
let codeAction =
435-
CodeActions.make ~title:"Exhaustive switch" ~kind:RefactorRewrite
436-
~uri:path ~newText ~range
435+
CodeActions.make ~command:None ~title:"Exhaustive switch"
436+
~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+
})
437453
in
438454
codeActions := codeAction :: !codeActions))
439455
| Some (Switch {switchExpr; completionExpr; pos}) -> (
@@ -458,8 +474,24 @@ module ExhaustiveSwitch = struct
458474
{switchExpr with pexp_desc = Pexp_match (completionExpr, cases)}
459475
in
460476
let codeAction =
461-
CodeActions.make ~title:"Exhaustive switch" ~kind:RefactorRewrite
462-
~uri:path ~newText ~range
477+
CodeActions.make ~title:"Exhaustive switch" ~command:None
478+
~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+
})
463495
in
464496
codeActions := codeAction :: !codeActions))
465497
end
@@ -691,8 +723,7 @@ module OpenCompiledFile = struct
691723
let xform ~path ~codeActions =
692724
let uri = path |> Uri.fromPath |> Uri.toString in
693725
let codeAction =
694-
CodeActions.make ~title:"Open Compiled JS" ~kind:Empty
695-
~edit:None
726+
CodeActions.make ~title:"Open Compiled JS" ~kind:Empty ~edit:None
696727
~command:
697728
(Some
698729
Protocol.
@@ -843,7 +874,7 @@ let extractCodeActions ~path ~startPos ~endPos ~currentFile ~debug =
843874
let signature, printSignatureItem = parseInterface ~filename:currentFile in
844875
AddDocTemplate.Interface.xform ~pos ~codeActions ~path ~signature
845876
~printSignatureItem;
846-
HandleImpltInter.xform ~path ~codeActions;
847877
OpenCompiledFile.xform ~path ~codeActions;
878+
HandleImpltInter.xform ~path ~codeActions;
848879
!codeActions
849880
| Other -> []

analysis/tests/src/expected/CompletionResolve.res.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Completion resolve: Belt_Array
2-
"\nUtilities for `Array` functions.\n\n### Note about index syntax\n\nCode like `arr[0]` does *not* compile to JavaScript `arr[0]`. Reason transforms\nthe `[]` index syntax into a function: `Array.get(arr, 0)`. By default, this\nuses the default standard library's `Array.get` function, which may raise an\nexception if the index isn't found. If you `open Belt`, it will use the\n`Belt.Array.get` function which returns options instead of raising exceptions. \n[See this for more information](../belt.mdx#array-access-runtime-safety).\n"
2+
"\nUtililites for `Array` functions.\n\n### Note about index syntax\n\nCode like `arr[0]` does *not* compile to JavaScript `arr[0]`. Reason transforms\nthe `[]` index syntax into a function: `Array.get(arr, 0)`. By default, this\nuses the default standard library's `Array.get` function, which may raise an\nexception if the index isn't found. If you `open Belt`, it will use the\n`Belt.Array.get` function which returns options instead of raising exceptions. \n[See this for more information](../belt.mdx#array-access-runtime-safety).\n"
33

44
Completion resolve: ModuleStuff
55
" This is a top level module doc. "

server/src/server.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,16 +1023,16 @@ function openCompiledFile(msg: p.RequestMessage): p.Message {
10231023
return response;
10241024
}
10251025

1026-
let executeCommands = [
1027-
"rescriptls/open-compiled-file",
1028-
"rescriptls/open-interface-file",
1029-
"rescriptls/open-implementation-file",
1030-
"rescriptls/create-interface-file"
1031-
]
1026+
enum ExecuteCommands {
1027+
OpenCompiledFile = "rescriptls/open-compiled-file",
1028+
OpenInterfaceFile = "rescriptls/open-interface-file",
1029+
OpenImplentationFile = "rescriptls/open-implementation-file",
1030+
CreateInterfaceFile = "rescriptls/create-interface-file"
1031+
}
10321032

10331033
function executeCommand(msg: p.RequestMessage): p.Message {
10341034
let params = msg.params as p.ExecuteCommandParams;
1035-
let command = params.command;
1035+
let command = params.command as ExecuteCommands;
10361036
let args = params.arguments;
10371037

10381038
let response: p.ResponseMessage = {
@@ -1059,7 +1059,7 @@ function executeCommand(msg: p.RequestMessage): p.Message {
10591059
params: reqParams
10601060
}
10611061

1062-
if (command === "rescriptls/open-compiled-file") {
1062+
if (command === ExecuteCommands.OpenCompiledFile) {
10631063
let message = openCompiledFile({ ...msg, params: { uri } })
10641064
if (p.Message.isResponse(message)) {
10651065
let { uri } = message.result as p.TextDocumentIdentifier
@@ -1068,7 +1068,7 @@ function executeCommand(msg: p.RequestMessage): p.Message {
10681068
} else {
10691069
send(message)
10701070
}
1071-
} else if (command === "rescriptls/create-interface-file") {
1071+
} else if (command === ExecuteCommands.CreateInterfaceFile) {
10721072
let message = createInterface({ ...msg, params: { uri } })
10731073
if (p.Message.isResponse(message)) {
10741074
let { uri } = message.result as p.TextDocumentIdentifier
@@ -1077,9 +1077,9 @@ function executeCommand(msg: p.RequestMessage): p.Message {
10771077
} else {
10781078
send(message)
10791079
}
1080-
} else if (command === "rescriptls/open-interface-file") {
1080+
} else if (command === ExecuteCommands.OpenInterfaceFile) {
10811081
send(request);
1082-
} else if (command === "rescriptls/open-implementation-file") {
1082+
} else if (command === ExecuteCommands.OpenImplentationFile) {
10831083
send(request);
10841084
}
10851085

@@ -1188,7 +1188,7 @@ function onMessage(msg: p.Message) {
11881188
resolveProvider: true,
11891189
},
11901190
executeCommandProvider: {
1191-
commands: executeCommands
1191+
commands: [ExecuteCommands.OpenImplentationFile, ExecuteCommands.OpenInterfaceFile, ExecuteCommands.OpenCompiledFile, ExecuteCommands.CreateInterfaceFile]
11921192
},
11931193
semanticTokensProvider: {
11941194
legend: {

0 commit comments

Comments
 (0)