feat(cli): add a no-ranges flag to the parse command

This commit is contained in:
Amaan Qureshi 2024-09-26 22:23:22 -04:00
parent e04387258b
commit 9ef12624c3
2 changed files with 12 additions and 9 deletions

View file

@ -191,6 +191,8 @@ struct Parse {
pub test_number: Option<u32>,
#[arg(short, long, help = "Force rebuild the parser")]
pub rebuild: bool,
#[arg(long, help = "Omit ranges in the output")]
pub no_ranges: bool,
}
#[derive(Args)]
@ -605,6 +607,7 @@ impl Parse {
cancellation_flag: Some(&cancellation_flag),
encoding,
open_log: self.open_log,
no_ranges: self.no_ranges,
};
let parse_result = parse::parse_file_at_path(&mut parser, &opts)?;

View file

@ -60,6 +60,7 @@ pub struct ParseFileOptions<'a> {
pub cancellation_flag: Option<&'a AtomicUsize>,
pub encoding: Option<u32>,
pub open_log: bool,
pub no_ranges: bool,
}
#[derive(Copy, Clone)]
@ -178,15 +179,14 @@ pub fn parse_file_at_path(parser: &mut Parser, opts: &ParseFileOptions) -> Resul
if let Some(field_name) = cursor.field_name() {
write!(&mut stdout, "{field_name}: ")?;
}
write!(
&mut stdout,
"({} [{}, {}] - [{}, {}]",
node.kind(),
start.row,
start.column,
end.row,
end.column
)?;
write!(&mut stdout, "({}", node.kind())?;
if !opts.no_ranges {
write!(
&mut stdout,
" [{}, {}] - [{}, {}]",
start.row, start.column, end.row, end.column
)?;
}
needs_newline = true;
}
if cursor.goto_first_child() {