Skip to content

Commit a796a46

Browse files
bors[bot]matklad
andauthored
Merge #5328
5328: change vis works on statics r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
2 parents 49fbd1b + d9fd7ca commit a796a46

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

crates/ra_assists/src/handlers/change_visibility.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use ra_syntax::{
22
ast::{self, NameOwner, VisibilityOwner},
33
AstNode,
4-
SyntaxKind::{CONST_DEF, ENUM_DEF, FN_DEF, MODULE, STRUCT_DEF, TRAIT_DEF, VISIBILITY},
4+
SyntaxKind::{
5+
CONST_DEF, ENUM_DEF, FN_DEF, MODULE, STATIC_DEF, STRUCT_DEF, TRAIT_DEF, VISIBILITY,
6+
},
57
T,
68
};
79
use test_utils::mark;
@@ -28,12 +30,15 @@ pub(crate) fn change_visibility(acc: &mut Assists, ctx: &AssistContext) -> Optio
2830

2931
fn add_vis(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
3032
let item_keyword = ctx.token_at_offset().find(|leaf| {
31-
matches!(leaf.kind(), T![const] | T![fn] | T![mod] | T![struct] | T![enum] | T![trait])
33+
matches!(
34+
leaf.kind(),
35+
T![const] | T![static] | T![fn] | T![mod] | T![struct] | T![enum] | T![trait]
36+
)
3237
});
3338

3439
let (offset, target) = if let Some(keyword) = item_keyword {
3540
let parent = keyword.parent();
36-
let def_kws = vec![CONST_DEF, FN_DEF, MODULE, STRUCT_DEF, ENUM_DEF, TRAIT_DEF];
41+
let def_kws = vec![CONST_DEF, STATIC_DEF, FN_DEF, MODULE, STRUCT_DEF, ENUM_DEF, TRAIT_DEF];
3742
// Parent is not a definition, can't add visibility
3843
if !def_kws.iter().any(|&def_kw| def_kw == parent.kind()) {
3944
return None;
@@ -151,6 +156,11 @@ mod tests {
151156
check_assist(change_visibility, "<|>const FOO = 3u8;", "pub(crate) const FOO = 3u8;");
152157
}
153158

159+
#[test]
160+
fn change_visibility_static() {
161+
check_assist(change_visibility, "<|>static FOO = 3u8;", "pub(crate) static FOO = 3u8;");
162+
}
163+
154164
#[test]
155165
fn change_visibility_handles_comment_attrs() {
156166
check_assist(

0 commit comments

Comments
 (0)