File tree 4 files changed +31
-7
lines changed
crates/ide-completion/src
4 files changed +31
-7
lines changed Original file line number Diff line number Diff line change @@ -62,21 +62,20 @@ pub(crate) fn complete_expr_path(
62
62
in_condition,
63
63
incomplete_let,
64
64
ref ref_expr_parent,
65
+ after_amp,
65
66
ref is_func_update,
66
67
ref innermost_ret_ty,
67
68
ref impl_,
68
69
in_match_guard,
69
70
..
70
71
} = expr_ctx;
71
72
72
- let has_raw_token =
73
- ref_expr_parent. as_ref ( ) . map ( |it| it. raw_token ( ) . is_some ( ) ) . unwrap_or ( false ) ;
74
- let has_const_token =
75
- ref_expr_parent. as_ref ( ) . map ( |it| it. const_token ( ) . is_some ( ) ) . unwrap_or ( false ) ;
76
- let has_mut_token =
77
- ref_expr_parent. as_ref ( ) . map ( |it| it. mut_token ( ) . is_some ( ) ) . unwrap_or ( false ) ;
73
+ let ( has_raw_token, has_const_token, has_mut_token) = ref_expr_parent
74
+ . as_ref ( )
75
+ . map ( |it| ( it. raw_token ( ) . is_some ( ) , it. const_token ( ) . is_some ( ) , it. mut_token ( ) . is_some ( ) ) )
76
+ . unwrap_or ( ( false , false , false ) ) ;
78
77
79
- let wants_raw_token = ref_expr_parent. is_some ( ) && !has_raw_token;
78
+ let wants_raw_token = ref_expr_parent. is_some ( ) && !has_raw_token && after_amp ;
80
79
let wants_const_token =
81
80
ref_expr_parent. is_some ( ) && has_raw_token && !has_const_token && !has_mut_token;
82
81
let wants_mut_token = if ref_expr_parent. is_some ( ) {
Original file line number Diff line number Diff line change @@ -146,6 +146,7 @@ pub(crate) struct PathExprCtx {
146
146
pub ( crate ) in_condition : bool ,
147
147
pub ( crate ) incomplete_let : bool ,
148
148
pub ( crate ) ref_expr_parent : Option < ast:: RefExpr > ,
149
+ pub ( crate ) after_amp : bool ,
149
150
/// The surrounding RecordExpression we are completing a functional update
150
151
pub ( crate ) is_func_update : Option < ast:: RecordExpr > ,
151
152
pub ( crate ) self_param : Option < hir:: SelfParam > ,
Original file line number Diff line number Diff line change @@ -1151,6 +1151,9 @@ fn classify_name_ref(
1151
1151
let after_if_expr = after_if_expr ( it. clone ( ) ) ;
1152
1152
let ref_expr_parent =
1153
1153
path. as_single_name_ref ( ) . and_then ( |_| it. parent ( ) ) . and_then ( ast:: RefExpr :: cast) ;
1154
+ let after_amp = non_trivia_sibling ( it. clone ( ) . into ( ) , Direction :: Prev )
1155
+ . map ( |it| it. kind ( ) == SyntaxKind :: AMP )
1156
+ . unwrap_or ( false ) ;
1154
1157
let ( innermost_ret_ty, self_param) = {
1155
1158
let find_ret_ty = |it : SyntaxNode | {
1156
1159
if let Some ( item) = ast:: Item :: cast ( it. clone ( ) ) {
@@ -1220,6 +1223,7 @@ fn classify_name_ref(
1220
1223
after_if_expr,
1221
1224
in_condition,
1222
1225
ref_expr_parent,
1226
+ after_amp,
1223
1227
is_func_update,
1224
1228
innermost_ret_ty,
1225
1229
self_param,
Original file line number Diff line number Diff line change @@ -522,6 +522,26 @@ fn completes_after_ref_expr() {
522
522
kw while
523
523
kw while let
524
524
"# ] ] ,
525
+ ) ;
526
+ check (
527
+ r#"fn main() { let _ = &mut $0 }"# ,
528
+ expect ! [ [ r#"
529
+ fn main() fn()
530
+ bt u32 u32
531
+ kw crate::
532
+ kw false
533
+ kw for
534
+ kw if
535
+ kw if let
536
+ kw loop
537
+ kw match
538
+ kw return
539
+ kw self::
540
+ kw true
541
+ kw unsafe
542
+ kw while
543
+ kw while let
544
+ "# ] ] ,
525
545
)
526
546
}
527
547
You can’t perform that action at this time.
0 commit comments