use calamine::{Reader, SheetType};
use crate::model::{
Diagnostic, DiagnosticKind, DiagnosticLocation, DiffStage, Severity,
};
use crate::open::OpenedWorkbook;
#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
pub enum ObjectCompareMode {
Ignore,
#[default]
WarnIfPresent,
CompareAvailable,
}
pub fn report_object_coverage(
old_wb: &mut OpenedWorkbook,
new_wb: &mut OpenedWorkbook,
mode: ObjectCompareMode,
diagnostics: &mut Vec<Diagnostic>,
) {
if mode == ObjectCompareMode::Ignore {
return;
}
detect_non_worksheet_sheets(old_wb, diagnostics);
detect_non_worksheet_sheets(new_wb, diagnostics);
emit_coverage_note(diagnostics);
}
fn detect_non_worksheet_sheets(wb: &mut OpenedWorkbook, diagnostics: &mut Vec<Diagnostic>) {
for (index, sheet) in wb.reader.sheets_metadata().iter().enumerate() {
let kind = match sheet.typ {
SheetType::ChartSheet => Some("chart sheet"),
SheetType::MacroSheet => Some("macro sheet"),
SheetType::Vba => Some("VBA module"),
SheetType::DialogSheet => Some("dialog sheet"),
SheetType::WorkSheet => None, };
if let Some(kind_label) = kind {
diagnostics.push(Diagnostic {
severity: Severity::Warning,
kind: DiagnosticKind::UnsupportedWorkbookFeature {
feature: kind_label.to_owned(),
},
location: DiagnosticLocation {
stage: DiffStage::Metadata,
sheet_order: Some(index),
sheet_name: Some(sheet.name.clone()),
address: None,
},
message: format!(
"sheet '{}' is a {} — content not compared \
(calamine 0.35 does not expose {} data)",
sheet.name, kind_label, kind_label
),
});
}
}
}
fn emit_coverage_note(diagnostics: &mut Vec<Diagnostic>) {
diagnostics.push(Diagnostic {
severity: Severity::Info,
kind: DiagnosticKind::UnsupportedWorkbookFeature {
feature: "non-cell objects".to_owned(),
},
location: DiagnosticLocation {
stage: DiffStage::Metadata,
sheet_order: None,
sheet_name: None,
address: None,
},
message: "charts, images, comments, hyperlinks, tables, pivot tables, \
data validation, and conditional formatting are not compared \
in this version (calamine 0.35 does not expose object content)"
.into(),
});
}