From 9353f36516e5b4026ce3a181d578c3a63876a18f Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Thu, 17 Jun 2021 13:59:31 +0200 Subject: Fix incorrect completions in empty braced use statement --- .../ide_completion/src/completions/unqualified_path.rs | 2 +- crates/ide_completion/src/context.rs | 4 ---- crates/ide_completion/src/tests/use_tree.rs | 17 +++++++++++++++++ 3 files changed, 18 insertions(+), 5 deletions(-) (limited to 'crates/ide_completion') diff --git a/crates/ide_completion/src/completions/unqualified_path.rs b/crates/ide_completion/src/completions/unqualified_path.rs index 4bafc1bf8..6f96eceb9 100644 --- a/crates/ide_completion/src/completions/unqualified_path.rs +++ b/crates/ide_completion/src/completions/unqualified_path.rs @@ -25,7 +25,7 @@ pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC return; } - if ctx.expects_new_use_tree() { + if ctx.in_use_tree() { // only show modules in a fresh UseTree cov_mark::hit!(only_completes_modules_in_import); ctx.scope.process_all_names(&mut |name, res| { diff --git a/crates/ide_completion/src/context.rs b/crates/ide_completion/src/context.rs index c3076f608..240cac1de 100644 --- a/crates/ide_completion/src/context.rs +++ b/crates/ide_completion/src/context.rs @@ -264,10 +264,6 @@ impl<'a> CompletionContext<'a> { } } - pub(crate) fn expects_new_use_tree(&self) -> bool { - matches!(self.completion_location, Some(ImmediateLocation::Use)) - } - pub(crate) fn expects_non_trait_assoc_item(&self) -> bool { matches!(self.completion_location, Some(ImmediateLocation::Impl)) } diff --git a/crates/ide_completion/src/tests/use_tree.rs b/crates/ide_completion/src/tests/use_tree.rs index 878bc42bf..7e6748ccc 100644 --- a/crates/ide_completion/src/tests/use_tree.rs +++ b/crates/ide_completion/src/tests/use_tree.rs @@ -236,3 +236,20 @@ pub use $0; "#]], ); } + +#[test] +fn use_tree_braces_at_start() { + check( + r#" +struct X; +mod bar {} +use {$0}; +"#, + expect![[r#" + kw crate:: + kw self:: + kw super:: + md bar + "#]], + ); +} -- cgit v1.2.3