Skip to content

Commit 6a3d96c

Browse files
committed
exclude functions with capture holes
The existing Expand Function Capture refactor does this.
1 parent 6cf6c94 commit 6a3d96c

3 files changed

Lines changed: 28 additions & 47 deletions

File tree

compiler-core/src/language_server/code_action.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10039,9 +10039,10 @@ impl<'ast> ast::visit::Visit<'ast> for WrapInAnonymousFunction<'ast> {
1003910039
return;
1004010040
}
1004110041

10042-
let is_excluded = match expression {
10043-
TypedExpr::Fn { kind, .. } if kind.is_anonymous() => true,
10044-
_ => false,
10042+
let is_excluded = if let TypedExpr::Fn { kind, .. } = expression {
10043+
kind.is_anonymous() || kind.is_capture()
10044+
} else {
10045+
false
1004510046
};
1004610047

1004710048
if let Type::Fn { arguments, .. } = &*expression.type_()
@@ -10204,7 +10205,7 @@ impl<'a> UnwrapAnonymousFunction<'a> {
1020410205
TypedStatement::Expression(TypedExpr::Call {
1020510206
location: call_location,
1020610207
arguments: call_arguments,
10207-
arguments_start: Some(arguments_start),
10208+
fun: &fun,
1020810209
..
1020910210
}),
1021010211
] = body.as_slice()

compiler-core/src/language_server/tests/action.rs

Lines changed: 22 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7035,6 +7035,28 @@ pub fn add(n, m) { n + m }
70357035
);
70367036
}
70377037

7038+
#[test]
7039+
fn expand_function_capture_in_pipeline() {
7040+
assert_code_action!(
7041+
EXPAND_FUNCTION_CAPTURE,
7042+
"pub fn main() {
7043+
1 |> wibble(2, _) |> wobble
7044+
}
7045+
7046+
fn wibble(a, b) {
7047+
todo
7048+
}
7049+
7050+
fn wobble(i) {
7051+
todo
7052+
}
7053+
7054+
",
7055+
find_position_of("wibble").to_selection()
7056+
);
7057+
}
7058+
7059+
70387060
#[test]
70397061
fn generate_dynamic_decoder() {
70407062
assert_code_action!(
@@ -11715,48 +11737,6 @@ fn wobble(i) {
1171511737
);
1171611738
}
1171711739

11718-
#[test]
11719-
fn wrap_multiargument_pipeline_step_in_anonymous_function() {
11720-
assert_code_action!(
11721-
WRAP_IN_ANONYMOUS_FUNCTION,
11722-
"pub fn main() {
11723-
1 |> wibble(2) |> wobble
11724-
}
11725-
11726-
fn wibble(a, b) {
11727-
todo
11728-
}
11729-
11730-
fn wobble(i) {
11731-
todo
11732-
}
11733-
11734-
",
11735-
find_position_of("wibble").to_selection()
11736-
);
11737-
}
11738-
11739-
#[test]
11740-
fn wrap_capturing_pipeline_step_in_anonymous_function() {
11741-
assert_code_action!(
11742-
WRAP_IN_ANONYMOUS_FUNCTION,
11743-
"pub fn main() {
11744-
1 |> wibble(2, _) |> wobble
11745-
}
11746-
11747-
fn wibble(a, b) {
11748-
todo
11749-
}
11750-
11751-
fn wobble(i) {
11752-
todo
11753-
}
11754-
11755-
",
11756-
find_position_of("wibble").to_selection()
11757-
);
11758-
}
11759-
1176011740
#[test]
1176111741
fn wrap_final_pipeline_step_in_anonymous_function() {
1176211742
assert_code_action!(

compiler-core/src/language_server/tests/snapshots/gleam_core__language_server__tests__action__wrap_capturing_pipeline_step_in_anonymous_function.snap renamed to compiler-core/src/language_server/tests/snapshots/gleam_core__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) {

0 commit comments

Comments
 (0)