Position Mapping
Bidirectional mapping between Mist source positions and Rust output positions for error remapping and LSP features.
Mist maintains a bidirectional mapping between Mist source positions and Rust output positions. This is essential for:
- Error remapping — Rust compiler errors point to the correct Mist source location
- LSP features — Go-to-definition, hover, and completion work from Mist source
Data Structure
The mapping is stored as pairs:
pub struct Mapping {
pub mist_path: PathBuf,
pub map: HashSet<(RustMap, MistMap)>,
}RustMap(usize, usize)— line/column in generated RustMistMap(usize, usize)— line/column in original Mist
Mapping Lifecycle
- Codegen — Each
Spanned<T>AST node records its Mist position and the current Rust position in the codegen output buffer viaGenSpanTranslation - Persistence — The mapping is serialized to
<output>.map.jsonalongside the transpiled.rsoutput - Build-time remapping — The builder reads
.map.jsonto remapcargodiagnostics back to Mist positions - LSP remapping — Both Mist→Rust and Rust→Mist direction queries are supported via
find()andfind_by_mist()