diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-02-28 07:07:21 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-02-28 07:07:21 +0000 |
commit | 901edac5f13ba685f67a0f2fc45b84ae65697b8b (patch) | |
tree | 533915b3a5917c2ff71edde525f7a5602cc69e45 /crates/ra_assists/src/handlers | |
parent | e0c6e106d9909f34f1b8bbf2b18dee6ece47aa91 (diff) | |
parent | 34a7e4fbafe34265563c7c27aadc524d094cf129 (diff) |
Merge #3357
3357: introduce const visibility assist r=matklad a=qmx
this adds the same change visibility assist to `const` declarations too - as suggested by @matklad
Co-authored-by: Douglas Campos <[email protected]>
Diffstat (limited to 'crates/ra_assists/src/handlers')
-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, |