Skip to content

Commit 6ab9724

Browse files
Tidy up the tests
1 parent 6866a05 commit 6ab9724

File tree

1 file changed

+15
-49
lines changed

1 file changed

+15
-49
lines changed

crates/completion/src/completions/complete_magic.rs

Lines changed: 15 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::{context::CompletionContext, item::CompletionKind, CompletionItem, Co
1010

1111
use super::Completions;
1212

13+
// TODO kb when typing, completes partial results, need to rerun manually to see the proper ones
1314
pub(crate) fn complete_magic(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> {
1415
if !(ctx.is_trivial_path || ctx.is_pat_binding_or_const) {
1516
return None;
@@ -19,7 +20,7 @@ pub(crate) fn complete_magic(acc: &mut Completions, ctx: &CompletionContext) ->
1920
let import_scope = ImportScope::find_insert_use_container(anchor.syntax(), &ctx.sema)?;
2021

2122
// TODO kb consider heuristics, such as "don't show `hash_map` import if `HashMap` is the import for completion"
22-
// TODO kb module functions are not completed, consider `std::io::stdin` one
23+
// also apply completion ordering
2324
let potential_import_name = ctx.token.to_string();
2425

2526
let possible_imports = ctx
@@ -38,6 +39,7 @@ pub(crate) fn complete_magic(acc: &mut Completions, ctx: &CompletionContext) ->
3839
builder.replace(anchor.syntax().text_range(), correct_qualifier);
3940

4041
// TODO kb: assists already have the merge behaviour setting, need to unite both
42+
// also consider a settings toggle for this particular feature?
4143
let rewriter =
4244
insert_use(&import_scope, mod_path_to_ast(&mod_path), Some(MergeBehaviour::Full));
4345
let old_ast = rewriter.rewrite_root()?;
@@ -60,37 +62,10 @@ pub(crate) fn complete_magic(acc: &mut Completions, ctx: &CompletionContext) ->
6062

6163
#[cfg(test)]
6264
mod tests {
63-
use expect_test::{expect, Expect};
64-
65-
use crate::{
66-
item::CompletionKind,
67-
test_utils::{check_edit, completion_list},
68-
};
69-
70-
fn check(ra_fixture: &str, expect: Expect) {
71-
let actual = completion_list(ra_fixture, CompletionKind::Magic);
72-
expect.assert_eq(&actual)
73-
}
65+
use crate::test_utils::check_edit;
7466

7567
#[test]
7668
fn function_magic_completion() {
77-
check(
78-
r#"
79-
//- /lib.rs crate:dep
80-
pub mod io {
81-
pub fn stdin() {}
82-
};
83-
84-
//- /main.rs crate:main deps:dep
85-
fn main() {
86-
stdi<|>
87-
}
88-
"#,
89-
expect![[r#"
90-
st dep::io::stdin
91-
"#]],
92-
);
93-
9469
check_edit(
9570
"dep::io::stdin",
9671
r#"
@@ -116,37 +91,28 @@ fn main() {
11691

11792
#[test]
11893
fn case_insensitive_magic_completion_works() {
119-
check(
120-
r#"
121-
//- /lib.rs crate:dep
122-
pub struct TestStruct;
123-
124-
//- /main.rs crate:main deps:dep
125-
fn main() {
126-
teru<|>
127-
}
128-
"#,
129-
expect![[r#"
130-
st dep::TestStruct
131-
"#]],
132-
);
133-
13494
check_edit(
135-
"dep::TestStruct",
95+
"dep::some_module::ThirdStruct",
13696
r#"
13797
//- /lib.rs crate:dep
138-
pub struct TestStruct;
98+
pub struct FirstStruct;
99+
pub mod some_module {
100+
pub struct SecondStruct;
101+
pub struct ThirdStruct;
102+
}
139103
140104
//- /main.rs crate:main deps:dep
105+
use dep::{FirstStruct, some_module::SecondStruct};
106+
141107
fn main() {
142-
teru<|>
108+
this<|>
143109
}
144110
"#,
145111
r#"
146-
use dep::TestStruct;
112+
use dep::{FirstStruct, some_module::{SecondStruct, ThirdStruct}};
147113
148114
fn main() {
149-
TestStruct
115+
ThirdStruct
150116
}
151117
"#,
152118
);

0 commit comments

Comments
 (0)