@@ -438,6 +438,7 @@ static PRECEDENCE_ATTR: &'static str = "precedence";
438
438
static ROOT_NODE_VAR : & ' static str = "ROOT_NODE" ;
439
439
static JUMP_TO_SCOPE_NODE_VAR : & ' static str = "JUMP_TO_SCOPE_NODE" ;
440
440
static FILE_PATH_VAR : & ' static str = "FILE_PATH" ;
441
+ static ROOT_PATH_VAR : & ' static str = "ROOT_PATH" ;
441
442
442
443
/// Holds information about how to construct stack graphs for a particular language.
443
444
pub struct StackGraphLanguage {
@@ -557,10 +558,12 @@ impl StackGraphLanguage {
557
558
stack_graph : & ' a mut StackGraph ,
558
559
file : Handle < File > ,
559
560
source : & ' a str ,
561
+ source_path : & Path ,
562
+ source_root : & Path ,
560
563
globals : & ' a Variables < ' a > ,
561
564
cancellation_flag : & ' a dyn CancellationFlag ,
562
565
) -> 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 )
564
567
. build ( globals, cancellation_flag)
565
568
}
566
569
@@ -573,8 +576,10 @@ impl StackGraphLanguage {
573
576
stack_graph : & ' a mut StackGraph ,
574
577
file : Handle < File > ,
575
578
source : & ' a str ,
579
+ source_path : & ' a Path ,
580
+ source_root : & ' a Path ,
576
581
) -> Builder < ' a > {
577
- Builder :: new ( self , stack_graph, file, source)
582
+ Builder :: new ( self , stack_graph, file, source, source_path , source_root )
578
583
}
579
584
}
580
585
@@ -583,6 +588,8 @@ pub struct Builder<'a> {
583
588
stack_graph : & ' a mut StackGraph ,
584
589
file : Handle < File > ,
585
590
source : & ' a str ,
591
+ source_path : & ' a Path ,
592
+ source_root : & ' a Path ,
586
593
graph : Graph < ' a > ,
587
594
remapped_nodes : HashMap < usize , NodeID > ,
588
595
injected_node_count : usize ,
@@ -595,13 +602,17 @@ impl<'a> Builder<'a> {
595
602
stack_graph : & ' a mut StackGraph ,
596
603
file : Handle < File > ,
597
604
source : & ' a str ,
605
+ source_path : & ' a Path ,
606
+ source_root : & ' a Path ,
598
607
) -> Self {
599
608
let span_calculator = SpanCalculator :: new ( source) ;
600
609
Builder {
601
610
sgl,
602
611
stack_graph,
603
612
file,
604
613
source,
614
+ source_path,
615
+ source_root,
605
616
graph : Graph :: new ( ) ,
606
617
remapped_nodes : HashMap :: new ( ) ,
607
618
injected_node_count : 0 ,
@@ -635,23 +646,33 @@ impl<'a> Builder<'a> {
635
646
let tree = parse_errors. into_tree ( ) ;
636
647
637
648
let mut globals = Variables :: nested ( globals) ;
649
+
638
650
if globals. get ( & ROOT_NODE_VAR . into ( ) ) . is_none ( ) {
639
651
let root_node = self . inject_node ( NodeID :: root ( ) ) ;
640
652
globals
641
653
. add ( ROOT_NODE_VAR . into ( ) , root_node. into ( ) )
642
654
. expect ( "Failed to set ROOT_NODE" ) ;
643
655
}
656
+
644
657
let jump_to_scope_node = self . inject_node ( NodeID :: jump_to ( ) ) ;
645
658
globals
646
659
. add ( JUMP_TO_SCOPE_NODE_VAR . into ( ) , jump_to_scope_node. into ( ) )
647
660
. expect ( "Failed to set JUMP_TO_SCOPE_NODE" ) ;
661
+
648
662
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 ( ) ;
650
664
globals
651
665
. add ( FILE_PATH_VAR . into ( ) , file_name. into ( ) )
652
666
. expect ( "Failed to set FILE_PATH" ) ;
653
667
}
654
668
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
+
655
676
let mut config = ExecutionConfig :: new ( & self . sgl . functions , & globals)
656
677
. lazy ( true )
657
678
. debug_attributes (
0 commit comments