@@ -26,7 +26,7 @@ use ide_db::{
2626use itertools:: Itertools ;
2727use proc_macro_api:: {
2828 MacroDylib , ProcMacroClient ,
29- bidirectional_protocol:: msg:: { SubRequest , SubResponse } ,
29+ bidirectional_protocol:: msg:: { ParentSpan , SubRequest , SubResponse } ,
3030} ;
3131use project_model:: { CargoConfig , PackageRoot , ProjectManifest , ProjectWorkspace } ;
3232use span:: { Span , SpanAnchor , SyntaxContext } ;
@@ -659,6 +659,44 @@ impl ProcMacroExpander for Expander {
659659 ctx : current_span. ctx . into_u32 ( ) ,
660660 } )
661661 }
662+ SubRequest :: SpanParent { file_id, ast_id, start, end, ctx } => {
663+ let span = Span {
664+ range : TextRange :: new ( TextSize :: from ( start) , TextSize :: from ( end) ) ,
665+ anchor : SpanAnchor {
666+ file_id : span:: EditionedFileId :: from_raw ( file_id) ,
667+ ast_id : span:: ErasedFileAstId :: from_raw ( ast_id) ,
668+ } ,
669+ // SAFETY: We only receive spans from the server. If someone mess up the communication UB can happen,
670+ // but that will be their problem.
671+ ctx : unsafe { SyntaxContext :: from_u32 ( ctx) } ,
672+ } ;
673+
674+ if let Some ( macro_call_id) = span. ctx . outer_expn ( db) {
675+ let macro_call_loc = db. lookup_intern_macro_call ( macro_call_id. into ( ) ) ;
676+
677+ let call_site_file = macro_call_loc. kind . file_id ( ) ;
678+ let call_site_ast_id = macro_call_loc. kind . erased_ast_id ( ) ;
679+
680+ if let Some ( editioned_file_id) = call_site_file. file_id ( ) {
681+ let range = db
682+ . ast_id_map ( editioned_file_id. into ( ) )
683+ . get_erased ( call_site_ast_id)
684+ . text_range ( ) ;
685+
686+ let parent_span = Some ( ParentSpan {
687+ file_id : editioned_file_id. editioned_file_id ( db) . as_u32 ( ) ,
688+ ast_id : span:: ROOT_ERASED_FILE_AST_ID . into_raw ( ) ,
689+ start : u32:: from ( range. start ( ) ) ,
690+ end : u32:: from ( range. end ( ) ) ,
691+ ctx : macro_call_loc. ctxt . into_u32 ( ) ,
692+ } ) ;
693+
694+ return Ok ( SubResponse :: SpanParentResult { parent_span } ) ;
695+ }
696+ }
697+
698+ Ok ( SubResponse :: SpanParentResult { parent_span : None } )
699+ }
662700 } ;
663701 match self . 0 . expand (
664702 subtree. view ( ) ,
0 commit comments