65 lines
2.2 KiB
Rust
65 lines
2.2 KiB
Rust
use crate::{
|
||
alignment::align_function,
|
||
config::EffectiveConfig,
|
||
diagnostics::Diagnostic,
|
||
input::SourceDocument,
|
||
metrics::{measure_module_function, FunctionNarrative},
|
||
rules::{
|
||
check_aligned, check_ast_document, check_entry_for_heading, check_function_documentation,
|
||
check_supplemental_function,
|
||
},
|
||
};
|
||
|
||
#[derive(Debug, Clone)]
|
||
pub struct DocumentAnalysis {
|
||
pub diagnostics: Vec<Diagnostic>,
|
||
pub metrics: Vec<FunctionNarrative>,
|
||
pub alignment_issues: Vec<String>,
|
||
}
|
||
|
||
pub fn analyze_document(document: &SourceDocument, config: &EffectiveConfig) -> DocumentAnalysis {
|
||
let markdown = &document.markdown;
|
||
let mut diagnostics = check_ast_document(document);
|
||
let mut metrics = Vec::new();
|
||
let mut alignment_issues = Vec::new();
|
||
if let Some(module) = &document.module {
|
||
for function in &module.functions {
|
||
let tree = align_function(markdown, function);
|
||
if !tree.complete {
|
||
alignment_issues.extend(
|
||
tree.issues
|
||
.iter()
|
||
.map(|issue| format!("{}:{}", function.local_name, issue)),
|
||
);
|
||
if let Some(heading) = markdown.function_segment(&function.id) {
|
||
diagnostics.extend(check_entry_for_heading(markdown, heading));
|
||
}
|
||
continue;
|
||
}
|
||
diagnostics.extend(check_aligned(markdown, &tree));
|
||
diagnostics.extend(check_supplemental_function(
|
||
markdown,
|
||
function,
|
||
&module.calls,
|
||
&tree,
|
||
));
|
||
if let Some(narrative) =
|
||
measure_module_function(markdown, function, &module.calls, config.narrative)
|
||
{
|
||
diagnostics.extend(check_function_documentation(
|
||
markdown,
|
||
&narrative,
|
||
config.narrative,
|
||
));
|
||
metrics.push(narrative);
|
||
}
|
||
}
|
||
}
|
||
diagnostics.sort_by(|left, right| (left.span, &left.id).cmp(&(right.span, &right.id)));
|
||
DocumentAnalysis {
|
||
diagnostics,
|
||
metrics,
|
||
alignment_issues,
|
||
}
|
||
}
|