mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 05:45:12 +00:00
Move out completion type position tests
This commit is contained in:
parent
f835279b3a
commit
b9d85f55b7
5 changed files with 198 additions and 206 deletions
|
@ -218,36 +218,6 @@ mod tests {
|
||||||
expect.assert_eq(&actual);
|
expect.assert_eq(&actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn dont_complete_values_in_type_pos() {
|
|
||||||
check(
|
|
||||||
r#"
|
|
||||||
const FOO: () = ();
|
|
||||||
static BAR: () = ();
|
|
||||||
struct Baz;
|
|
||||||
fn foo() {
|
|
||||||
let _: self::$0;
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
expect![[r#"
|
|
||||||
st Baz
|
|
||||||
"#]],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn dont_complete_enum_variants_in_type_pos() {
|
|
||||||
check(
|
|
||||||
r#"
|
|
||||||
enum Foo { Bar }
|
|
||||||
fn foo() {
|
|
||||||
let _: Foo::$0;
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
expect![[r#""#]],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn dont_complete_primitive_in_use() {
|
fn dont_complete_primitive_in_use() {
|
||||||
check_builtin(r#"use self::$0;"#, expect![[""]]);
|
check_builtin(r#"use self::$0;"#, expect![[""]]);
|
||||||
|
@ -258,32 +228,6 @@ fn foo() {
|
||||||
check_builtin(r#"fn foo() { self::$0 }"#, expect![[""]]);
|
check_builtin(r#"fn foo() { self::$0 }"#, expect![[""]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn completes_primitives() {
|
|
||||||
check_builtin(
|
|
||||||
r#"fn main() { let _: $0 = 92; }"#,
|
|
||||||
expect![[r#"
|
|
||||||
bt u32
|
|
||||||
bt bool
|
|
||||||
bt u8
|
|
||||||
bt isize
|
|
||||||
bt u16
|
|
||||||
bt u64
|
|
||||||
bt u128
|
|
||||||
bt f32
|
|
||||||
bt i128
|
|
||||||
bt i16
|
|
||||||
bt str
|
|
||||||
bt i64
|
|
||||||
bt char
|
|
||||||
bt f64
|
|
||||||
bt i32
|
|
||||||
bt i8
|
|
||||||
bt usize
|
|
||||||
"#]],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn completes_enum_variant() {
|
fn completes_enum_variant() {
|
||||||
check(
|
check(
|
||||||
|
@ -749,24 +693,4 @@ fn main() {
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn completes_types_and_const_in_arg_list() {
|
|
||||||
check(
|
|
||||||
r#"
|
|
||||||
mod foo {
|
|
||||||
pub const CONST: () = ();
|
|
||||||
pub type Type = ();
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Foo<T>(t);
|
|
||||||
|
|
||||||
fn foo(_: Foo<foo::$0>) {}
|
|
||||||
"#,
|
|
||||||
expect![[r#"
|
|
||||||
ta Type
|
|
||||||
ct CONST
|
|
||||||
"#]],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,28 +112,6 @@ mod tests {
|
||||||
expect.assert_eq(&actual)
|
expect.assert_eq(&actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn dont_complete_values_in_type_pos() {
|
|
||||||
check(
|
|
||||||
r#"
|
|
||||||
const FOO: () = ();
|
|
||||||
static BAR: () = ();
|
|
||||||
enum Foo {
|
|
||||||
Bar
|
|
||||||
}
|
|
||||||
struct Baz;
|
|
||||||
fn foo() {
|
|
||||||
let local = ();
|
|
||||||
let _: $0;
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
expect![[r#"
|
|
||||||
en Foo
|
|
||||||
st Baz
|
|
||||||
"#]],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn completes_bindings_from_let() {
|
fn completes_bindings_from_let() {
|
||||||
check(
|
check(
|
||||||
|
@ -238,29 +216,6 @@ fn main() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn completes_generic_params_in_struct() {
|
|
||||||
check(
|
|
||||||
r#"struct S<T> { x: $0}"#,
|
|
||||||
expect![[r#"
|
|
||||||
sp Self
|
|
||||||
tp T
|
|
||||||
st S<…>
|
|
||||||
"#]],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn completes_self_in_enum() {
|
|
||||||
check(
|
|
||||||
r#"enum X { Y($0) }"#,
|
|
||||||
expect![[r#"
|
|
||||||
sp Self
|
|
||||||
en X
|
|
||||||
"#]],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn completes_module_items() {
|
fn completes_module_items() {
|
||||||
check(
|
check(
|
||||||
|
@ -314,19 +269,6 @@ mod m {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn completes_return_type() {
|
|
||||||
check(
|
|
||||||
r#"
|
|
||||||
struct Foo;
|
|
||||||
fn x() -> $0
|
|
||||||
"#,
|
|
||||||
expect![[r#"
|
|
||||||
st Foo
|
|
||||||
"#]],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn dont_show_both_completions_for_shadowing() {
|
fn dont_show_both_completions_for_shadowing() {
|
||||||
check(
|
check(
|
||||||
|
@ -508,19 +450,6 @@ fn foo() { $0 }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn completes_macros_as_type() {
|
|
||||||
check(
|
|
||||||
r#"
|
|
||||||
macro_rules! foo { () => {} }
|
|
||||||
fn main() { let x: $0 }
|
|
||||||
"#,
|
|
||||||
expect![[r#"
|
|
||||||
ma foo!(…) macro_rules! foo
|
|
||||||
"#]],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn completes_macros_as_stmt() {
|
fn completes_macros_as_stmt() {
|
||||||
check(
|
check(
|
||||||
|
@ -666,30 +595,4 @@ fn f() {}
|
||||||
expect![[""]],
|
expect![[""]],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn completes_types_and_const_in_arg_list() {
|
|
||||||
check(
|
|
||||||
r#"
|
|
||||||
enum Bar {
|
|
||||||
Baz
|
|
||||||
}
|
|
||||||
trait Foo {
|
|
||||||
type Bar;
|
|
||||||
}
|
|
||||||
|
|
||||||
const CONST: () = ();
|
|
||||||
|
|
||||||
fn foo<T: Foo<$0>, const CONST_PARAM: usize>(_: T) {}
|
|
||||||
"#,
|
|
||||||
expect![[r#"
|
|
||||||
ta Bar = type Bar;
|
|
||||||
tp T
|
|
||||||
cp CONST_PARAM
|
|
||||||
tt Foo
|
|
||||||
en Bar
|
|
||||||
ct CONST
|
|
||||||
"#]],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,9 @@ mod item_list;
|
||||||
mod use_tree;
|
mod use_tree;
|
||||||
mod items;
|
mod items;
|
||||||
mod pattern;
|
mod pattern;
|
||||||
|
mod type_pos;
|
||||||
|
|
||||||
|
use std::mem;
|
||||||
|
|
||||||
use hir::{PrefixKind, Semantics};
|
use hir::{PrefixKind, Semantics};
|
||||||
use ide_db::{
|
use ide_db::{
|
||||||
|
@ -46,7 +49,16 @@ pub(crate) fn completion_list(code: &str) -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn completion_list_with_config(config: CompletionConfig, code: &str) -> String {
|
fn completion_list_with_config(config: CompletionConfig, code: &str) -> String {
|
||||||
render_completion_list(get_all_items(config, code))
|
// filter out all but one builtintype completion for smaller test outputs
|
||||||
|
let items = get_all_items(config, code);
|
||||||
|
let mut bt_seen = false;
|
||||||
|
let items = items
|
||||||
|
.into_iter()
|
||||||
|
.filter(|it| {
|
||||||
|
it.completion_kind != CompletionKind::BuiltinType || !mem::replace(&mut bt_seen, true)
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
render_completion_list(items)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates analysis from a multi-file fixture, returns positions marked with $0.
|
/// Creates analysis from a multi-file fixture, returns positions marked with $0.
|
||||||
|
|
|
@ -35,22 +35,6 @@ impl Tra$0
|
||||||
ma foo!(…) #[macro_export] macro_rules! foo
|
ma foo!(…) #[macro_export] macro_rules! foo
|
||||||
ma foo!(…) #[macro_export] macro_rules! foo
|
ma foo!(…) #[macro_export] macro_rules! foo
|
||||||
bt u32
|
bt u32
|
||||||
bt bool
|
|
||||||
bt u8
|
|
||||||
bt isize
|
|
||||||
bt u16
|
|
||||||
bt u64
|
|
||||||
bt u128
|
|
||||||
bt f32
|
|
||||||
bt i128
|
|
||||||
bt i16
|
|
||||||
bt str
|
|
||||||
bt i64
|
|
||||||
bt char
|
|
||||||
bt f64
|
|
||||||
bt i32
|
|
||||||
bt i8
|
|
||||||
bt usize
|
|
||||||
"##]],
|
"##]],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -69,22 +53,6 @@ impl Trait for Str$0
|
||||||
ma foo!(…) #[macro_export] macro_rules! foo
|
ma foo!(…) #[macro_export] macro_rules! foo
|
||||||
ma foo!(…) #[macro_export] macro_rules! foo
|
ma foo!(…) #[macro_export] macro_rules! foo
|
||||||
bt u32
|
bt u32
|
||||||
bt bool
|
|
||||||
bt u8
|
|
||||||
bt isize
|
|
||||||
bt u16
|
|
||||||
bt u64
|
|
||||||
bt u128
|
|
||||||
bt f32
|
|
||||||
bt i128
|
|
||||||
bt i16
|
|
||||||
bt str
|
|
||||||
bt i64
|
|
||||||
bt char
|
|
||||||
bt f64
|
|
||||||
bt i32
|
|
||||||
bt i8
|
|
||||||
bt usize
|
|
||||||
"##]],
|
"##]],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
185
crates/ide_completion/src/tests/type_pos.rs
Normal file
185
crates/ide_completion/src/tests/type_pos.rs
Normal file
|
@ -0,0 +1,185 @@
|
||||||
|
//! Completions tests for type position.
|
||||||
|
use expect_test::{expect, Expect};
|
||||||
|
|
||||||
|
use crate::tests::completion_list;
|
||||||
|
|
||||||
|
fn check_with(ra_fixture: &str, expect: Expect) {
|
||||||
|
let base = r#"
|
||||||
|
enum Enum { TupleV(u32), RecordV { field: u32 }, UnitV }
|
||||||
|
use self::Enum::TupleV;
|
||||||
|
mod module {}
|
||||||
|
|
||||||
|
trait Trait {}
|
||||||
|
static STATIC: Unit = Unit;
|
||||||
|
const CONST: Unit = Unit;
|
||||||
|
struct Record { field: u32 }
|
||||||
|
struct Tuple(u32);
|
||||||
|
struct Unit
|
||||||
|
macro_rules! makro {}
|
||||||
|
"#;
|
||||||
|
let actual = completion_list(&format!("{}\n{}", base, ra_fixture));
|
||||||
|
expect.assert_eq(&actual)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[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#"
|
||||||
|
kw pub(crate)
|
||||||
|
kw pub
|
||||||
|
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() {
|
||||||
|
// 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
|
||||||
|
st Record
|
||||||
|
st Tuple
|
||||||
|
md module
|
||||||
|
st Unit
|
||||||
|
ma makro!(…) macro_rules! makro
|
||||||
|
bt u32
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn body_type_pos() {
|
||||||
|
// FIXME: return shouldnt show up here
|
||||||
|
check_with(
|
||||||
|
r#"
|
||||||
|
fn foo<'lt, T, const C: usize>() {
|
||||||
|
let local = ();
|
||||||
|
let _: $0;
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
kw return
|
||||||
|
tp T
|
||||||
|
tt Trait
|
||||||
|
en Enum
|
||||||
|
st Record
|
||||||
|
st Tuple
|
||||||
|
md module
|
||||||
|
st Unit
|
||||||
|
ma makro!(…) macro_rules! makro
|
||||||
|
bt u32
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
check_with(
|
||||||
|
r#"
|
||||||
|
fn foo<'lt, T, const C: usize>() {
|
||||||
|
let local = ();
|
||||||
|
let _: self::$0;
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
tt Trait
|
||||||
|
en Enum
|
||||||
|
st Record
|
||||||
|
st Tuple
|
||||||
|
md module
|
||||||
|
st Unit
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[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#"
|
||||||
|
trait Trait2 {
|
||||||
|
type Foo;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn foo<'lt, T: Trait2<$0>, const CONST_PARAM: usize>(_: T) {}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
kw return
|
||||||
|
ta Foo = type Foo;
|
||||||
|
tp T
|
||||||
|
cp CONST_PARAM
|
||||||
|
tt Trait
|
||||||
|
en Enum
|
||||||
|
st Record
|
||||||
|
st Tuple
|
||||||
|
tt Trait2
|
||||||
|
md module
|
||||||
|
st Unit
|
||||||
|
ct CONST
|
||||||
|
ma makro!(…) macro_rules! makro
|
||||||
|
bt u32
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
check_with(
|
||||||
|
r#"
|
||||||
|
trait Trait2 {
|
||||||
|
type Foo;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn foo<'lt, T: Trait2<self::$0>, const CONST_PARAM: usize>(_: T) {}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
tt Trait
|
||||||
|
en Enum
|
||||||
|
st Record
|
||||||
|
st Tuple
|
||||||
|
tt Trait2
|
||||||
|
md module
|
||||||
|
st Unit
|
||||||
|
ct CONST
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue