From d338a803941c2b0ac83decfcdfac33c09dfaa971 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Wed, 16 Jun 2021 17:37:23 +0200 Subject: Start refactoring ide_completion tests --- crates/ide_completion/src/completions/snippet.rs | 17 ----------------- 1 file changed, 17 deletions(-) (limited to 'crates/ide_completion/src/completions/snippet.rs') diff --git a/crates/ide_completion/src/completions/snippet.rs b/crates/ide_completion/src/completions/snippet.rs index b9862de67..5560f1acf 100644 --- a/crates/ide_completion/src/completions/snippet.rs +++ b/crates/ide_completion/src/completions/snippet.rs @@ -105,21 +105,4 @@ mod tests { check(r#"fn foo(x: i32) { ::foo$0 }"#, expect![[""]]); check(r#"fn foo(x: i32) { ::$0 }"#, expect![[""]]); } - - #[test] - fn completes_snippets_in_items() { - check( - r#" -#[cfg(test)] -mod tests { - $0 -} -"#, - expect![[r#" - sn tmod (Test module) - sn tfn (Test function) - sn macro_rules - "#]], - ) - } } -- cgit v1.2.3 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/snippet.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'crates/ide_completion/src/completions/snippet.rs') 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 From 11115ebad8d0cb367478a4f154abe08c0c25aa95 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Wed, 16 Jun 2021 18:50:18 +0200 Subject: Don't complete paths after attributes --- crates/ide_completion/src/completions/snippet.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ide_completion/src/completions/snippet.rs') diff --git a/crates/ide_completion/src/completions/snippet.rs b/crates/ide_completion/src/completions/snippet.rs index 4e64a0090..d142265e0 100644 --- a/crates/ide_completion/src/completions/snippet.rs +++ b/crates/ide_completion/src/completions/snippet.rs @@ -36,7 +36,7 @@ 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() || ctx.previous_token_is(T![unsafe]) { + if !ctx.expects_item() || ctx.previous_token_is(T![unsafe]) || ctx.path_qual().is_some() { return; } if ctx.has_visibility_prev_sibling() { -- cgit v1.2.3 From aa644b55859c6b5c6695a5d4fb35d1b6efbbebcc Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Wed, 16 Jun 2021 21:45:02 +0200 Subject: Move test_utils into tests module --- crates/ide_completion/src/completions/snippet.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ide_completion/src/completions/snippet.rs') diff --git a/crates/ide_completion/src/completions/snippet.rs b/crates/ide_completion/src/completions/snippet.rs index d142265e0..81ddfa34f 100644 --- a/crates/ide_completion/src/completions/snippet.rs +++ b/crates/ide_completion/src/completions/snippet.rs @@ -87,10 +87,10 @@ fn ${1:feature}() { mod tests { use expect_test::{expect, Expect}; - use crate::{test_utils::completion_list, CompletionKind}; + use crate::{tests::filtered_completion_list, CompletionKind}; fn check(ra_fixture: &str, expect: Expect) { - let actual = completion_list(ra_fixture, CompletionKind::Snippet); + let actual = filtered_completion_list(ra_fixture, CompletionKind::Snippet); expect.assert_eq(&actual) } -- cgit v1.2.3