From 7b20904e8b10a1e09cca684ac6677fc947261ec0 Mon Sep 17 00:00:00 2001 From: Tom Dohrmann Date: Wed, 21 Jul 2021 12:53:50 +0200 Subject: [PATCH] hide keyword suggestions in non trivial paths --- .../ide_completion/src/completions/keyword.rs | 4 ++++ crates/ide_completion/src/context.rs | 4 ++++ crates/ide_completion/src/tests/item_list.rs | 18 ++---------------- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/crates/ide_completion/src/completions/keyword.rs b/crates/ide_completion/src/completions/keyword.rs index ffa5b547add..72a8a5ebe1a 100644 --- a/crates/ide_completion/src/completions/keyword.rs +++ b/crates/ide_completion/src/completions/keyword.rs @@ -20,6 +20,10 @@ pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte cov_mark::hit!(no_keyword_completion_in_attr_of_expr); return; } + if ctx.is_non_trivial_path() { + cov_mark::hit!(no_keyword_completion_in_non_trivial_path); + return; + } // Suggest .await syntax for types that implement Future trait if let Some(receiver) = ctx.dot_receiver() { diff --git a/crates/ide_completion/src/context.rs b/crates/ide_completion/src/context.rs index f0da98739fd..061c082ab89 100644 --- a/crates/ide_completion/src/context.rs +++ b/crates/ide_completion/src/context.rs @@ -353,6 +353,10 @@ pub(crate) fn is_trivial_path(&self) -> bool { matches!(self.path_context, Some(PathCompletionContext { is_trivial_path: true, .. })) } + pub(crate) fn is_non_trivial_path(&self) -> bool { + matches!(self.path_context, Some(PathCompletionContext { is_trivial_path: false, .. })) + } + pub(crate) fn path_qual(&self) -> Option<&ast::Path> { self.path_context.as_ref().and_then(|it| it.qualifier.as_ref()) } diff --git a/crates/ide_completion/src/tests/item_list.rs b/crates/ide_completion/src/tests/item_list.rs index 129c9e51728..a170616f554 100644 --- a/crates/ide_completion/src/tests/item_list.rs +++ b/crates/ide_completion/src/tests/item_list.rs @@ -101,25 +101,11 @@ fn in_item_list_after_attr() { #[test] fn in_qualified_path() { + cov_mark::check!(no_keyword_completion_in_non_trivial_path); check( r#"crate::$0"#, expect![[r##" - kw pub(crate) - kw pub - kw unsafe - kw fn - kw const - kw type - kw impl - kw extern - kw use - kw trait - kw static - kw mod - kw enum - kw struct - kw union - ma makro!(…) #[macro_export] macro_rules! makro + ma makro!(…) #[macro_export] macro_rules! makro md module "##]], )