Skip to main content

format_node_range_with_alignment

Function format_node_range_with_alignment 

Source
pub fn format_node_range_with_alignment(
    node: &SyntaxNode,
    range: TextRange,
    alignment: PostingAlignment,
) -> Option<(TextRange, String)>
Expand description

Like format_node_range but skips the per-call compute_alignment walk by accepting a precomputed PostingAlignment.

The cache pattern is identical to format_node_with_alignment: parse → take ParseResult::alignment → call this function. The hot path the cache addresses is the LSP textDocument/rangeFormatting fallback (CST-snap path that fires on parse-error files), which can be invoked per-keystroke through format-on-type clients. Without the cache the per-call cost is O(N_postings_in_file); with the cache it’s O(N_cst_nodes covered by range).

alignment MUST match what compute_alignment(&SourceFile::cast(node).unwrap()) would return for the given node; pinned by format_node_range_matches_format_node_range_with_alignment. Same range semantics, ERROR_NODE policy, snap rules, and # Panics precondition as format_node_range.