aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-10-17 23:45:32 +0100
committerGitHub <[email protected]>2020-10-17 23:45:32 +0100
commitaed7b6d98aab8c222124d336b69f83ed4f1dfb2d (patch)
tree425f5c6dda7b123b0654534387cb6dd351868847 /crates
parent63956e509eea1aba1a303c58bf60d068863a61dd (diff)
parent13451d3dc4477cc1dab38d6d66643de4bd4aa59e (diff)
Merge #6271
6271: Complete methods when receiver is a macro r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/hir_def/src/body.rs6
-rw-r--r--crates/hir_expand/src/db.rs1
-rw-r--r--crates/ide/src/completion/complete_dot.rs15
3 files changed, 20 insertions, 2 deletions
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 {
105 105
106 let macro_call = InFile::new(self.current_file_id, &macro_call); 106 let macro_call = InFile::new(self.current_file_id, &macro_call);
107 107
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> {
109 if let Some(local_scope) = local_scope { 109 if let Some(local_scope) = local_scope {
110 if let Some(def) = path.as_ident().and_then(|n| local_scope.get_legacy_macro(n)) { 110 if let Some(def) = path.as_ident().and_then(|n| local_scope.get_legacy_macro(n)) {
111 return Some(def); 111 return Some(def);
112 } 112 }
113 } 113 }
114 self.resolve_path_as_macro(db, &path) 114 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) {
116 let file_id = call_id.as_file(); 118 let file_id = call_id.as_file();
117 if let Some(node) = db.parse_or_expand(file_id) { 119 if let Some(node) = db.parse_or_expand(file_id) {
118 if let Some(expr) = T::cast(node) { 120 if let Some(expr) = T::cast(node) {
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 {
389 CALL_EXPR => FragmentKind::Expr, 389 CALL_EXPR => FragmentKind::Expr,
390 INDEX_EXPR => FragmentKind::Expr, 390 INDEX_EXPR => FragmentKind::Expr,
391 METHOD_CALL_EXPR => FragmentKind::Expr, 391 METHOD_CALL_EXPR => FragmentKind::Expr,
392 FIELD_EXPR => FragmentKind::Expr,
392 AWAIT_EXPR => FragmentKind::Expr, 393 AWAIT_EXPR => FragmentKind::Expr,
393 CAST_EXPR => FragmentKind::Expr, 394 CAST_EXPR => FragmentKind::Expr,
394 REF_EXPR => FragmentKind::Expr, 395 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() {
413 "#]], 413 "#]],
414 ); 414 );
415 } 415 }
416
417 #[test]
418 fn completes_method_call_when_receiver_is_a_macro_call() {
419 check(
420 r#"
421struct S;
422impl S { fn foo(&self) {} }
423macro_rules! make_s { () => { S }; }
424fn main() { make_s!().f<|>; }
425"#,
426 expect![[r#"
427 me foo() fn foo(&self)
428 "#]],
429 )
430 }
416} 431}