From e14f5cfff04942f45a4af3b45152df9672b3458a Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Thu, 17 Jun 2021 13:13:12 +0200 Subject: Move out and rewrite UseTree completion tests --- crates/ide_completion/src/completions/keyword.rs | 35 ------------------------ 1 file changed, 35 deletions(-) (limited to 'crates/ide_completion/src/completions/keyword.rs') diff --git a/crates/ide_completion/src/completions/keyword.rs b/crates/ide_completion/src/completions/keyword.rs index 73bbc4345..b6f06a44f 100644 --- a/crates/ide_completion/src/completions/keyword.rs +++ b/crates/ide_completion/src/completions/keyword.rs @@ -199,41 +199,6 @@ mod tests { expect.assert_eq(&actual) } - #[test] - fn test_keywords_in_use_stmt() { - check( - r"use $0", - expect![[r#" - kw crate:: - kw self - kw super:: - "#]], - ); - - // FIXME: `self` shouldn't be shown here and the check below - check( - r"use a::$0", - expect![[r#" - kw self - "#]], - ); - - check( - r"use super::$0", - expect![[r#" - kw self - kw super:: - "#]], - ); - - check( - r"use a::{b, $0}", - expect![[r#" - kw self - "#]], - ); - } - #[test] fn test_keywords_in_function() { check( -- cgit v1.2.3 From 2225db2eb48bd8c8fdf399c50652d3f95c851ace Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Thu, 17 Jun 2021 13:56:55 +0200 Subject: Refine `self`, `super` and `crate` completion in use paths --- crates/ide_completion/src/completions/keyword.rs | 29 +++++++++++++++--------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'crates/ide_completion/src/completions/keyword.rs') diff --git a/crates/ide_completion/src/completions/keyword.rs b/crates/ide_completion/src/completions/keyword.rs index b6f06a44f..9754122a0 100644 --- a/crates/ide_completion/src/completions/keyword.rs +++ b/crates/ide_completion/src/completions/keyword.rs @@ -18,17 +18,24 @@ pub(crate) fn complete_use_tree_keyword(acc: &mut Completions, ctx: &CompletionC item }; - if ctx.use_item_syntax.is_some() { - let qual = ctx.path_qual(); - if qual.is_none() { - kw_completion("crate::").add_to(acc); - } - kw_completion("self").add_to(acc); - if iter::successors(qual.cloned(), |p| p.qualifier()) - .all(|p| p.segment().and_then(|s| s.super_token()).is_some()) - { - kw_completion("super::").add_to(acc); - } + if ctx.in_use_tree() { + match &ctx.path_context { + Some(PathCompletionContext { qualifier: Some(qual), use_tree_parent, .. }) => { + if iter::successors(Some(qual.clone()), |p| p.qualifier()) + .all(|p| p.segment().and_then(|s| s.super_token()).is_some()) + { + kw_completion("super::").add_to(acc); + } + if *use_tree_parent { + kw_completion("self").add_to(acc); + } + } + _ => { + kw_completion("crate::").add_to(acc); + kw_completion("self::").add_to(acc); + kw_completion("super::").add_to(acc); + } + }; } // Suggest .await syntax for types that implement Future trait -- cgit v1.2.3