diff options
Diffstat (limited to 'crates/ra_assists')
-rw-r--r-- | crates/ra_assists/src/handlers/change_visibility.rs | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/crates/ra_assists/src/handlers/change_visibility.rs b/crates/ra_assists/src/handlers/change_visibility.rs index f325b6f92..54e0a6c84 100644 --- a/crates/ra_assists/src/handlers/change_visibility.rs +++ b/crates/ra_assists/src/handlers/change_visibility.rs | |||
@@ -2,8 +2,8 @@ use ra_syntax::{ | |||
2 | ast::{self, NameOwner, VisibilityOwner}, | 2 | ast::{self, NameOwner, VisibilityOwner}, |
3 | AstNode, | 3 | AstNode, |
4 | SyntaxKind::{ | 4 | SyntaxKind::{ |
5 | ATTR, COMMENT, ENUM_DEF, FN_DEF, IDENT, MODULE, STRUCT_DEF, TRAIT_DEF, VISIBILITY, | 5 | ATTR, COMMENT, CONST_DEF, ENUM_DEF, FN_DEF, IDENT, MODULE, STRUCT_DEF, TRAIT_DEF, |
6 | WHITESPACE, | 6 | VISIBILITY, WHITESPACE, |
7 | }, | 7 | }, |
8 | SyntaxNode, TextUnit, T, | 8 | SyntaxNode, TextUnit, T, |
9 | }; | 9 | }; |
@@ -30,13 +30,13 @@ pub(crate) fn change_visibility(ctx: AssistCtx) -> Option<Assist> { | |||
30 | 30 | ||
31 | fn add_vis(ctx: AssistCtx) -> Option<Assist> { | 31 | fn add_vis(ctx: AssistCtx) -> Option<Assist> { |
32 | let item_keyword = ctx.token_at_offset().find(|leaf| match leaf.kind() { | 32 | let item_keyword = ctx.token_at_offset().find(|leaf| match leaf.kind() { |
33 | T![fn] | T![mod] | T![struct] | T![enum] | T![trait] => true, | 33 | T![const] | T![fn] | T![mod] | T![struct] | T![enum] | T![trait] => true, |
34 | _ => false, | 34 | _ => false, |
35 | }); | 35 | }); |
36 | 36 | ||
37 | let (offset, target) = if let Some(keyword) = item_keyword { | 37 | let (offset, target) = if let Some(keyword) = item_keyword { |
38 | let parent = keyword.parent(); | 38 | let parent = keyword.parent(); |
39 | let def_kws = vec![FN_DEF, MODULE, STRUCT_DEF, ENUM_DEF, TRAIT_DEF]; | 39 | let def_kws = vec![CONST_DEF, FN_DEF, MODULE, STRUCT_DEF, ENUM_DEF, TRAIT_DEF]; |
40 | // Parent is not a definition, can't add visibility | 40 | // Parent is not a definition, can't add visibility |
41 | if !def_kws.iter().any(|&def_kw| def_kw == parent.kind()) { | 41 | if !def_kws.iter().any(|&def_kw| def_kw == parent.kind()) { |
42 | return None; | 42 | return None; |
@@ -136,6 +136,11 @@ mod tests { | |||
136 | } | 136 | } |
137 | 137 | ||
138 | #[test] | 138 | #[test] |
139 | fn change_visibility_const() { | ||
140 | check_assist(change_visibility, "<|>const FOO = 3u8;", "<|>pub(crate) const FOO = 3u8;"); | ||
141 | } | ||
142 | |||
143 | #[test] | ||
139 | fn change_visibility_handles_comment_attrs() { | 144 | fn change_visibility_handles_comment_attrs() { |
140 | check_assist( | 145 | check_assist( |
141 | change_visibility, | 146 | change_visibility, |