File tree Expand file tree Collapse file tree 4 files changed +71
-7
lines changed
compiler-core/src/language_server Expand file tree Collapse file tree 4 files changed +71
-7
lines changed Original file line number Diff line number Diff line change 8
8
extract a ` use ` expression.
9
9
([ Giacomo Cavalieri] ( https://github.com/giacomocavalieri ) )
10
10
11
+ - Fixed a bug where the "Extract function" code action would generate a function
12
+ with the wrong type when used on a use expression.
13
+ ([ Giacomo Cavalieri] ( https://github.com/giacomocavalieri ) )
14
+
11
15
## v1.13.0-rc1 - 2025-09-29
12
16
13
17
### Compiler
Original file line number Diff line number Diff line change @@ -8635,13 +8635,23 @@ impl<'a> ExtractFunction<'a> {
8635
8635
end,
8636
8636
)
8637
8637
}
8638
- ExtractedValue :: Expression ( expression) => self . extract_code_in_tail_position (
8639
- expression. location ( ) ,
8640
- expression. location ( ) ,
8641
- expression. type_ ( ) ,
8642
- extracted. parameters ,
8643
- end,
8644
- ) ,
8638
+ ExtractedValue :: Expression ( expression) => {
8639
+ let expression_type = match expression {
8640
+ TypedExpr :: Fn {
8641
+ type_,
8642
+ kind : FunctionLiteralKind :: Use { .. } ,
8643
+ ..
8644
+ } => type_. fn_types ( ) . expect ( "use callback to be a function" ) . 1 ,
8645
+ _ => expression. type_ ( ) ,
8646
+ } ;
8647
+ self . extract_code_in_tail_position (
8648
+ expression. location ( ) ,
8649
+ expression. location ( ) ,
8650
+ expression_type,
8651
+ extracted. parameters ,
8652
+ end,
8653
+ )
8654
+ }
8645
8655
ExtractedValue :: Statements {
8646
8656
location,
8647
8657
position : StatementPosition :: NotTail ,
Original file line number Diff line number Diff line change @@ -10571,3 +10571,22 @@ fn wibble(f: fn() -> Int) -> Int { f() }
10571
10571
) ;
10572
10572
}
10573
10573
10574
+ #[ test]
10575
+ fn extract_use_in_tail_position_2 ( ) {
10576
+ assert_code_action ! (
10577
+ EXTRACT_FUNCTION ,
10578
+ r#"
10579
+ pub fn main() {
10580
+ use <- wibble
10581
+ use <- wobble
10582
+ 123
10583
+ }
10584
+
10585
+ fn wibble(f: fn() -> Float) -> Float { f() }
10586
+ fn wobble(f: fn() -> Int) -> Float { 1.1 }
10587
+ "# ,
10588
+ find_position_of( "use" )
10589
+ . nth_occurrence( 2 )
10590
+ . select_until( find_position_of( "wobble" ) )
10591
+ ) ;
10592
+ }
Original file line number Diff line number Diff line change
1
+ -- -
2
+ source : compiler - core / src / language_server / tests / action .rs
3
+ expression : " \n pub fn main() {\n use <- wibble\n use <- wobble\n 123\n }\n\n fn wibble(f: fn() -> Float) -> Float { f() }\n fn wobble(f: fn() -> Int) -> Float { 1.1 }\n "
4
+ -- -
5
+ ---- - BEFORE ACTION
6
+
7
+ pub fn main () {
8
+ use < - wibble
9
+ use < - wobble
10
+ ▔▔▔▔▔▔▔↑
11
+ 123
12
+ }
13
+
14
+ fn wibble (f : fn () - > Float ) - > Float { f () }
15
+ fn wobble (f : fn () - > Int ) - > Float { 1.1 }
16
+
17
+
18
+ ---- - AFTER ACTION
19
+
20
+ pub fn main () {
21
+ use < - wibble
22
+ function ()
23
+ }
24
+
25
+ fn function () -> Float {
26
+ use < - wobble
27
+ 123
28
+ }
29
+
30
+ fn wibble (f : fn () - > Float ) - > Float { f () }
31
+ fn wobble (f : fn () - > Int ) - > Float { 1.1 }
You can’t perform that action at this time.
0 commit comments