mirror of
https://github.com/encounter/objdiff.git
synced 2025-12-20 02:15:24 +00:00
Support overriding diff options in project config (& for individual units) (#263)
* Support loading diff options from project config * Support per-unit option overrides
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
use anyhow::Result;
|
||||
use globset::Glob;
|
||||
use objdiff_core::config::{default_ignore_patterns, default_watch_patterns, try_project_config};
|
||||
use objdiff_core::{
|
||||
config::{
|
||||
apply_project_options, default_ignore_patterns, default_watch_patterns, try_project_config,
|
||||
},
|
||||
diff::DiffObjConfig,
|
||||
};
|
||||
use typed_path::{Utf8UnixComponent, Utf8UnixPath};
|
||||
|
||||
use crate::app::{AppState, ObjectConfig};
|
||||
@@ -124,6 +129,38 @@ pub fn load_project_config(state: &mut AppState) -> Result<()> {
|
||||
state.object_nodes = build_nodes(&mut state.objects);
|
||||
state.current_project_config = Some(project_config);
|
||||
state.project_config_info = Some(info);
|
||||
if let Some(options) =
|
||||
state.current_project_config.as_ref().and_then(|project| project.options.as_ref())
|
||||
{
|
||||
let mut diff_config = DiffObjConfig::default();
|
||||
if let Err(e) = apply_project_options(&mut diff_config, options) {
|
||||
log::error!("Failed to apply project config options: {e:#}");
|
||||
state.show_error_toast("Failed to apply project config options", &e);
|
||||
}
|
||||
}
|
||||
if let Some(project) = state.current_project_config.as_ref()
|
||||
&& let Some(units) = project.units.as_deref()
|
||||
{
|
||||
let mut unit_option_errors = Vec::new();
|
||||
for unit in units {
|
||||
if let Some(options) = unit.options() {
|
||||
let mut diff_config = DiffObjConfig::default();
|
||||
if let Err(e) = apply_project_options(&mut diff_config, options) {
|
||||
unit_option_errors.push((unit.name().to_string(), e));
|
||||
}
|
||||
}
|
||||
}
|
||||
for (unit_name, error) in unit_option_errors {
|
||||
log::error!(
|
||||
"Failed to apply project config options for unit {}: {error:#}",
|
||||
unit_name
|
||||
);
|
||||
state.show_error_toast(
|
||||
&format!("Failed to apply project config options for unit {unit_name}"),
|
||||
&error,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Reload selected object
|
||||
if let Some(selected_obj) = &state.config.selected_obj {
|
||||
|
||||
Reference in New Issue
Block a user