Skip to main content

Module edit

Module edit 

Source
Expand description

CST mutation operations (add, remove, update fields). Edit engine for surgical CST mutations that preserve formatting.

Edits work by producing TextEdits (insertions/deletions at byte offsets) that are collected in an EditBatch and applied atomically to the source string. After applying, the caller re-parses from scratch to get a fresh CST + AST.

The key challenge is list field editing: .cabal files use several different formatting styles for list fields (single-line, leading-comma, trailing-comma, no-comma), and the edit engine must detect and follow the existing style.

Structs§

EditBatch
A batch of edits to apply atomically.
TextEdit
A text edit to apply to the source.

Enums§

ListStyle
The detected formatting style of a list field.

Functions§

add_field_to_root
Add a new top-level metadata field to the root of the file.
add_field_to_section
Add a new field to a section at the end (before any conditionals).
add_list_item
Add an item to a list field (e.g., add a dependency to build-depends).
add_section
Add a new top-level section to the end of the file.
detect_list_style
Detect the list style of a field node.
find_field
Find a field node within a section (or the root) by field name.
find_section
Find a section node by keyword and optional name.
remove_list_item
Remove an item from a list field by prefix match on the item name.
set_field_value
Set a simple scalar field value. Replaces the current value text.