44//! with the needed functionality.
55
66use crate :: resolution:: name_resolution:: { Resolver , ResolverImpl } ;
7+ use crate :: resolution:: util:: canonical_path;
78
89use super :: hacky_resolver:: HackyResolver ;
910use crate :: effect:: SrcLoc ;
@@ -13,7 +14,7 @@ use anyhow::Result;
1314use log:: debug;
1415use ra_ap_hir:: HirFileId ;
1516use ra_ap_syntax:: ast:: MacroCall ;
16- use ra_ap_syntax:: SyntaxNode ;
17+ use ra_ap_syntax:: { AstNode , SyntaxNode } ;
1718use std:: fmt:: Display ;
1819use std:: path:: Path as FilePath ;
1920use syn:: { self , spanned:: Spanned } ;
@@ -117,14 +118,11 @@ impl<'a> FileResolver<'a> {
117118 Some ( ( file_id, expanded_syntax) )
118119 }
119120
120- pub fn resolve_macro_def_path (
121- & self ,
122- macro_call : & MacroCall ,
123- ) -> Option < CanonicalPath > {
124- let path = macro_call. path ( ) ?;
125- let last_segment = path. segment ( ) ?. name_ref ( ) ?. text ( ) . to_string ( ) ;
126- let fake_ident = syn:: Ident :: new ( & last_segment, proc_macro2:: Span :: call_site ( ) ) ;
127- Some ( self . resolve_def ( & fake_ident) )
121+ pub fn resolve_macro_def ( & self , macro_call : & MacroCall ) -> Option < CanonicalPath > {
122+ let containing_fn =
123+ & macro_call. syntax ( ) . ancestors ( ) . find_map ( ra_ap_syntax:: ast:: Fn :: cast) ?;
124+ let def = self . resolver . sems . to_def ( containing_fn) ?;
125+ canonical_path ( & self . resolver . sems , self . resolver . sems . db , & def. into ( ) )
128126 }
129127
130128 fn resolve_core ( & self , i : & syn:: Ident ) -> Result < CanonicalPath > {
0 commit comments