Skip to content

Commit f3548fb

Browse files
committed
chore: clenup after review
1 parent 8a98dce commit f3548fb

File tree

4 files changed

+16
-22
lines changed

4 files changed

+16
-22
lines changed

tree-sitter-stack-graphs/src/lib.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -435,10 +435,16 @@ static SCOPE_ATTRS: Lazy<HashSet<&'static str>> =
435435
static PRECEDENCE_ATTR: &'static str = "precedence";
436436

437437
// Global variables
438-
static ROOT_NODE_VAR: &'static str = "ROOT_NODE";
439-
static JUMP_TO_SCOPE_NODE_VAR: &'static str = "JUMP_TO_SCOPE_NODE";
440-
static FILE_PATH_VAR: &'static str = "FILE_PATH";
441-
static ROOT_PATH_VAR: &'static str = "ROOT_PATH";
438+
/// Name of the variable used to pass the root node.
439+
pub const ROOT_NODE_VAR: &'static str = "ROOT_NODE";
440+
/// Name of the variable used to pass the jump-to-scope node.
441+
pub const JUMP_TO_SCOPE_NODE_VAR: &'static str = "JUMP_TO_SCOPE_NODE";
442+
/// Name of the variable used to pass the file path.
443+
/// If a root path is given, it should be a descendant the root path.
444+
pub const FILE_PATH_VAR: &'static str = "FILE_PATH";
445+
/// Name of the variable used to pass the root path.
446+
/// If given, should be an ancestor of the file path.
447+
pub const ROOT_PATH_VAR: &'static str = "ROOT_PATH";
442448

443449
/// Holds information about how to construct stack graphs for a particular language.
444450
pub struct StackGraphLanguage {
@@ -649,11 +655,6 @@ impl<'a> Builder<'a> {
649655
.add(JUMP_TO_SCOPE_NODE_VAR.into(), jump_to_scope_node.into())
650656
.expect("Failed to set JUMP_TO_SCOPE_NODE");
651657

652-
// FILE_PATH is mandatory
653-
globals
654-
.get(&FILE_PATH_VAR.into())
655-
.expect("FILE_PATH not set");
656-
657658
let mut config = ExecutionConfig::new(&self.sgl.functions, &globals)
658659
.lazy(true)
659660
.debug_attributes(

tree-sitter-stack-graphs/src/loader.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ use crate::FileAnalyzer;
3131
use crate::StackGraphLanguage;
3232
use crate::FILE_PATH_VAR;
3333

34+
const BUILTINS_FILENAME: &str = "<builtins>";
35+
3436
pub static DEFAULT_TSG_PATHS: Lazy<Vec<LoadPath>> =
3537
Lazy::new(|| vec![LoadPath::Grammar("queries/stack-graphs".into())]);
3638
pub static DEFAULT_BUILTINS_PATHS: Lazy<Vec<LoadPath>> =
@@ -77,18 +79,14 @@ impl LanguageConfiguration {
7779
if let Some((builtins_path, builtins_source)) = builtins_source {
7880
let mut builtins_globals = Variables::new();
7981

80-
let builtins_path_var = Path::new("<builtins>");
8182
builtins_globals
82-
.add(
83-
FILE_PATH_VAR.into(),
84-
builtins_path_var.to_str().unwrap().into(),
85-
)
83+
.add(FILE_PATH_VAR.into(), BUILTINS_FILENAME.into())
8684
.expect("failed to add file path variable");
8785

8886
if let Some(builtins_config) = builtins_config {
8987
Loader::load_globals_from_config_str(builtins_config, &mut builtins_globals)?;
9088
}
91-
let file = builtins.add_file("<builtins>").unwrap();
89+
let file = builtins.add_file(BUILTINS_FILENAME).unwrap();
9290
sgl.build_stack_graph_into(
9391
&mut builtins,
9492
file,

tree-sitter-stack-graphs/tests/it/builder.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,14 @@
44
// Licensed under either of Apache License, Version 2.0, or MIT license, at your option.
55
// Please see the LICENSE-APACHE or LICENSE-MIT files in this distribution for license details.
66
// ------------------------------------------------------------------------------------------------
7-
8-
use std::path::Path;
9-
107
use stack_graphs::graph::StackGraph;
118
use tree_sitter_graph::Variables;
129
use tree_sitter_stack_graphs::NoCancellation;
1310
use tree_sitter_stack_graphs::StackGraphLanguage;
11+
use tree_sitter_stack_graphs::FILE_PATH_VAR;
1412

1513
use crate::edges::check_stack_graph_edges;
1614
use crate::nodes::check_stack_graph_nodes;
17-
use crate::FILE_PATH_VAR;
1815

1916
#[test]
2017
fn can_support_preexisting_nodes() {

tree-sitter-stack-graphs/tests/it/main.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ use tree_sitter_graph::Variables;
1414
use tree_sitter_stack_graphs::BuildError;
1515
use tree_sitter_stack_graphs::NoCancellation;
1616
use tree_sitter_stack_graphs::StackGraphLanguage;
17-
18-
static FILE_PATH_VAR: &'static str = "FILE_PATH";
17+
use tree_sitter_stack_graphs::FILE_PATH_VAR;
1918

2019
mod builder;
2120
mod edges;
@@ -35,7 +34,6 @@ pub(self) fn build_stack_graph(
3534
let mut globals = Variables::new();
3635
let source_path = Path::new(file_name);
3736

38-
// The FILE_PATH_VAR is not accessible here
3937
globals
4038
.add(FILE_PATH_VAR.into(), source_path.to_str().unwrap().into())
4139
.expect("failed to add file path variable");

0 commit comments

Comments
 (0)