Skip to content
This repository was archived by the owner on Sep 9, 2025. It is now read-only.

Commit c783935

Browse files
author
Hendrik van Antwerpen
committed
Read globals
1 parent dcec17e commit c783935

File tree

1 file changed

+15
-8
lines changed
  • languages/tree-sitter-stack-graphs-typescript/rust

1 file changed

+15
-8
lines changed

languages/tree-sitter-stack-graphs-typescript/rust/tsconfig.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ use stack_graphs::graph::StackGraph;
1919
use tree_sitter_stack_graphs::FileAnalyzer;
2020
use tree_sitter_stack_graphs::LoadError;
2121

22-
const PACKAGE_NAME: &str = ""; // FIXME should be a parameter to TsConfigAnalyzer
23-
const PROJECT_NAME: &str = ""; // FIXME should be a parameter to TsConfigAnalyzer
24-
2522
const M_NS: &str = "%M";
2623
const NON_REL_M_NS: &str = "%NonRelM";
2724
const PROJ_NS: &str = "%Proj";
@@ -37,9 +34,20 @@ impl FileAnalyzer for TsConfigAnalyzer {
3734
path: &Path,
3835
source: &str,
3936
all_paths: &mut dyn Iterator<Item = &'a Path>,
40-
_globals: &HashMap<String, String>,
37+
globals: &HashMap<String, String>,
4138
_cancellation_flag: &dyn tree_sitter_stack_graphs::CancellationFlag,
4239
) -> Result<(), tree_sitter_stack_graphs::LoadError> {
40+
// read globals
41+
let pkg_name = globals
42+
.get("PACKAGE_NAME")
43+
.map(String::as_str)
44+
.unwrap_or("");
45+
let proj_name = globals
46+
.get("PROJECT_NAME")
47+
.map(String::as_str)
48+
.unwrap_or("");
49+
50+
// parse source
4351
let tsc = TsConfig::parse_str(path, source).map_err(|_| LoadError::ParseError)?;
4452

4553
// root node
@@ -51,12 +59,12 @@ impl FileAnalyzer for TsConfigAnalyzer {
5159
self.add_debug_name(graph, proj_scope, "proj_scope");
5260

5361
// project definition
54-
let proj_def = self.add_ns_pop(graph, file, root, PROJ_NS, PROJECT_NAME);
62+
let proj_def = self.add_ns_pop(graph, file, root, PROJ_NS, proj_name);
5563
self.add_debug_name(graph, proj_def, "proj_def");
5664
self.add_edge(graph, proj_def, proj_scope, 0);
5765

5866
// project reference
59-
let proj_ref = self.add_ns_push(graph, file, root, PROJ_NS, PROJECT_NAME);
67+
let proj_ref = self.add_ns_push(graph, file, root, PROJ_NS, proj_name);
6068
self.add_debug_name(graph, proj_ref, "proj_ref");
6169
self.add_edge(graph, proj_scope, proj_ref, 0);
6270

@@ -66,8 +74,7 @@ impl FileAnalyzer for TsConfigAnalyzer {
6674
self.add_debug_name(graph, root_dir_ref, "root_dir.ref");
6775

6876
// package definition
69-
let pkg_def =
70-
self.add_module_pops(graph, file, NON_REL_M_NS, Path::new(PACKAGE_NAME), root);
77+
let pkg_def = self.add_module_pops(graph, file, NON_REL_M_NS, Path::new(pkg_name), root);
7178
self.add_debug_name(graph, pkg_def, "pkg_def");
7279
self.add_edge(graph, pkg_def, root_dir_ref, 0);
7380

0 commit comments

Comments
 (0)