diff options
author | Aleksey Kladov <[email protected]> | 2020-08-13 16:42:52 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-08-13 16:58:27 +0100 |
commit | 1b0c7701cc97cd7bef8bb9729011d4cf291a60c5 (patch) | |
tree | b69f0c9947d9cec522ce835d7213b21075fe6dcf /crates/ide/src/completion/complete_macro_in_item_position.rs | |
parent | fc34403018079ea053f26d0a31b7517053c7dd8c (diff) |
Rename ra_ide -> ide
Diffstat (limited to 'crates/ide/src/completion/complete_macro_in_item_position.rs')
-rw-r--r-- | crates/ide/src/completion/complete_macro_in_item_position.rs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/crates/ide/src/completion/complete_macro_in_item_position.rs b/crates/ide/src/completion/complete_macro_in_item_position.rs new file mode 100644 index 000000000..0447f0511 --- /dev/null +++ b/crates/ide/src/completion/complete_macro_in_item_position.rs | |||
@@ -0,0 +1,41 @@ | |||
1 | //! FIXME: write short doc here | ||
2 | |||
3 | use crate::completion::{CompletionContext, Completions}; | ||
4 | |||
5 | pub(super) fn complete_macro_in_item_position(acc: &mut Completions, ctx: &CompletionContext) { | ||
6 | // Show only macros in top level. | ||
7 | if ctx.is_new_item { | ||
8 | ctx.scope.process_all_names(&mut |name, res| { | ||
9 | if let hir::ScopeDef::MacroDef(mac) = res { | ||
10 | acc.add_macro(ctx, Some(name.to_string()), mac); | ||
11 | } | ||
12 | }) | ||
13 | } | ||
14 | } | ||
15 | |||
16 | #[cfg(test)] | ||
17 | mod tests { | ||
18 | use expect::{expect, Expect}; | ||
19 | |||
20 | use crate::completion::{test_utils::completion_list, CompletionKind}; | ||
21 | |||
22 | fn check(ra_fixture: &str, expect: Expect) { | ||
23 | let actual = completion_list(ra_fixture, CompletionKind::Reference); | ||
24 | expect.assert_eq(&actual) | ||
25 | } | ||
26 | |||
27 | #[test] | ||
28 | fn completes_macros_as_item() { | ||
29 | check( | ||
30 | r#" | ||
31 | macro_rules! foo { () => {} } | ||
32 | fn foo() {} | ||
33 | |||
34 | <|> | ||
35 | "#, | ||
36 | expect![[r#" | ||
37 | ma foo!(…) macro_rules! foo | ||
38 | "#]], | ||
39 | ) | ||
40 | } | ||
41 | } | ||