@@ -9,6 +9,7 @@ use stack_graphs::graph::StackGraph;
9
9
use tree_sitter_graph:: Variables ;
10
10
use tree_sitter_stack_graphs:: NoCancellation ;
11
11
use tree_sitter_stack_graphs:: StackGraphLanguage ;
12
+ use tree_sitter_stack_graphs:: FILE_PATH_VAR ;
12
13
13
14
use crate :: edges:: check_stack_graph_edges;
14
15
use crate :: nodes:: check_stack_graph_nodes;
@@ -22,12 +23,18 @@ fn can_support_preexisting_nodes() {
22
23
"# ;
23
24
let python = "pass" ;
24
25
26
+ let file_name = "test.py" ;
27
+
25
28
let mut graph = StackGraph :: new ( ) ;
26
- let file = graph. get_or_create_file ( "test.py" ) ;
29
+ let file = graph. get_or_create_file ( file_name ) ;
27
30
let node_id = graph. new_node_id ( file) ;
28
31
let _preexisting_node = graph. add_scope_node ( node_id, true ) . unwrap ( ) ;
29
32
30
- let globals = Variables :: new ( ) ;
33
+ let mut globals = Variables :: new ( ) ;
34
+ globals
35
+ . add ( FILE_PATH_VAR . into ( ) , file_name. into ( ) )
36
+ . expect ( "failed to add file path variable" ) ;
37
+
31
38
let language = StackGraphLanguage :: from_str ( tree_sitter_python:: language ( ) , tsg) . unwrap ( ) ;
32
39
language
33
40
. build_stack_graph_into ( & mut graph, file, python, & globals, & NoCancellation )
@@ -45,15 +52,21 @@ fn can_support_injected_nodes() {
45
52
"# ;
46
53
let python = "pass" ;
47
54
55
+ let file_name = "test.py" ;
56
+
48
57
let mut graph = StackGraph :: new ( ) ;
49
- let file = graph. get_or_create_file ( "test.py" ) ;
58
+ let file = graph. get_or_create_file ( file_name ) ;
50
59
let node_id = graph. new_node_id ( file) ;
51
60
let _preexisting_node = graph. add_scope_node ( node_id, true ) . unwrap ( ) ;
52
61
53
62
let language = StackGraphLanguage :: from_str ( tree_sitter_python:: language ( ) , tsg) . unwrap ( ) ;
54
63
let mut builder = language. builder_into_stack_graph ( & mut graph, file, python) ;
55
64
56
65
let mut globals = Variables :: new ( ) ;
66
+ globals
67
+ . add ( FILE_PATH_VAR . into ( ) , file_name. into ( ) )
68
+ . expect ( "failed to add file path variable" ) ;
69
+
57
70
globals
58
71
. add ( "EXT_NODE" . into ( ) , builder. inject_node ( node_id) . into ( ) )
59
72
. expect ( "Failed to add EXT_NODE variable" ) ;
0 commit comments