From 34a7e4fbafe34265563c7c27aadc524d094cf129 Mon Sep 17 00:00:00 2001 From: Douglas Campos Date: Fri, 28 Feb 2020 01:15:17 +0000 Subject: introduce const visibility assist --- crates/ra_assists/src/handlers/change_visibility.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'crates/ra_assists/src/handlers') 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::{ ast::{self, NameOwner, VisibilityOwner}, AstNode, SyntaxKind::{ - ATTR, COMMENT, ENUM_DEF, FN_DEF, IDENT, MODULE, STRUCT_DEF, TRAIT_DEF, VISIBILITY, - WHITESPACE, + ATTR, COMMENT, CONST_DEF, ENUM_DEF, FN_DEF, IDENT, MODULE, STRUCT_DEF, TRAIT_DEF, + VISIBILITY, WHITESPACE, }, SyntaxNode, TextUnit, T, }; @@ -30,13 +30,13 @@ pub(crate) fn change_visibility(ctx: AssistCtx) -> Option { fn add_vis(ctx: AssistCtx) -> Option { let item_keyword = ctx.token_at_offset().find(|leaf| match leaf.kind() { - T![fn] | T![mod] | T![struct] | T![enum] | T![trait] => true, + T![const] | T![fn] | T![mod] | T![struct] | T![enum] | T![trait] => true, _ => false, }); let (offset, target) = if let Some(keyword) = item_keyword { let parent = keyword.parent(); - let def_kws = vec![FN_DEF, MODULE, STRUCT_DEF, ENUM_DEF, TRAIT_DEF]; + let def_kws = vec![CONST_DEF, FN_DEF, MODULE, STRUCT_DEF, ENUM_DEF, TRAIT_DEF]; // Parent is not a definition, can't add visibility if !def_kws.iter().any(|&def_kw| def_kw == parent.kind()) { return None; @@ -135,6 +135,11 @@ mod tests { check_assist(change_visibility, "<|>pub(crate) fn foo() {}", "<|>pub fn foo() {}") } + #[test] + fn change_visibility_const() { + check_assist(change_visibility, "<|>const FOO = 3u8;", "<|>pub(crate) const FOO = 3u8;"); + } + #[test] fn change_visibility_handles_comment_attrs() { check_assist( -- cgit v1.2.3