Skip to content

Commit 9ff8e58

Browse files
committed
exclude functions with capture holes
The existing Expand Function Capture refactor does this.
1 parent 6903d4e commit 9ff8e58

3 files changed

Lines changed: 26 additions & 46 deletions

File tree

compiler-core/src/language_server/code_action.rs

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

10057-
let is_excluded = match expression {
10058-
TypedExpr::Fn { kind, .. } if kind.is_anonymous() => true,
10059-
_ => false,
10057+
let is_excluded = if let TypedExpr::Fn { kind, .. } = expression {
10058+
kind.is_anonymous() || kind.is_capture()
10059+
} else {
10060+
false
1006010061
};
1006110062

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

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

Lines changed: 21 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7035,6 +7035,27 @@ 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+
70387059
#[test]
70397060
fn generate_dynamic_decoder() {
70407061
assert_code_action!(
@@ -11715,48 +11736,6 @@ fn wobble(i) {
1171511736
);
1171611737
}
1171711738

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-
1176011739
#[test]
1176111740
fn wrap_final_pipeline_step_in_anonymous_function() {
1176211741
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)