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

Commit 460793f

Browse files
author
Hendrik van Antwerpen
authored
Merge pull request #190 from github/analyze-updates
Updates to `analyze` (and `test`)
2 parents 73905d2 + baa16bb commit 460793f

File tree

7 files changed

+97
-37
lines changed

7 files changed

+97
-37
lines changed

languages/tree-sitter-stack-graphs-typescript/src/stack-graphs.tsg

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2732,7 +2732,7 @@ if none @is_async {
27322732
}
27332733

27342734

2735-
;; Variables
2735+
;; Variables / Identifiers
27362736

27372737
; x;
27382738

@@ -2742,6 +2742,8 @@ if none @is_async {
27422742
(for_in_statement ["var" "let" "const"]?@is_def left:(identifier)@name)
27432743
(assignment_expression left:(identifier)@name)
27442744
(augmented_assignment_expression left:(identifier)@name)
2745+
(asserts (identifier)@name)
2746+
(type_predicate name:(identifier)@name)
27452747
; FIXME type_query has its own restricted expression production
27462748
; we need to do this for every (identifier) inside a type query
27472749
; this cannot be expressed, so we manually unroll three levels here
@@ -2789,6 +2791,8 @@ if none @is_def {
27892791
(for_in_statement ["var" "let" "const"]?@is_def left:(identifier)@name)
27902792
(assignment_expression left:(identifier)@name)
27912793
(augmented_assignment_expression left:(identifier)@name)
2794+
(asserts (identifier)@name)
2795+
(type_predicate name:(identifier)@name)
27922796
; FIXME type_query has its own restricted expression production
27932797
(type_query (identifier)@name)
27942798
(type_query (member_expression object:(identifier)@name))
@@ -4972,9 +4976,6 @@ if none @is_acc {
49724976
)@asserts {
49734977
; propagate lexical scope
49744978
edge @type.lexical_scope -> @asserts.lexical_scope
4975-
4976-
; type is type of inner
4977-
edge @asserts.type -> @type.type
49784979
}
49794980

49804981

@@ -5119,9 +5120,8 @@ if none @is_acc {
51195120
(_)@type
51205121
)@type_pred {
51215122
; propagate lexical scope
5123+
edge @name.lexical_scope -> @type_pred.lexical_scope
51225124
edge @type.lexical_scope -> @type_pred.lexical_scope
5123-
5124-
; FIXME name is a expression reference
51255125
}
51265126

51275127

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function assert(
2+
condition: any,
3+
): asserts condition {
4+
// ^ defined: 2
5+
}
6+
7+
export {}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function assertIsString(
2+
val: any
3+
): asserts val is string {
4+
// ^ defined: 2
5+
}
6+
7+
export {}

tree-sitter-stack-graphs/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3232
- The `--show-ignored` flag of the `test` command has been renamed to `--show-skipped`. Only explicitly skipped test files (with a `.skip` extension) will be shown. Other unsupported files are, such as generated HTML files, are never shown.
3333
- The `--hide-passing` flag of the `test` command has been renamed to the more common `--quiet`/`-q`.
3434
- The output of the `test` command has changed to print the test name before the test result, so that it clear which test is currently running.
35+
- The output of the `test` and `analyze` commands has changed in debug builds to include the run time per file.
36+
- The `--hide-failure-errors` has been renamed to the more general `--hide-error-details`. The new flag is supported by the `test` and `analyze` commands.
37+
- The files in directory arguments are now processed in filename order.
3538

3639
## v0.6.0 -- 2023-01-13
3740

tree-sitter-stack-graphs/src/cli/analyze.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ pub struct AnalyzeArgs {
5959
#[clap(long, short = 'v')]
6060
pub verbose: bool,
6161

62+
/// Hide failure error details.
63+
#[clap(long)]
64+
pub hide_error_details: bool,
65+
6266
/// Maximum runtime per file in seconds.
6367
#[clap(
6468
long,
@@ -78,6 +82,7 @@ impl AnalyzeArgs {
7882
source_paths,
7983
continue_from: None,
8084
verbose: false,
85+
hide_error_details: false,
8186
max_file_time: None,
8287
wait_at_start: false,
8388
}
@@ -93,6 +98,7 @@ impl AnalyzeArgs {
9398
let source_root = source_path;
9499
for source_entry in WalkDir::new(source_root)
95100
.follow_links(true)
101+
.sort_by_file_name()
96102
.into_iter()
97103
.filter_map(|e| e.ok())
98104
.filter(|e| e.file_type().is_file())
@@ -203,7 +209,9 @@ impl AnalyzeArgs {
203209
Err(LoadError::ParseErrors(parse_errors)) => {
204210
let parse_error = map_parse_errors(source_path, &parse_errors, &source, "");
205211
file_status.error("parsing failed")?;
206-
eprintln!("{}", parse_error);
212+
if !self.hide_error_details {
213+
println!("{}", parse_error);
214+
}
207215
return Ok(());
208216
}
209217
Err(LoadError::Cancelled(_)) => {

tree-sitter-stack-graphs/src/cli/test.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ pub struct TestArgs {
9090

9191
/// Hide failure error details.
9292
#[clap(long)]
93-
pub hide_failure_errors: bool,
93+
pub hide_error_details: bool,
9494

9595
/// Show skipped files in output.
9696
#[clap(long)]
@@ -153,7 +153,7 @@ impl TestArgs {
153153
Self {
154154
test_paths,
155155
quiet: false,
156-
hide_failure_errors: false,
156+
hide_error_details: false,
157157
show_skipped: false,
158158
save_graph: None,
159159
save_paths: None,
@@ -169,6 +169,7 @@ impl TestArgs {
169169
let test_root = test_path;
170170
for test_entry in WalkDir::new(test_root)
171171
.follow_links(true)
172+
.sort_by_file_name()
172173
.into_iter()
173174
.filter_map(|e| e.ok())
174175
.filter(|e| e.file_type().is_file())
@@ -336,7 +337,7 @@ impl TestArgs {
336337
result.count(),
337338
))?;
338339
}
339-
if !success && !self.hide_failure_errors {
340+
if !success && !self.hide_error_details {
340341
for failure in result.failures_iter() {
341342
println!("{}", failure);
342343
}

tree-sitter-stack-graphs/src/cli/util.rs

Lines changed: 61 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use std::io::Write;
1313
use std::path::Path;
1414
use std::path::PathBuf;
1515
use std::time::Duration;
16+
use std::time::Instant;
1617
use tree_sitter_graph::parse_error::TreeWithParseErrorVec;
1718

1819
use crate::cli::MAX_PARSE_ERRORS;
@@ -164,6 +165,8 @@ pub struct FileStatusLogger<'a> {
164165
path: &'a Path,
165166
verbose: bool,
166167
path_logged: bool,
168+
#[cfg(debug_assertions)]
169+
processing_started: Option<Instant>,
167170
}
168171

169172
impl<'a> FileStatusLogger<'a> {
@@ -172,50 +175,81 @@ impl<'a> FileStatusLogger<'a> {
172175
path,
173176
verbose,
174177
path_logged: false,
178+
#[cfg(debug_assertions)]
179+
processing_started: None,
175180
}
176181
}
177182

178-
pub fn processing(&mut self) -> Result<(), anyhow::Error> {
179-
self.print_path(false)?;
180-
Ok(())
183+
pub fn processing(&mut self) -> std::io::Result<()> {
184+
#[cfg(debug_assertions)]
185+
{
186+
self.processing_started = Some(Instant::now());
187+
}
188+
if !self.verbose {
189+
return Ok(());
190+
}
191+
self.print_path();
192+
std::io::stdout().flush()
181193
}
182194

183-
pub fn ok(&mut self, status: &str) -> Result<(), anyhow::Error> {
184-
self.print_path(false)?;
185-
if self.verbose {
186-
println!("{}", status.green());
187-
self.path_logged = false;
195+
pub fn ok(&mut self, status: &str) -> std::io::Result<()> {
196+
if !self.verbose {
197+
return Ok(());
188198
}
189-
Ok(())
199+
self.print_path();
200+
print!("{}", status.green());
201+
#[cfg(debug_assertions)]
202+
self.print_processing_time();
203+
println!();
204+
self.path_logged = false;
205+
std::io::stdout().flush()
190206
}
191207

192-
pub fn info(&mut self, status: &str) -> Result<(), anyhow::Error> {
193-
self.print_path(true)?;
194-
println!("{}", status.dimmed());
208+
pub fn info(&mut self, status: &str) -> std::io::Result<()> {
209+
if !self.verbose {
210+
return Ok(());
211+
}
212+
self.print_path();
213+
print!("{}", status.dimmed());
214+
#[cfg(debug_assertions)]
215+
self.print_processing_time();
216+
println!();
195217
self.path_logged = false;
196-
Ok(())
218+
std::io::stdout().flush()
197219
}
198220

199-
pub fn warn(&mut self, status: &str) -> Result<(), anyhow::Error> {
200-
self.print_path(true)?;
201-
println!("{}", status.yellow());
221+
pub fn warn(&mut self, status: &str) -> std::io::Result<()> {
222+
self.print_path();
223+
print!("{}", status.yellow());
224+
#[cfg(debug_assertions)]
225+
self.print_processing_time();
226+
println!();
202227
self.path_logged = false;
203-
Ok(())
228+
std::io::stdout().flush()
204229
}
205230

206-
pub fn error(&mut self, status: &str) -> Result<(), anyhow::Error> {
207-
self.print_path(true)?;
208-
println!("{}", status.red());
231+
pub fn error(&mut self, status: &str) -> std::io::Result<()> {
232+
self.print_path();
233+
print!("{}", status.red());
234+
#[cfg(debug_assertions)]
235+
self.print_processing_time();
236+
println!();
209237
self.path_logged = false;
210-
Ok(())
238+
std::io::stdout().flush()
239+
}
240+
241+
fn print_path(&mut self) {
242+
if self.path_logged {
243+
return;
244+
}
245+
print!("{}: ", self.path.display());
246+
self.path_logged = true;
211247
}
212248

213-
fn print_path(&mut self, force: bool) -> Result<(), anyhow::Error> {
214-
if (self.verbose || force) && !self.path_logged {
215-
print!("{}: ", self.path.display());
216-
std::io::stdout().flush()?;
217-
self.path_logged = true;
249+
#[cfg(debug_assertions)]
250+
fn print_processing_time(&mut self) {
251+
if let Some(processing_started) = self.processing_started {
252+
print!(" [{:.2} s]", processing_started.elapsed().as_secs_f64());
218253
}
219-
Ok(())
220254
}
221255
}

0 commit comments

Comments
 (0)