@@ -438,6 +438,7 @@ static PRECEDENCE_ATTR: &'static str = "precedence";
438438static ROOT_NODE_VAR : & ' static str = "ROOT_NODE" ;
439439static JUMP_TO_SCOPE_NODE_VAR : & ' static str = "JUMP_TO_SCOPE_NODE" ;
440440static FILE_PATH_VAR : & ' static str = "FILE_PATH" ;
441+ static ROOT_PATH_VAR : & ' static str = "ROOT_PATH" ;
441442
442443/// Holds information about how to construct stack graphs for a particular language.
443444pub struct StackGraphLanguage {
@@ -557,10 +558,12 @@ impl StackGraphLanguage {
557558 stack_graph : & ' a mut StackGraph ,
558559 file : Handle < File > ,
559560 source : & ' a str ,
561+ source_path : & Path ,
562+ source_root : & Path ,
560563 globals : & ' a Variables < ' a > ,
561564 cancellation_flag : & ' a dyn CancellationFlag ,
562565 ) -> Result < ( ) , BuildError > {
563- self . builder_into_stack_graph ( stack_graph, file, source)
566+ self . builder_into_stack_graph ( stack_graph, file, source, source_path , source_root )
564567 . build ( globals, cancellation_flag)
565568 }
566569
@@ -573,8 +576,10 @@ impl StackGraphLanguage {
573576 stack_graph : & ' a mut StackGraph ,
574577 file : Handle < File > ,
575578 source : & ' a str ,
579+ source_path : & ' a Path ,
580+ source_root : & ' a Path ,
576581 ) -> Builder < ' a > {
577- Builder :: new ( self , stack_graph, file, source)
582+ Builder :: new ( self , stack_graph, file, source, source_path , source_root )
578583 }
579584}
580585
@@ -583,6 +588,8 @@ pub struct Builder<'a> {
583588 stack_graph : & ' a mut StackGraph ,
584589 file : Handle < File > ,
585590 source : & ' a str ,
591+ source_path : & ' a Path ,
592+ source_root : & ' a Path ,
586593 graph : Graph < ' a > ,
587594 remapped_nodes : HashMap < usize , NodeID > ,
588595 injected_node_count : usize ,
@@ -595,13 +602,17 @@ impl<'a> Builder<'a> {
595602 stack_graph : & ' a mut StackGraph ,
596603 file : Handle < File > ,
597604 source : & ' a str ,
605+ source_path : & ' a Path ,
606+ source_root : & ' a Path ,
598607 ) -> Self {
599608 let span_calculator = SpanCalculator :: new ( source) ;
600609 Builder {
601610 sgl,
602611 stack_graph,
603612 file,
604613 source,
614+ source_path,
615+ source_root,
605616 graph : Graph :: new ( ) ,
606617 remapped_nodes : HashMap :: new ( ) ,
607618 injected_node_count : 0 ,
@@ -635,23 +646,33 @@ impl<'a> Builder<'a> {
635646 let tree = parse_errors. into_tree ( ) ;
636647
637648 let mut globals = Variables :: nested ( globals) ;
649+
638650 if globals. get ( & ROOT_NODE_VAR . into ( ) ) . is_none ( ) {
639651 let root_node = self . inject_node ( NodeID :: root ( ) ) ;
640652 globals
641653 . add ( ROOT_NODE_VAR . into ( ) , root_node. into ( ) )
642654 . expect ( "Failed to set ROOT_NODE" ) ;
643655 }
656+
644657 let jump_to_scope_node = self . inject_node ( NodeID :: jump_to ( ) ) ;
645658 globals
646659 . add ( JUMP_TO_SCOPE_NODE_VAR . into ( ) , jump_to_scope_node. into ( ) )
647660 . expect ( "Failed to set JUMP_TO_SCOPE_NODE" ) ;
661+
648662 if globals. get ( & FILE_PATH_VAR . into ( ) ) . is_none ( ) {
649- let file_name = self . stack_graph [ self . file ] . to_string ( ) ;
663+ let file_name = self . source_path . to_str ( ) . unwrap ( ) . to_string ( ) ;
650664 globals
651665 . add ( FILE_PATH_VAR . into ( ) , file_name. into ( ) )
652666 . expect ( "Failed to set FILE_PATH" ) ;
653667 }
654668
669+ if globals. get ( & ROOT_PATH_VAR . into ( ) ) . is_none ( ) {
670+ let root_path = self . source_root . to_str ( ) . unwrap ( ) . to_string ( ) ;
671+ globals
672+ . add ( ROOT_PATH_VAR . into ( ) , root_path. into ( ) )
673+ . expect ( "Failed to set ROOT_PATH" ) ;
674+ }
675+
655676 let mut config = ExecutionConfig :: new ( & self . sgl . functions , & globals)
656677 . lazy ( true )
657678 . debug_attributes (
0 commit comments