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 @@ -8411,6 +8411,15 @@ impl<'a> UnwrapAnonymousFunction<'a> {
8411
8411
_ => return ,
8412
8412
}
8413
8413
8414
+ // We can't apply to functions with comments in (yet)
8415
+ if self
8416
+ . module
8417
+ . extra
8418
+ . has_comment_between ( location. start , location. end )
8419
+ {
8420
+ return ;
8421
+ }
8422
+
8414
8423
// We can only apply to anonymous functions containing a single function call
8415
8424
let [
8416
8425
TypedStatement :: Expression ( TypedExpr :: Call {
Original file line number Diff line number Diff line change @@ -10059,7 +10059,43 @@ fn op(first a, second b) {
10059
10059
) ;
10060
10060
}
10061
10061
10062
+ #[ test]
10063
+ fn dont_unwrap_anonymous_function_with_comment_after ( ) {
10064
+ assert_no_code_actions ! (
10065
+ UNWRAP_ANONYMOUS_FUNCTION ,
10066
+ "pub fn main() {
10067
+ fn(a) {
10068
+ op(a)
10069
+ // look out!
10070
+ }
10071
+ }
10072
+
10073
+ fn op(a) {
10074
+ todo
10075
+ }
10076
+ " ,
10077
+ find_position_of( "fn(a)" ) . to_selection( )
10078
+ ) ;
10079
+ }
10062
10080
10081
+ #[ test]
10082
+ fn dont_unwrap_anonymous_function_with_comment_before ( ) {
10083
+ assert_no_code_actions ! (
10084
+ UNWRAP_ANONYMOUS_FUNCTION ,
10085
+ "pub fn main() {
10086
+ fn(a) {
10087
+ // look out!
10088
+ op(a)
10089
+ }
10090
+ }
10091
+
10092
+ fn op(a) {
10093
+ todo
10094
+ }
10095
+ " ,
10096
+ find_position_of( "fn(a)" ) . to_selection( )
10097
+ ) ;
10098
+ }
10063
10099
10064
10100
#[ test]
10065
10101
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