mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-04 20:54:13 +00:00
Various keyword completion fixes
This commit is contained in:
parent
b9d85f55b7
commit
0729913525
@ -92,7 +92,7 @@ pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte
|
||||
}
|
||||
|
||||
if !ctx.has_visibility_prev_sibling()
|
||||
&& (expects_item || ctx.expects_non_trait_assoc_item() || ctx.expect_record_field())
|
||||
&& (expects_item || ctx.expects_non_trait_assoc_item() || ctx.expect_field())
|
||||
{
|
||||
add_keyword("pub(crate)", "pub(crate) ");
|
||||
add_keyword("pub", "pub ");
|
||||
@ -122,6 +122,10 @@ pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte
|
||||
add_keyword("union", "union $1 {\n $0\n}");
|
||||
}
|
||||
|
||||
if ctx.expects_type() {
|
||||
return;
|
||||
}
|
||||
|
||||
if ctx.expects_expression() {
|
||||
if !has_block_expr_parent {
|
||||
add_keyword("unsafe", "unsafe {\n $0\n}");
|
||||
|
@ -286,8 +286,11 @@ impl<'a> CompletionContext<'a> {
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn expect_record_field(&self) -> bool {
|
||||
matches!(self.completion_location, Some(ImmediateLocation::RecordField))
|
||||
pub(crate) fn expect_field(&self) -> bool {
|
||||
matches!(
|
||||
self.completion_location,
|
||||
Some(ImmediateLocation::RecordField | ImmediateLocation::TupleField)
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn in_use_tree(&self) -> bool {
|
||||
|
@ -31,6 +31,7 @@ pub(crate) enum ImmediateLocation {
|
||||
Impl,
|
||||
Trait,
|
||||
RecordField,
|
||||
TupleField,
|
||||
RefExpr,
|
||||
IdentPat,
|
||||
BlockExpr,
|
||||
@ -187,7 +188,13 @@ pub(crate) fn determine_location(
|
||||
ast::SourceFile(_it) => ImmediateLocation::ItemList,
|
||||
ast::ItemList(_it) => ImmediateLocation::ItemList,
|
||||
ast::RefExpr(_it) => ImmediateLocation::RefExpr,
|
||||
ast::RecordField(_it) => ImmediateLocation::RecordField,
|
||||
ast::RecordField(it) => if it.ty().map_or(false, |it| it.syntax().text_range().contains(offset)) {
|
||||
return None;
|
||||
} else {
|
||||
ImmediateLocation::RecordField
|
||||
},
|
||||
ast::TupleField(_it) => ImmediateLocation::TupleField,
|
||||
ast::TupleFieldList(_it) => ImmediateLocation::TupleField,
|
||||
ast::AssocItemList(it) => match it.syntax().parent().map(|it| it.kind()) {
|
||||
Some(IMPL) => ImmediateLocation::Impl,
|
||||
Some(TRAIT) => ImmediateLocation::Trait,
|
||||
|
@ -23,12 +23,33 @@ macro_rules! makro {}
|
||||
|
||||
#[test]
|
||||
fn record_field_ty() {
|
||||
// FIXME: pub shouldnt show up here
|
||||
check_with(
|
||||
r#"
|
||||
struct Foo<'lt, T, const C: usize> {
|
||||
f: $0
|
||||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
sp Self
|
||||
tp T
|
||||
tt Trait
|
||||
en Enum
|
||||
st Record
|
||||
st Tuple
|
||||
md module
|
||||
st Foo<…>
|
||||
st Unit
|
||||
ma makro!(…) macro_rules! makro
|
||||
bt u32
|
||||
"#]],
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tuple_struct_field() {
|
||||
check_with(
|
||||
r#"
|
||||
struct Foo<'lt, T, const C: usize>(f$0);
|
||||
"#,
|
||||
expect![[r#"
|
||||
kw pub(crate)
|
||||
@ -48,38 +69,13 @@ struct Foo<'lt, T, const C: usize> {
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tuple_struct_field() {
|
||||
// FIXME: pub should show up here
|
||||
check_with(
|
||||
r#"
|
||||
struct Foo<'lt, T, const C: usize>(f$0);
|
||||
"#,
|
||||
expect![[r#"
|
||||
sp Self
|
||||
tp T
|
||||
tt Trait
|
||||
en Enum
|
||||
st Record
|
||||
st Tuple
|
||||
md module
|
||||
st Foo<…>
|
||||
st Unit
|
||||
ma makro!(…) macro_rules! makro
|
||||
bt u32
|
||||
"#]],
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fn_return_type() {
|
||||
// FIXME: return shouldnt show up here
|
||||
check_with(
|
||||
r#"
|
||||
fn x<'lt, T, const C: usize>() -> $0
|
||||
"#,
|
||||
expect![[r#"
|
||||
kw return
|
||||
tp T
|
||||
tt Trait
|
||||
en Enum
|
||||
@ -95,7 +91,6 @@ fn x<'lt, T, const C: usize>() -> $0
|
||||
|
||||
#[test]
|
||||
fn body_type_pos() {
|
||||
// FIXME: return shouldnt show up here
|
||||
check_with(
|
||||
r#"
|
||||
fn foo<'lt, T, const C: usize>() {
|
||||
@ -104,7 +99,6 @@ fn foo<'lt, T, const C: usize>() {
|
||||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
kw return
|
||||
tp T
|
||||
tt Trait
|
||||
en Enum
|
||||
@ -136,7 +130,6 @@ fn foo<'lt, T, const C: usize>() {
|
||||
|
||||
#[test]
|
||||
fn completes_types_and_const_in_arg_list() {
|
||||
// FIXME: return shouldnt show up here
|
||||
// FIXME: we should complete the lifetime here for now
|
||||
check_with(
|
||||
r#"
|
||||
@ -147,7 +140,6 @@ trait Trait2 {
|
||||
fn foo<'lt, T: Trait2<$0>, const CONST_PARAM: usize>(_: T) {}
|
||||
"#,
|
||||
expect![[r#"
|
||||
kw return
|
||||
ta Foo = type Foo;
|
||||
tp T
|
||||
cp CONST_PARAM
|
||||
|
Loading…
Reference in New Issue
Block a user