From 19c10672023ead0c1d64486154b6c4145b649568 Mon Sep 17 00:00:00 2001 From: Igor Aleksanov Date: Sun, 25 Oct 2020 10:59:15 +0300 Subject: Reorganize completions structure --- .../src/completions/macro_in_item_position.rs | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 crates/completion/src/completions/macro_in_item_position.rs (limited to 'crates/completion/src/completions/macro_in_item_position.rs') 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 @@ +//! Completes macro invocations used in item position. + +use crate::{CompletionContext, Completions}; + +pub(crate) fn complete_macro_in_item_position(acc: &mut Completions, ctx: &CompletionContext) { + // Show only macros in top level. + if ctx.is_new_item { + ctx.scope.process_all_names(&mut |name, res| { + if let hir::ScopeDef::MacroDef(mac) = res { + acc.add_macro(ctx, Some(name.to_string()), mac); + } + }) + } +} + +#[cfg(test)] +mod tests { + use expect_test::{expect, Expect}; + + use crate::{test_utils::completion_list, CompletionKind}; + + fn check(ra_fixture: &str, expect: Expect) { + let actual = completion_list(ra_fixture, CompletionKind::Reference); + expect.assert_eq(&actual) + } + + #[test] + fn completes_macros_as_item() { + check( + r#" +macro_rules! foo { () => {} } +fn foo() {} + +<|> +"#, + expect![[r#" + ma foo!(…) macro_rules! foo + "#]], + ) + } +} -- cgit v1.2.3