feat: provide a rebuild flag to force rebuild parsers

This commit is contained in:
Amaan Qureshi 2024-09-24 11:05:08 -04:00
parent 1aa28e04ee
commit 52f696096d
2 changed files with 16 additions and 1 deletions

View file

@ -132,6 +132,7 @@ pub struct Loader {
use_all_highlight_names: bool,
debug_build: bool,
sanitize_build: bool,
force_rebuild: bool,
#[cfg(feature = "wasm")]
wasm_store: Mutex<Option<tree_sitter::WasmStore>>,
@ -200,6 +201,7 @@ impl Loader {
use_all_highlight_names: true,
debug_build: false,
sanitize_build: false,
force_rebuild: false,
#[cfg(feature = "wasm")]
wasm_store: Mutex::default(),
@ -474,7 +476,7 @@ impl Loader {
fs::create_dir_all(&self.parser_lib_path)?;
}
let mut recompile = config.output_path.is_some(); // if specified, always recompile
let mut recompile = self.force_rebuild || config.output_path.is_some(); // if specified, always recompile
let output_path = config.output_path.unwrap_or_else(|| {
let mut path = self.parser_lib_path.join(lib_name);
@ -1185,6 +1187,10 @@ impl Loader {
self.sanitize_build = flag;
}
pub fn force_rebuild(&mut self, rebuild: bool) {
self.force_rebuild = rebuild;
}
#[cfg(feature = "wasm")]
pub fn use_wasm(&mut self, engine: &tree_sitter::wasmtime::Engine) {
*self.wasm_store.lock().unwrap() = Some(tree_sitter::WasmStore::new(engine).unwrap());