feat(cli): rebuild parsers by default when --grammar-path is passed.

This commit is contained in:
Will Lillis 2025-06-07 02:57:57 -04:00
parent 1562b719d2
commit aed8b8b32c

View file

@ -182,8 +182,8 @@ struct Parse {
/// The source file(s) to use
#[arg(num_args=1..)]
pub paths: Option<Vec<PathBuf>>,
/// The path to the tree-sitter grammar directory
#[arg(long, short = 'p')]
/// The path to the tree-sitter grammar directory, implies --rebuild
#[arg(long, short = 'p', conflicts_with = "rebuild")]
pub grammar_path: Option<PathBuf>,
/// The path to the parser's dynamic library
#[arg(long, short = 'l')]
@ -280,8 +280,8 @@ struct Test {
/// Only run corpus test cases from a given filename
#[arg(long)]
pub file_name: Option<String>,
/// The path to the tree-sitter grammar directory
#[arg(long, short = 'p')]
/// The path to the tree-sitter grammar directory, implies --rebuild
#[arg(long, short = 'p', conflicts_with = "rebuild")]
pub grammar_path: Option<PathBuf>,
/// The path to the parser's dynamic library
#[arg(long, short = 'l')]
@ -346,8 +346,8 @@ struct Fuzz {
/// Subdirectory to the language
#[arg(long)]
pub subdir: Option<PathBuf>,
/// The path to the tree-sitter grammar directory
#[arg(long, short = 'p')]
/// The path to the tree-sitter grammar directory, implies --rebuild
#[arg(long, short = 'p', conflicts_with = "rebuild")]
pub grammar_path: Option<PathBuf>,
/// The path to the parser's dynamic library
#[arg(long)]
@ -385,8 +385,8 @@ struct Query {
/// Path to a file with queries
#[arg(index = 1, required = true)]
query_path: PathBuf,
/// The path to the tree-sitter grammar directory
#[arg(long, short = 'p')]
/// The path to the tree-sitter grammar directory, implies --rebuild
#[arg(long, short = 'p', conflicts_with = "rebuild")]
pub grammar_path: Option<PathBuf>,
/// The path to the parser's dynamic library
#[arg(long, short = 'l')]
@ -467,8 +467,8 @@ struct Highlight {
/// The source file(s) to use
#[arg(num_args = 1..)]
pub paths: Option<Vec<PathBuf>>,
/// The path to the tree-sitter grammar directory
#[arg(long, short = 'p')]
/// The path to the tree-sitter grammar directory, implies --rebuild
#[arg(long, short = 'p', conflicts_with = "rebuild")]
pub grammar_path: Option<PathBuf>,
/// The path to an alternative config.json file
#[arg(long)]
@ -499,8 +499,8 @@ struct Tags {
/// The source file(s) to use
#[arg(num_args = 1..)]
pub paths: Option<Vec<PathBuf>>,
/// The path to the tree-sitter grammar directory
#[arg(long, short = 'p')]
/// The path to the tree-sitter grammar directory, implies --rebuild
#[arg(long, short = 'p', conflicts_with = "rebuild")]
pub grammar_path: Option<PathBuf>,
/// The path to an alternative config.json file
#[arg(long)]
@ -985,7 +985,7 @@ impl Parse {
let mut parser = Parser::new();
loader.debug_build(self.debug_build);
loader.force_rebuild(self.rebuild);
loader.force_rebuild(self.rebuild || self.grammar_path.is_some());
#[cfg(feature = "wasm")]
if self.wasm {
@ -1165,7 +1165,7 @@ impl Test {
let stat = self.stat.unwrap_or_default();
loader.debug_build(self.debug_build);
loader.force_rebuild(self.rebuild);
loader.force_rebuild(self.rebuild || self.grammar_path.is_some());
let mut parser = Parser::new();
@ -1321,7 +1321,7 @@ impl Version {
impl Fuzz {
fn run(self, mut loader: loader::Loader, current_dir: &Path) -> Result<()> {
loader.sanitize_build(true);
loader.force_rebuild(self.rebuild);
loader.force_rebuild(self.rebuild || self.grammar_path.is_some());
if self.lib_path.is_none() && self.lang_name.is_some() {
eprintln!("Warning: --lang-name` specified without --lib-path. This argument will be ignored.");
@ -1373,6 +1373,7 @@ impl Query {
fn run(self, mut loader: loader::Loader, current_dir: &Path) -> Result<()> {
let config = Config::load(self.config_path)?;
let loader_config = config.get()?;
loader.force_rebuild(self.rebuild || self.grammar_path.is_some());
loader.find_all_languages(&loader_config)?;
let query_path = Path::new(&self.query_path);
@ -1504,7 +1505,7 @@ impl Highlight {
loader.configure_highlights(&theme_config.theme.highlight_names);
let loader_config = config.get()?;
loader.find_all_languages(&loader_config)?;
loader.force_rebuild(self.rebuild);
loader.force_rebuild(self.rebuild || self.grammar_path.is_some());
let cancellation_flag = util::cancel_on_signal();
@ -1659,7 +1660,7 @@ impl Tags {
let config = Config::load(self.config_path)?;
let loader_config = config.get()?;
loader.find_all_languages(&loader_config)?;
loader.force_rebuild(self.rebuild);
loader.force_rebuild(self.rebuild || self.grammar_path.is_some());
let cancellation_flag = util::cancel_on_signal();