pub fn format_module(
module: &Module,
source: &str,
) -> Result<String, FormatSourceError>Expand description
Formats every module item in order, preserving attached file-boundary comments.
- Precondition: spans and attached trivia refer to
source, or use synthetic spans with"". - Complexity: O(n + v + b + g + c + p) time plus delegated CEL layout, for source bytes n, visited AST nodes v, emitted bytes b including indentation, summed scanned region bytes g, converted character prefixes c, and measured output-line prefixes p. O(l + b + g + h) space plus CEL layout storage, for source lines l and writer call depth h. Repeated prefix/region work is not globally linear. Rejection also copies the recorded diagnostics in time and space proportional to their count and owned text.
§Errors
Returns Recovered for any recorded syntax error or recovery placeholder.
§Examples
let source = "sheet helper() {} sheet root {}";
let mut module = adam_lang::AdamAstParser::new().parse_module_str(source).unwrap();
adam_lang::attach_module_trivia(source, &mut module);
let formatted = adam_lang::format_module(&module, source).unwrap();
assert_eq!(adam_lang::format_source(&formatted).unwrap(), formatted);