6271: Complete methods when receiver is a macro r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2020-10-17 22:45:32 +00:00 committed by GitHub
commit aed7b6d98a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 2 deletions

View File

@ -105,14 +105,16 @@ impl Expander {
let macro_call = InFile::new(self.current_file_id, &macro_call);
if let Some(call_id) = macro_call.as_call_id(db, self.crate_def_map.krate, |path| {
let resolver = |path: ModPath| -> Option<MacroDefId> {
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) {

View File

@ -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,

View File

@ -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)
"#]],
)
}
}