Skip to content

Commit 3ca97b0

Browse files
bors[bot]matklad
andauthored
Merge #6277
6277: Change visibility works for type aliases r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
2 parents 886cfd6 + 604caed commit 3ca97b0

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

crates/assists/src/handlers/change_visibility.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use syntax::{
22
ast::{self, NameOwner, VisibilityOwner},
33
AstNode,
4-
SyntaxKind::{CONST, ENUM, FN, MODULE, STATIC, STRUCT, TRAIT, VISIBILITY},
4+
SyntaxKind::{CONST, ENUM, FN, MODULE, STATIC, STRUCT, TRAIT, TYPE_ALIAS, VISIBILITY},
55
T,
66
};
77
use test_utils::mark;
@@ -30,13 +30,20 @@ fn add_vis(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
3030
let item_keyword = ctx.token_at_offset().find(|leaf| {
3131
matches!(
3232
leaf.kind(),
33-
T![const] | T![static] | T![fn] | T![mod] | T![struct] | T![enum] | T![trait]
33+
T![const]
34+
| T![static]
35+
| T![fn]
36+
| T![mod]
37+
| T![struct]
38+
| T![enum]
39+
| T![trait]
40+
| T![type]
3441
)
3542
});
3643

3744
let (offset, target) = if let Some(keyword) = item_keyword {
3845
let parent = keyword.parent();
39-
let def_kws = vec![CONST, STATIC, FN, MODULE, STRUCT, ENUM, TRAIT];
46+
let def_kws = vec![CONST, STATIC, TYPE_ALIAS, FN, MODULE, STRUCT, ENUM, TRAIT];
4047
// Parent is not a definition, can't add visibility
4148
if !def_kws.iter().any(|&def_kw| def_kw == parent.kind()) {
4249
return None;
@@ -159,6 +166,11 @@ mod tests {
159166
check_assist(change_visibility, "<|>static FOO = 3u8;", "pub(crate) static FOO = 3u8;");
160167
}
161168

169+
#[test]
170+
fn change_visibility_type_alias() {
171+
check_assist(change_visibility, "<|>type T = ();", "pub(crate) type T = ();");
172+
}
173+
162174
#[test]
163175
fn change_visibility_handles_comment_attrs() {
164176
check_assist(

crates/assists/src/handlers/fix_visibility.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
use base_db::FileId;
22
use hir::{db::HirDatabase, HasSource, HasVisibility, PathResolution};
3-
use syntax::{ast, AstNode, TextRange, TextSize};
3+
use syntax::{
4+
ast::{self, VisibilityOwner},
5+
AstNode, TextRange, TextSize,
6+
};
47

58
use crate::{utils::vis_offset, AssistContext, AssistId, AssistKind, Assists};
6-
use ast::VisibilityOwner;
79

810
// FIXME: this really should be a fix for diagnostic, rather than an assist.
911

0 commit comments

Comments
 (0)