Skip to content

Commit 7d4fd44

Browse files
authored
fix(lsp): Correct use argument label code_action with inferred funcs (#2283)
1 parent 0d249dc commit 7d4fd44

File tree

2 files changed

+44
-9
lines changed

2 files changed

+44
-9
lines changed

compiler/src/language_server/code_action.re

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,16 @@ let rec process_explicit_type_annotation =
9696

9797
let rec process_named_arg_label = (uri, results: list(Sourcetree.node)) => {
9898
switch (results) {
99-
| [Argument({arg_label, label_specified, loc}), ..._] when !label_specified =>
99+
| [
100+
Argument({
101+
arg_label: Labeled({txt}) | Default({txt}),
102+
label_specified: false,
103+
loc,
104+
}),
105+
..._,
106+
] =>
100107
let loc = {...loc, loc_end: loc.loc_start};
101-
let arg_label =
102-
switch (arg_label) {
103-
| Unlabeled =>
104-
failwith("Impossible: unlabeled argument after typechecking")
105-
| Labeled({txt})
106-
| Default({txt}) => txt
107-
};
108-
Some(named_arg_label(Utils.loc_to_range(loc), uri, arg_label));
108+
Some(named_arg_label(Utils.loc_to_range(loc), uri, txt));
109109
| [_, ...rest] => process_named_arg_label(uri, rest)
110110
| _ => None
111111
};

compiler/test/suites/grainlsp.re

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,41 @@ f(x="x")
351351
`Null,
352352
);
353353

354+
assertLspOutput(
355+
"code_action_add_function_label_pattern",
356+
"file:///a.gr",
357+
{|module A
358+
let f = ((a, b)) => a + b
359+
f((1, 2))
360+
|},
361+
lsp_input(
362+
"textDocument/codeAction",
363+
`Assoc([
364+
("textDocument", `Assoc([("uri", `String("file:///a.gr"))])),
365+
("range", lsp_range((2, 2), (2, 2))),
366+
("context", `Assoc([("diagnostics", `List([]))])),
367+
]),
368+
),
369+
`Null,
370+
);
371+
372+
assertLspOutput(
373+
"code_action_add_function_inferred",
374+
"file:///a.gr",
375+
{|module A
376+
a => {a(1); void}
377+
|},
378+
lsp_input(
379+
"textDocument/codeAction",
380+
`Assoc([
381+
("textDocument", `Assoc([("uri", `String("file:///a.gr"))])),
382+
("range", lsp_range((1, 8), (1, 8))),
383+
("context", `Assoc([("diagnostics", `List([]))])),
384+
]),
385+
),
386+
`Null,
387+
);
388+
354389
assertLspOutput(
355390
"code_action_remove_function_block_braces_1",
356391
"file:///a.gr",

0 commit comments

Comments
 (0)