Skip to content

Commit aed7b6d

Browse files
bors[bot]matklad
andauthored
Merge #6271
6271: Complete methods when receiver is a macro r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
2 parents 63956e5 + 13451d3 commit aed7b6d

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

crates/hir_def/src/body.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,16 @@ impl Expander {
105105

106106
let macro_call = InFile::new(self.current_file_id, &macro_call);
107107

108-
if let Some(call_id) = macro_call.as_call_id(db, self.crate_def_map.krate, |path| {
108+
let resolver = |path: ModPath| -> Option<MacroDefId> {
109109
if let Some(local_scope) = local_scope {
110110
if let Some(def) = path.as_ident().and_then(|n| local_scope.get_legacy_macro(n)) {
111111
return Some(def);
112112
}
113113
}
114114
self.resolve_path_as_macro(db, &path)
115-
}) {
115+
};
116+
117+
if let Some(call_id) = macro_call.as_call_id(db, self.crate_def_map.krate, resolver) {
116118
let file_id = call_id.as_file();
117119
if let Some(node) = db.parse_or_expand(file_id) {
118120
if let Some(expr) = T::cast(node) {

crates/hir_expand/src/db.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ fn to_fragment_kind(db: &dyn AstDatabase, id: MacroCallId) -> FragmentKind {
389389
CALL_EXPR => FragmentKind::Expr,
390390
INDEX_EXPR => FragmentKind::Expr,
391391
METHOD_CALL_EXPR => FragmentKind::Expr,
392+
FIELD_EXPR => FragmentKind::Expr,
392393
AWAIT_EXPR => FragmentKind::Expr,
393394
CAST_EXPR => FragmentKind::Expr,
394395
REF_EXPR => FragmentKind::Expr,

crates/ide/src/completion/complete_dot.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,4 +413,19 @@ fn foo() {
413413
"#]],
414414
);
415415
}
416+
417+
#[test]
418+
fn completes_method_call_when_receiver_is_a_macro_call() {
419+
check(
420+
r#"
421+
struct S;
422+
impl S { fn foo(&self) {} }
423+
macro_rules! make_s { () => { S }; }
424+
fn main() { make_s!().f<|>; }
425+
"#,
426+
expect![[r#"
427+
me foo() fn foo(&self)
428+
"#]],
429+
)
430+
}
416431
}

0 commit comments

Comments
 (0)