From 4fe4c30436986318dad339ce1ece2ae698a99303 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 17 Oct 2020 23:35:21 +0200 Subject: Improve readability --- crates/hir_def/src/body.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'crates') diff --git a/crates/hir_def/src/body.rs b/crates/hir_def/src/body.rs index 9a9a605dd..d51036e4f 100644 --- a/crates/hir_def/src/body.rs +++ b/crates/hir_def/src/body.rs @@ -105,14 +105,16 @@ impl Expander { let macro_call = InFile::new(self.current_file_id, ¯o_call); - if let Some(call_id) = macro_call.as_call_id(db, self.crate_def_map.krate, |path| { + let resolver = |path: ModPath| -> Option { if let Some(local_scope) = local_scope { if let Some(def) = path.as_ident().and_then(|n| local_scope.get_legacy_macro(n)) { return Some(def); } } self.resolve_path_as_macro(db, &path) - }) { + }; + + if let Some(call_id) = macro_call.as_call_id(db, self.crate_def_map.krate, resolver) { let file_id = call_id.as_file(); if let Some(node) = db.parse_or_expand(file_id) { if let Some(expr) = T::cast(node) { -- cgit v1.2.3 From 13451d3dc4477cc1dab38d6d66643de4bd4aa59e Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 17 Oct 2020 23:43:13 +0200 Subject: Complete methods when receiver is a macro --- crates/hir_expand/src/db.rs | 1 + crates/ide/src/completion/complete_dot.rs | 15 +++++++++++++++ 2 files changed, 16 insertions(+) (limited to 'crates') diff --git a/crates/hir_expand/src/db.rs b/crates/hir_expand/src/db.rs index b591130ca..ade57ac1b 100644 --- a/crates/hir_expand/src/db.rs +++ b/crates/hir_expand/src/db.rs @@ -389,6 +389,7 @@ fn to_fragment_kind(db: &dyn AstDatabase, id: MacroCallId) -> FragmentKind { CALL_EXPR => FragmentKind::Expr, INDEX_EXPR => FragmentKind::Expr, METHOD_CALL_EXPR => FragmentKind::Expr, + FIELD_EXPR => FragmentKind::Expr, AWAIT_EXPR => FragmentKind::Expr, CAST_EXPR => FragmentKind::Expr, REF_EXPR => FragmentKind::Expr, diff --git a/crates/ide/src/completion/complete_dot.rs b/crates/ide/src/completion/complete_dot.rs index 0b9f1798a..f0f9a7f1d 100644 --- a/crates/ide/src/completion/complete_dot.rs +++ b/crates/ide/src/completion/complete_dot.rs @@ -413,4 +413,19 @@ fn foo() { "#]], ); } + + #[test] + fn completes_method_call_when_receiver_is_a_macro_call() { + check( + r#" +struct S; +impl S { fn foo(&self) {} } +macro_rules! make_s { () => { S }; } +fn main() { make_s!().f<|>; } +"#, + expect![[r#" + me foo() fn foo(&self) + "#]], + ) + } } -- cgit v1.2.3