From 4c1a02288c2c46d98c048ef9007a82c11a3f855d Mon Sep 17 00:00:00 2001 From: Maan2003 Date: Fri, 11 Jun 2021 19:10:56 +0530 Subject: change visibility for use and macro items --- crates/ide_assists/src/handlers/change_visibility.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'crates') diff --git a/crates/ide_assists/src/handlers/change_visibility.rs b/crates/ide_assists/src/handlers/change_visibility.rs index d7e39b2ae..ed936667f 100644 --- a/crates/ide_assists/src/handlers/change_visibility.rs +++ b/crates/ide_assists/src/handlers/change_visibility.rs @@ -1,7 +1,9 @@ use syntax::{ ast::{self, NameOwner, VisibilityOwner}, AstNode, - SyntaxKind::{CONST, ENUM, FN, MODULE, STATIC, STRUCT, TRAIT, TYPE_ALIAS, VISIBILITY}, + SyntaxKind::{ + CONST, ENUM, FN, MACRO_DEF, MODULE, STATIC, STRUCT, TRAIT, TYPE_ALIAS, USE, VISIBILITY, + }, T, }; @@ -37,12 +39,15 @@ fn add_vis(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { | T![enum] | T![trait] | T![type] + | T![use] + | T![macro] ) }); let (offset, target) = if let Some(keyword) = item_keyword { let parent = keyword.parent()?; - let def_kws = vec![CONST, STATIC, TYPE_ALIAS, FN, MODULE, STRUCT, ENUM, TRAIT]; + let def_kws = + vec![CONST, STATIC, TYPE_ALIAS, FN, MODULE, STRUCT, ENUM, TRAIT, USE, MACRO_DEF]; // Parent is not a definition, can't add visibility if !def_kws.iter().any(|&def_kw| def_kw == parent.kind()) { return None; @@ -122,6 +127,8 @@ mod tests { check_assist(change_visibility, "$0trait Foo {}", "pub(crate) trait Foo {}"); check_assist(change_visibility, "m$0od {}", "pub(crate) mod {}"); check_assist(change_visibility, "unsafe f$0n foo() {}", "pub(crate) unsafe fn foo() {}"); + check_assist(change_visibility, "$0macro foo() {}", "pub(crate) macro foo() {}"); + check_assist(change_visibility, "$0use foo;", "pub(crate) use foo;"); } #[test] -- cgit v1.2.3