aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_completion/src/completions/snippet.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-06-16 20:53:43 +0100
committerGitHub <[email protected]>2021-06-16 20:53:43 +0100
commitd6b8af44829521a9f925c4d87599efa3fef38edc (patch)
tree47119538effd381ecd8e15d422103512f2b47406 /crates/ide_completion/src/completions/snippet.rs
parentf38770cd2606148bfe764351849ea7ebea45132c (diff)
parentaa644b55859c6b5c6695a5d4fb35d1b6efbbebcc (diff)
Merge #9301
9301: internal: Start refactoring ide_completion tests r=Veykril a=Veykril Our current completion test infra resovles around usually just checking a specific `CompletionKind` which is suboptimal. We only see what we want to see in tests with this causing us to miss a lot of incorrect completions we are doing. Instead we should test for different cursor locations for all kinds(sans the magic kind maybe? not sure yet). This way we will also see potential duplicate completions that merely different in their kind. Also since most completion submodules complete things in tests of other modules due to the tests overlapping it makes more sense to group these tests differently which implies moving them to a new module. Exceptions for this might be stuff like attribute completion as these cannot currently interfere. I only wrote a few tests to check for completions in `ItemList` position so far and I already found a few incorrect/irrelevant completions as these haven't been tested properly due to them being hidden by the `CompletionKind` filtering. I think `CompletionKind` doesn't really seem to be beneficial to me as to I can't think of a occasion where we would want to only check a specific completion kind. Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates/ide_completion/src/completions/snippet.rs')
-rw-r--r--crates/ide_completion/src/completions/snippet.rs28
1 files changed, 8 insertions, 20 deletions
diff --git a/crates/ide_completion/src/completions/snippet.rs b/crates/ide_completion/src/completions/snippet.rs
index b9862de67..81ddfa34f 100644
--- a/crates/ide_completion/src/completions/snippet.rs
+++ b/crates/ide_completion/src/completions/snippet.rs
@@ -1,6 +1,7 @@
1//! This file provides snippet completions, like `pd` => `eprintln!(...)`. 1//! This file provides snippet completions, like `pd` => `eprintln!(...)`.
2 2
3use ide_db::helpers::SnippetCap; 3use ide_db::helpers::SnippetCap;
4use syntax::T;
4 5
5use crate::{ 6use crate::{
6 context::PathCompletionContext, item::Builder, CompletionContext, CompletionItem, 7 context::PathCompletionContext, item::Builder, CompletionContext, CompletionItem,
@@ -35,9 +36,13 @@ pub(crate) fn complete_expr_snippet(acc: &mut Completions, ctx: &CompletionConte
35} 36}
36 37
37pub(crate) fn complete_item_snippet(acc: &mut Completions, ctx: &CompletionContext) { 38pub(crate) fn complete_item_snippet(acc: &mut Completions, ctx: &CompletionContext) {
38 if !ctx.expects_item() { 39 if !ctx.expects_item() || ctx.previous_token_is(T![unsafe]) || ctx.path_qual().is_some() {
39 return; 40 return;
40 } 41 }
42 if ctx.has_visibility_prev_sibling() {
43 return; // technically we could do some of these snippet completions if we were to put the
44 // attributes before the vis node.
45 }
41 let cap = match ctx.config.snippet_cap { 46 let cap = match ctx.config.snippet_cap {
42 Some(it) => it, 47 Some(it) => it,
43 None => return, 48 None => return,
@@ -82,10 +87,10 @@ fn ${1:feature}() {
82mod tests { 87mod tests {
83 use expect_test::{expect, Expect}; 88 use expect_test::{expect, Expect};
84 89
85 use crate::{test_utils::completion_list, CompletionKind}; 90 use crate::{tests::filtered_completion_list, CompletionKind};
86 91
87 fn check(ra_fixture: &str, expect: Expect) { 92 fn check(ra_fixture: &str, expect: Expect) {
88 let actual = completion_list(ra_fixture, CompletionKind::Snippet); 93 let actual = filtered_completion_list(ra_fixture, CompletionKind::Snippet);
89 expect.assert_eq(&actual) 94 expect.assert_eq(&actual)
90 } 95 }
91 96
@@ -105,21 +110,4 @@ mod tests {
105 check(r#"fn foo(x: i32) { ::foo$0 }"#, expect![[""]]); 110 check(r#"fn foo(x: i32) { ::foo$0 }"#, expect![[""]]);
106 check(r#"fn foo(x: i32) { ::$0 }"#, expect![[""]]); 111 check(r#"fn foo(x: i32) { ::$0 }"#, expect![[""]]);
107 } 112 }
108
109 #[test]
110 fn completes_snippets_in_items() {
111 check(
112 r#"
113#[cfg(test)]
114mod tests {
115 $0
116}
117"#,
118 expect![[r#"
119 sn tmod (Test module)
120 sn tfn (Test function)
121 sn macro_rules
122 "#]],
123 )
124 }
125} 113}