From 604caedeb2f9c72566147c780383dc9895a2e6f5 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 18 Oct 2020 17:04:12 +0200 Subject: Change visibility works for type aliases --- crates/assists/src/handlers/change_visibility.rs | 18 +++++++++++++++--- crates/assists/src/handlers/fix_visibility.rs | 6 ++++-- 2 files changed, 19 insertions(+), 5 deletions(-) (limited to 'crates/assists/src/handlers') diff --git a/crates/assists/src/handlers/change_visibility.rs b/crates/assists/src/handlers/change_visibility.rs index 32dc05378..22d7c95d9 100644 --- a/crates/assists/src/handlers/change_visibility.rs +++ b/crates/assists/src/handlers/change_visibility.rs @@ -1,7 +1,7 @@ use syntax::{ ast::{self, NameOwner, VisibilityOwner}, AstNode, - SyntaxKind::{CONST, ENUM, FN, MODULE, STATIC, STRUCT, TRAIT, VISIBILITY}, + SyntaxKind::{CONST, ENUM, FN, MODULE, STATIC, STRUCT, TRAIT, TYPE_ALIAS, VISIBILITY}, T, }; use test_utils::mark; @@ -30,13 +30,20 @@ fn add_vis(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { let item_keyword = ctx.token_at_offset().find(|leaf| { matches!( leaf.kind(), - T![const] | T![static] | T![fn] | T![mod] | T![struct] | T![enum] | T![trait] + T![const] + | T![static] + | T![fn] + | T![mod] + | T![struct] + | T![enum] + | T![trait] + | T![type] ) }); let (offset, target) = if let Some(keyword) = item_keyword { let parent = keyword.parent(); - let def_kws = vec![CONST, STATIC, FN, MODULE, STRUCT, ENUM, TRAIT]; + let def_kws = vec![CONST, STATIC, TYPE_ALIAS, FN, MODULE, STRUCT, ENUM, TRAIT]; // Parent is not a definition, can't add visibility if !def_kws.iter().any(|&def_kw| def_kw == parent.kind()) { return None; @@ -159,6 +166,11 @@ mod tests { check_assist(change_visibility, "<|>static FOO = 3u8;", "pub(crate) static FOO = 3u8;"); } + #[test] + fn change_visibility_type_alias() { + check_assist(change_visibility, "<|>type T = ();", "pub(crate) type T = ();"); + } + #[test] fn change_visibility_handles_comment_attrs() { check_assist( diff --git a/crates/assists/src/handlers/fix_visibility.rs b/crates/assists/src/handlers/fix_visibility.rs index d505e9444..66f74150c 100644 --- a/crates/assists/src/handlers/fix_visibility.rs +++ b/crates/assists/src/handlers/fix_visibility.rs @@ -1,9 +1,11 @@ use base_db::FileId; use hir::{db::HirDatabase, HasSource, HasVisibility, PathResolution}; -use syntax::{ast, AstNode, TextRange, TextSize}; +use syntax::{ + ast::{self, VisibilityOwner}, + AstNode, TextRange, TextSize, +}; use crate::{utils::vis_offset, AssistContext, AssistId, AssistKind, Assists}; -use ast::VisibilityOwner; // FIXME: this really should be a fix for diagnostic, rather than an assist. -- cgit v1.2.3