From 9ea6ee6b2785da02ff1963fbbc2eea340450905c Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Wed, 16 Jun 2021 17:56:04 +0200 Subject: Don't show incorrect completions after unsafe or visiblity node --- crates/ide_completion/src/completions/keyword.rs | 22 ++++++++++++---------- crates/ide_completion/src/completions/snippet.rs | 7 ++++++- 2 files changed, 18 insertions(+), 11 deletions(-) (limited to 'crates/ide_completion/src/completions') diff --git a/crates/ide_completion/src/completions/keyword.rs b/crates/ide_completion/src/completions/keyword.rs index 0bfdf9603..7970e75c7 100644 --- a/crates/ide_completion/src/completions/keyword.rs +++ b/crates/ide_completion/src/completions/keyword.rs @@ -90,11 +90,13 @@ pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte } if expects_item || has_block_expr_parent { + if !ctx.has_visibility_prev_sibling() { + add_keyword("impl", "impl $1 {\n $0\n}"); + add_keyword("extern", "extern $0"); + } add_keyword("use", "use $0"); - add_keyword("impl", "impl $1 {\n $0\n}"); add_keyword("trait", "trait $1 {\n $0\n}"); add_keyword("static", "static $0"); - add_keyword("extern", "extern $0"); add_keyword("mod", "mod $0"); } @@ -241,11 +243,11 @@ mod tests { kw fn kw const kw type - kw use kw impl + kw extern + kw use kw trait kw static - kw extern kw mod kw match kw while @@ -269,11 +271,11 @@ mod tests { kw fn kw const kw type - kw use kw impl + kw extern + kw use kw trait kw static - kw extern kw mod kw match kw while @@ -297,11 +299,11 @@ mod tests { kw fn kw const kw type - kw use kw impl + kw extern + kw use kw trait kw static - kw extern kw mod kw match kw while @@ -399,11 +401,11 @@ fn quux() -> i32 { kw fn kw const kw type - kw use kw impl + kw extern + kw use kw trait kw static - kw extern kw mod kw match kw while diff --git a/crates/ide_completion/src/completions/snippet.rs b/crates/ide_completion/src/completions/snippet.rs index 5560f1acf..4e64a0090 100644 --- a/crates/ide_completion/src/completions/snippet.rs +++ b/crates/ide_completion/src/completions/snippet.rs @@ -1,6 +1,7 @@ //! This file provides snippet completions, like `pd` => `eprintln!(...)`. use ide_db::helpers::SnippetCap; +use syntax::T; use crate::{ context::PathCompletionContext, item::Builder, CompletionContext, CompletionItem, @@ -35,9 +36,13 @@ pub(crate) fn complete_expr_snippet(acc: &mut Completions, ctx: &CompletionConte } pub(crate) fn complete_item_snippet(acc: &mut Completions, ctx: &CompletionContext) { - if !ctx.expects_item() { + if !ctx.expects_item() || ctx.previous_token_is(T![unsafe]) { return; } + if ctx.has_visibility_prev_sibling() { + return; // technically we could do some of these snippet completions if we were to put the + // attributes before the vis node. + } let cap = match ctx.config.snippet_cap { Some(it) => it, None => return, -- cgit v1.2.3