diff options
author | Aleksey Kladov <[email protected]> | 2019-01-08 19:30:56 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-01-08 19:30:56 +0000 |
commit | 6bca91af532d79abbced5b151cb4188ff8625c04 (patch) | |
tree | 6f61b6358bb99925adf71ade2ecb12e38e4ef51f /crates/ra_analysis/src/completion/complete_path.rs | |
parent | fa3c9ce3921b6a3f67222bf4f9b4efdf4f11c2a5 (diff) |
rename ra_analysis -> ra_ide_api
Diffstat (limited to 'crates/ra_analysis/src/completion/complete_path.rs')
-rw-r--r-- | crates/ra_analysis/src/completion/complete_path.rs | 128 |
1 files changed, 0 insertions, 128 deletions
diff --git a/crates/ra_analysis/src/completion/complete_path.rs b/crates/ra_analysis/src/completion/complete_path.rs deleted file mode 100644 index 4723a65a6..000000000 --- a/crates/ra_analysis/src/completion/complete_path.rs +++ /dev/null | |||
@@ -1,128 +0,0 @@ | |||
1 | use crate::{ | ||
2 | Cancelable, | ||
3 | completion::{CompletionItem, CompletionItemKind, Completions, CompletionKind, CompletionContext}, | ||
4 | }; | ||
5 | |||
6 | pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) -> Cancelable<()> { | ||
7 | let (path, module) = match (&ctx.path_prefix, &ctx.module) { | ||
8 | (Some(path), Some(module)) => (path.clone(), module), | ||
9 | _ => return Ok(()), | ||
10 | }; | ||
11 | let def_id = match module.resolve_path(ctx.db, &path)?.take_types() { | ||
12 | Some(it) => it, | ||
13 | None => return Ok(()), | ||
14 | }; | ||
15 | match def_id.resolve(ctx.db)? { | ||
16 | hir::Def::Module(module) => { | ||
17 | let module_scope = module.scope(ctx.db)?; | ||
18 | module_scope.entries().for_each(|(name, res)| { | ||
19 | CompletionItem::new(CompletionKind::Reference, name.to_string()) | ||
20 | .from_resolution(ctx, res) | ||
21 | .add_to(acc) | ||
22 | }); | ||
23 | } | ||
24 | hir::Def::Enum(e) => e | ||
25 | .variants(ctx.db)? | ||
26 | .into_iter() | ||
27 | .for_each(|(name, _variant)| { | ||
28 | CompletionItem::new(CompletionKind::Reference, name.to_string()) | ||
29 | .kind(CompletionItemKind::EnumVariant) | ||
30 | .add_to(acc) | ||
31 | }), | ||
32 | _ => return Ok(()), | ||
33 | }; | ||
34 | Ok(()) | ||
35 | } | ||
36 | |||
37 | #[cfg(test)] | ||
38 | mod tests { | ||
39 | use crate::completion::{CompletionKind, check_completion}; | ||
40 | |||
41 | fn check_reference_completion(code: &str, expected_completions: &str) { | ||
42 | check_completion(code, expected_completions, CompletionKind::Reference); | ||
43 | } | ||
44 | |||
45 | #[test] | ||
46 | fn completes_use_item_starting_with_self() { | ||
47 | check_reference_completion( | ||
48 | r" | ||
49 | use self::m::<|>; | ||
50 | |||
51 | mod m { | ||
52 | struct Bar; | ||
53 | } | ||
54 | ", | ||
55 | "Bar", | ||
56 | ); | ||
57 | } | ||
58 | |||
59 | #[test] | ||
60 | fn completes_use_item_starting_with_crate() { | ||
61 | check_reference_completion( | ||
62 | " | ||
63 | //- /lib.rs | ||
64 | mod foo; | ||
65 | struct Spam; | ||
66 | //- /foo.rs | ||
67 | use crate::Sp<|> | ||
68 | ", | ||
69 | "Spam;foo", | ||
70 | ); | ||
71 | } | ||
72 | |||
73 | #[test] | ||
74 | fn completes_nested_use_tree() { | ||
75 | check_reference_completion( | ||
76 | " | ||
77 | //- /lib.rs | ||
78 | mod foo; | ||
79 | struct Spam; | ||
80 | //- /foo.rs | ||
81 | use crate::{Sp<|>}; | ||
82 | ", | ||
83 | "Spam;foo", | ||
84 | ); | ||
85 | } | ||
86 | |||
87 | #[test] | ||
88 | fn completes_deeply_nested_use_tree() { | ||
89 | check_reference_completion( | ||
90 | " | ||
91 | //- /lib.rs | ||
92 | mod foo; | ||
93 | pub mod bar { | ||
94 | pub mod baz { | ||
95 | pub struct Spam; | ||
96 | } | ||
97 | } | ||
98 | //- /foo.rs | ||
99 | use crate::{bar::{baz::Sp<|>}}; | ||
100 | ", | ||
101 | "Spam", | ||
102 | ); | ||
103 | } | ||
104 | |||
105 | #[test] | ||
106 | fn completes_enum_variant() { | ||
107 | check_reference_completion( | ||
108 | " | ||
109 | //- /lib.rs | ||
110 | enum E { Foo, Bar(i32) } | ||
111 | fn foo() { let _ = E::<|> } | ||
112 | ", | ||
113 | "Foo;Bar", | ||
114 | ); | ||
115 | } | ||
116 | |||
117 | #[test] | ||
118 | fn dont_render_function_parens_in_use_item() { | ||
119 | check_reference_completion( | ||
120 | " | ||
121 | //- /lib.rs | ||
122 | mod m { pub fn foo() {} } | ||
123 | use crate::m::f<|>; | ||
124 | ", | ||
125 | "foo", | ||
126 | ) | ||
127 | } | ||
128 | } | ||