Skip to content

Commit 7c84782

Browse files
committed
exclude functions with capture holes
The existing Expand Function Capture refactor does this.
1 parent 711fe19 commit 7c84782

4 files changed

Lines changed: 26 additions & 78 deletions

language-server/src/code_action.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11087,9 +11087,10 @@ impl<'ast> ast::visit::Visit<'ast> for WrapInAnonymousFunction<'ast> {
1108711087
return;
1108811088
}
1108911089

11090-
let is_excluded = match expression {
11091-
TypedExpr::Fn { kind, .. } if kind.is_anonymous() => true,
11092-
_ => false,
11090+
let is_excluded = if let TypedExpr::Fn { kind, .. } = expression {
11091+
kind.is_anonymous() || kind.is_capture()
11092+
} else {
11093+
false
1109311094
};
1109411095

1109511096
if let Type::Fn { arguments, .. } = &*expression.type_()

language-server/src/tests/action.rs

Lines changed: 21 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7272,6 +7272,27 @@ pub fn add(n, m) { n + m }
72727272
);
72737273
}
72747274

7275+
#[test]
7276+
fn expand_function_capture_in_pipeline() {
7277+
assert_code_action!(
7278+
EXPAND_FUNCTION_CAPTURE,
7279+
"pub fn main() {
7280+
1 |> wibble(2, _) |> wobble
7281+
}
7282+
7283+
fn wibble(a, b) {
7284+
todo
7285+
}
7286+
7287+
fn wobble(i) {
7288+
todo
7289+
}
7290+
7291+
",
7292+
find_position_of("wibble").to_selection()
7293+
);
7294+
}
7295+
72757296
#[test]
72767297
fn generate_dynamic_decoder() {
72777298
assert_code_action!(
@@ -12546,48 +12567,6 @@ fn wobble(i) {
1254612567
);
1254712568
}
1254812569

12549-
#[test]
12550-
fn wrap_multiargument_pipeline_step_in_anonymous_function() {
12551-
assert_code_action!(
12552-
WRAP_IN_ANONYMOUS_FUNCTION,
12553-
"pub fn main() {
12554-
1 |> wibble(2) |> wobble
12555-
}
12556-
12557-
fn wibble(a, b) {
12558-
todo
12559-
}
12560-
12561-
fn wobble(i) {
12562-
todo
12563-
}
12564-
12565-
",
12566-
find_position_of("wibble").to_selection()
12567-
);
12568-
}
12569-
12570-
#[test]
12571-
fn wrap_capturing_pipeline_step_in_anonymous_function() {
12572-
assert_code_action!(
12573-
WRAP_IN_ANONYMOUS_FUNCTION,
12574-
"pub fn main() {
12575-
1 |> wibble(2, _) |> wobble
12576-
}
12577-
12578-
fn wibble(a, b) {
12579-
todo
12580-
}
12581-
12582-
fn wobble(i) {
12583-
todo
12584-
}
12585-
12586-
",
12587-
find_position_of("wibble").to_selection()
12588-
);
12589-
}
12590-
1259112570
#[test]
1259212571
fn wrap_final_pipeline_step_in_anonymous_function() {
1259312572
assert_code_action!(

language-server/src/tests/snapshots/gleam_language_server__tests__action__wrap_capturing_pipeline_step_in_anonymous_function.snap renamed to language-server/src/tests/snapshots/gleam_language_server__tests__action__expand_function_capture_in_pipeline.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fn wobble(i) {
2020

2121
----- AFTER ACTION
2222
pub fn main() {
23-
1 |> fn(int) { wibble(2, _)(int) } |> wobble
23+
1 |> fn(int) { wibble(2, int) } |> wobble
2424
}
2525

2626
fn wibble(a, b) {

language-server/src/tests/snapshots/gleam_language_server__tests__action__wrap_multiargument_pipeline_step_in_anonymous_function.snap

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)