diff --git a/crates/ide_completion/src/completions/dot.rs b/crates/ide_completion/src/completions/dot.rs index 286d7cb67c..d975405347 100644 --- a/crates/ide_completion/src/completions/dot.rs +++ b/crates/ide_completion/src/completions/dot.rs @@ -33,7 +33,7 @@ fn complete_undotted_self(acc: &mut Completions, ctx: &CompletionContext) { if !ctx.config.enable_self_on_the_fly { return; } - if !ctx.is_trivial_path() || ctx.is_path_disallowed() { + if !ctx.is_trivial_path() || ctx.is_path_disallowed() || !ctx.expects_expression() { return; } ctx.scope.process_all_names(&mut |name, def| { diff --git a/crates/ide_completion/src/tests.rs b/crates/ide_completion/src/tests.rs index 12008cf59c..89faa9526c 100644 --- a/crates/ide_completion/src/tests.rs +++ b/crates/ide_completion/src/tests.rs @@ -9,7 +9,7 @@ mod use_tree; mod items; mod pattern; mod type_pos; -mod where_clause; +mod predicate; use std::mem; diff --git a/crates/ide_completion/src/tests/predicate.rs b/crates/ide_completion/src/tests/predicate.rs new file mode 100644 index 0000000000..04ff08669d --- /dev/null +++ b/crates/ide_completion/src/tests/predicate.rs @@ -0,0 +1,142 @@ +//! Completion tests for predicates and bounds. +use expect_test::{expect, Expect}; + +use crate::tests::{completion_list, BASE_FIXTURE}; + +fn check(ra_fixture: &str, expect: Expect) { + let actual = completion_list(&format!("{}\n{}", BASE_FIXTURE, ra_fixture)); + expect.assert_eq(&actual) +} + +#[test] +fn predicate_start() { + // FIXME: `for` kw + check( + r#" +struct Foo<'lt, T, const C: usize> where $0 {} +"#, + expect![[r#" + tt Trait + en Enum + st Record + st Tuple + md module + st Foo<…> + st Unit + ma makro!(…) macro_rules! makro + bt u32 + "#]], + ); +} + +#[test] +fn bound_for_type_pred() { + // FIXME: only show traits, macros and modules + check( + r#" +struct Foo<'lt, T, const C: usize> where T: $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 bound_for_lifetime_pred() { + // FIXME: should only show lifetimes here + check( + r#" +struct Foo<'lt, T, const C: usize> where 'lt: $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 bound_for_for_pred() { + // FIXME: only show traits, macros and modules + check( + r#" +struct Foo<'lt, T, const C: usize> where for<'a> T: $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 param_list_for_for_pred() { + check( + r#" +struct Foo<'lt, T, const C: usize> where for<'a> $0 {} +"#, + expect![[r#" + tt Trait + en Enum + st Record + st Tuple + md module + st Foo<…> + st Unit + ma makro!(…) macro_rules! makro + bt u32 + "#]], + ); +} + +#[test] +fn pred_on_fn_in_impl() { + // FIXME: only show traits, macros and modules + check( + r#" +impl Record { + fn method(self) where $0 {} +} +"#, + expect![[r#" + sp Self + tt Trait + en Enum + st Record + st Tuple + md module + st Unit + ma makro!(…) macro_rules! makro + bt u32 + "#]], + ); +} diff --git a/crates/ide_completion/src/tests/where_clause.rs b/crates/ide_completion/src/tests/where_clause.rs deleted file mode 100644 index 0395cbf37a..0000000000 --- a/crates/ide_completion/src/tests/where_clause.rs +++ /dev/null @@ -1,12 +0,0 @@ -//! Completion tests for inside of where clauses. -//! -//! The parent of the where clause tends to bleed completions of itself into the where clause so this -//! has to be thoroughly tested. -use expect_test::{expect, Expect}; - -use crate::tests::completion_list; - -fn check(ra_fixture: &str, expect: Expect) { - let actual = completion_list(ra_fixture); - expect.assert_eq(&actual) -}