diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-10-26 19:06:34 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-10-26 19:06:34 +0000 |
commit | d10e2a04c8a5ff157acd95bc7458d36d9f396390 (patch) | |
tree | fb68b034d7e56053e5d1b4302e2996f64b024e11 /crates/completion/src/completions/macro_in_item_position.rs | |
parent | d01e412eb1572676a33ad145f3370a7157dbc9df (diff) | |
parent | 357bf0cedc658b7c95952324fda4bbe7f41a3e6a (diff) |
Merge #6351
6351: Organized completions r=popzxc a=popzxc
This PR continues the work on refactoring of the `completions` crate.
In this episode:
- Actual completions methods are encapsulated into `completions` module, so they aren't mixed with the rest of the code.
- Name duplication was removed (`complete_attribute` => `completions::attribute`, `completion_context` => `context`).
- `Completions` structure was moved from `item` module to the `completions`.
- `presentation` module was removed, as it was basically a module with `impl` for `Completions`.
- Code approaches were a bit unified here and there.
Co-authored-by: Igor Aleksanov <[email protected]>
Diffstat (limited to 'crates/completion/src/completions/macro_in_item_position.rs')
-rw-r--r-- | crates/completion/src/completions/macro_in_item_position.rs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/crates/completion/src/completions/macro_in_item_position.rs b/crates/completion/src/completions/macro_in_item_position.rs new file mode 100644 index 000000000..82884a181 --- /dev/null +++ b/crates/completion/src/completions/macro_in_item_position.rs | |||
@@ -0,0 +1,41 @@ | |||
1 | //! Completes macro invocations used in item position. | ||
2 | |||
3 | use crate::{CompletionContext, Completions}; | ||
4 | |||
5 | pub(crate) 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_test::{expect, Expect}; | ||
19 | |||
20 | use crate::{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 | } | ||