mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-04 19:29:07 +00:00
Don't complete visibility accessors after existing ones
This commit is contained in:
parent
d338a80394
commit
1a8f76a224
@ -75,7 +75,9 @@ pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte
|
||||
return;
|
||||
}
|
||||
|
||||
if expects_item || ctx.expects_non_trait_assoc_item() || ctx.expect_record_field() {
|
||||
if !ctx.has_visibility_prev_sibling()
|
||||
&& (expects_item || ctx.expects_non_trait_assoc_item() || ctx.expect_record_field())
|
||||
{
|
||||
add_keyword("pub(crate)", "pub(crate) ");
|
||||
add_keyword("pub", "pub ");
|
||||
}
|
||||
|
@ -302,6 +302,10 @@ impl<'a> CompletionContext<'a> {
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn has_visibility_prev_sibling(&self) -> bool {
|
||||
matches!(self.prev_sibling, Some(ImmediatePrevSibling::Visibility))
|
||||
}
|
||||
|
||||
pub(crate) fn after_if(&self) -> bool {
|
||||
matches!(self.prev_sibling, Some(ImmediatePrevSibling::IfExpr))
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ pub(crate) enum ImmediatePrevSibling {
|
||||
IfExpr,
|
||||
TraitDefName,
|
||||
ImplDefType,
|
||||
Visibility,
|
||||
}
|
||||
|
||||
/// Direct parent "thing" of what we are currently completing.
|
||||
@ -79,6 +80,17 @@ pub(crate) fn determine_prev_sibling(name_like: &ast::NameLike) -> Option<Immedi
|
||||
_ => node,
|
||||
};
|
||||
let prev_sibling = non_trivia_sibling(node.into(), Direction::Prev)?.into_node()?;
|
||||
if prev_sibling.kind() == ERROR {
|
||||
let prev_sibling = prev_sibling.first_child()?;
|
||||
let res = match_ast! {
|
||||
match prev_sibling {
|
||||
// vis followed by random ident will always error the parser
|
||||
ast::Visibility(_it) => ImmediatePrevSibling::Visibility,
|
||||
_ => return None,
|
||||
}
|
||||
};
|
||||
return Some(res);
|
||||
}
|
||||
let res = match_ast! {
|
||||
match prev_sibling {
|
||||
ast::ExprStmt(it) => {
|
||||
@ -421,4 +433,9 @@ mod tests {
|
||||
check_prev_sibling(r"fn foo() { if true {} w$0", ImmediatePrevSibling::IfExpr);
|
||||
check_prev_sibling(r"fn foo() { if true {}; w$0", None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_vis_prev_sibling() {
|
||||
check_prev_sibling(r"pub w$0", ImmediatePrevSibling::Visibility);
|
||||
}
|
||||
}
|
||||
|
@ -146,8 +146,6 @@ const CONST: () = ();
|
||||
|
||||
pub $0"#,
|
||||
expect![[r##"
|
||||
kw pub(crate)
|
||||
kw pub
|
||||
kw unsafe
|
||||
kw fn
|
||||
kw const
|
||||
|
Loading…
Reference in New Issue
Block a user