Skip to content

Commit 901edac

Browse files
bors[bot]qmx
andauthored
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]>
2 parents e0c6e10 + 34a7e4f commit 901edac

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

crates/ra_assists/src/handlers/change_visibility.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use ra_syntax::{
22
ast::{self, NameOwner, VisibilityOwner},
33
AstNode,
44
SyntaxKind::{
5-
ATTR, COMMENT, ENUM_DEF, FN_DEF, IDENT, MODULE, STRUCT_DEF, TRAIT_DEF, VISIBILITY,
6-
WHITESPACE,
5+
ATTR, COMMENT, CONST_DEF, ENUM_DEF, FN_DEF, IDENT, MODULE, STRUCT_DEF, TRAIT_DEF,
6+
VISIBILITY, WHITESPACE,
77
},
88
SyntaxNode, TextUnit, T,
99
};
@@ -30,13 +30,13 @@ pub(crate) fn change_visibility(ctx: AssistCtx) -> Option<Assist> {
3030

3131
fn add_vis(ctx: AssistCtx) -> Option<Assist> {
3232
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,
3434
_ => false,
3535
});
3636

3737
let (offset, target) = if let Some(keyword) = item_keyword {
3838
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];
4040
// Parent is not a definition, can't add visibility
4141
if !def_kws.iter().any(|&def_kw| def_kw == parent.kind()) {
4242
return None;
@@ -135,6 +135,11 @@ mod tests {
135135
check_assist(change_visibility, "<|>pub(crate) fn foo() {}", "<|>pub fn foo() {}")
136136
}
137137

138+
#[test]
139+
fn change_visibility_const() {
140+
check_assist(change_visibility, "<|>const FOO = 3u8;", "<|>pub(crate) const FOO = 3u8;");
141+
}
142+
138143
#[test]
139144
fn change_visibility_handles_comment_attrs() {
140145
check_assist(

0 commit comments

Comments
 (0)