File tree Expand file tree Collapse file tree 3 files changed +46
-0
lines changed Expand file tree Collapse file tree 3 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -7714,6 +7714,15 @@ impl<'a> UnwrapAnonymousFunction<'a> {
7714
7714
_ => return ,
7715
7715
}
7716
7716
7717
+ // We can't apply to functions with comments in (yet)
7718
+ if self
7719
+ . module
7720
+ . extra
7721
+ . has_comment_between ( location. start , location. end )
7722
+ {
7723
+ return ;
7724
+ }
7725
+
7717
7726
// We can only apply to anonymous functions containing a single function call
7718
7727
let [
7719
7728
TypedStatement :: Expression ( TypedExpr :: Call {
Original file line number Diff line number Diff line change @@ -9395,7 +9395,43 @@ fn op(first a, second b) {
9395
9395
) ;
9396
9396
}
9397
9397
9398
+ #[ test]
9399
+ fn dont_unwrap_anonymous_function_with_comment_after ( ) {
9400
+ assert_no_code_actions ! (
9401
+ UNWRAP_ANONYMOUS_FUNCTION ,
9402
+ "pub fn main() {
9403
+ fn(a) {
9404
+ op(a)
9405
+ // look out!
9406
+ }
9407
+ }
9408
+
9409
+ fn op(a) {
9410
+ todo
9411
+ }
9412
+ " ,
9413
+ find_position_of( "fn(a)" ) . to_selection( )
9414
+ ) ;
9415
+ }
9398
9416
9417
+ #[ test]
9418
+ fn dont_unwrap_anonymous_function_with_comment_before ( ) {
9419
+ assert_no_code_actions ! (
9420
+ UNWRAP_ANONYMOUS_FUNCTION ,
9421
+ "pub fn main() {
9422
+ fn(a) {
9423
+ // look out!
9424
+ op(a)
9425
+ }
9426
+ }
9427
+
9428
+ fn op(a) {
9429
+ todo
9430
+ }
9431
+ " ,
9432
+ find_position_of( "fn(a)" ) . to_selection( )
9433
+ ) ;
9434
+ }
9399
9435
9400
9436
#[ test]
9401
9437
fn unwrap_anonymous_function_unavailable_when_args_discarded ( ) {
Original file line number Diff line number Diff line change @@ -40,6 +40,7 @@ impl ModuleExtra {
40
40
self . first_comment_between ( start, end) . is_some ( )
41
41
}
42
42
43
+ // TODO: this won't necessarily find the first comment, just any comment
43
44
pub ( crate ) fn first_comment_between ( & self , start : u32 , end : u32 ) -> Option < SrcSpan > {
44
45
self . comments
45
46
. binary_search_by ( |comment| {
You can’t perform that action at this time.
0 commit comments