File tree 1 file changed +10
-3
lines changed
crates/ra_assists/src/handlers
1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -47,8 +47,7 @@ fn add_vis(ctx: AssistCtx) -> Option<Assist> {
47
47
return None ;
48
48
}
49
49
( vis_offset ( & parent) , keyword. text_range ( ) )
50
- } else {
51
- let field_name: ast:: Name = ctx. find_node_at_offset ( ) ?;
50
+ } else if let Some ( field_name) = ctx. find_node_at_offset :: < ast:: Name > ( ) {
52
51
let field = field_name. syntax ( ) . ancestors ( ) . find_map ( ast:: RecordFieldDef :: cast) ?;
53
52
if field. name ( ) ? != field_name {
54
53
tested_by ! ( change_visibility_field_false_positive) ;
@@ -58,6 +57,13 @@ fn add_vis(ctx: AssistCtx) -> Option<Assist> {
58
57
return None ;
59
58
}
60
59
( vis_offset ( field. syntax ( ) ) , field_name. syntax ( ) . text_range ( ) )
60
+ } else if let Some ( field) = ctx. find_node_at_offset :: < ast:: TupleFieldDef > ( ) {
61
+ if field. visibility ( ) . is_some ( ) {
62
+ return None ;
63
+ }
64
+ ( vis_offset ( field. syntax ( ) ) , field. syntax ( ) . text_range ( ) )
65
+ } else {
66
+ return None ;
61
67
} ;
62
68
63
69
ctx. add_assist ( AssistId ( "change_visibility" ) , "Change visibility to pub(crate)" , |edit| {
@@ -129,7 +135,8 @@ mod tests {
129
135
change_visibility,
130
136
r"struct S { <|>field: u32 }" ,
131
137
r"struct S { <|>pub(crate) field: u32 }" ,
132
- )
138
+ ) ;
139
+ check_assist ( change_visibility, r"struct S ( <|>u32 )" , r"struct S ( <|>pub(crate) u32 )" ) ;
133
140
}
134
141
135
142
#[ test]
You can’t perform that action at this time.
0 commit comments