Skip to main content

Module visit

Module visit 

Source
Expand description

Visitors for AST positions that carry a currency or an account name.

These exist because hand-rolled “for each currency / for each account” walks across the AST kept missing positions. The earlier pattern was: every consumer (LSP completion, hover usage count, WASM editor extraction, etc.) wrote its own walk over Directive variants, and silently dropped any position the author happened not to remember (Note.account, Posting.cost.currency, MetaValue::Account metadata values, Custom.values, …). Fixing it in five different files left the underlying problem intact: the next contributor writing a “for each X” walk will reach for the same shape and reintroduce the same bug class.

These visitors are the canonical answer. Every position that carries a currency or an account name is enumerated exactly once here, with no _ => {} catch-all — at any layer of the match. That means:

  • A future Directive variant added to the enum forces a compile error at the top-level visit_* match.
  • A future MetaValue variant forces a compile error at visit_meta_value_currency and visit_meta_value_account.
  • A future PriceAnnotation variant forces a compile error at visit_price_currency.

This file is the ONE place that needs to be updated when new variants are added to any of those enums. Downstream consumers calling visit_* benefit automatically.

Spans of source tokens are intentionally NOT exposed here: source positions are parser-only metadata published via ParseResult::currency_occurrences (the parser is the canonical owner of source-position data). Value-level consumers (extract, hover usage count, completion suggestions) want the strings; source-position consumers (LSP rename / references / document-highlight / linked-editing / goto-definition) consume the parser’s index. Separating the concerns keeps the AST value types pure.

Functions§

visit_accounts
Walk every position an account name can appear in this directive, invoking visit once per occurrence.
visit_currencies
Walk every position a currency name can appear in this directive, invoking visit once per occurrence.
visit_links
Walk every position a link can appear in this directive, invoking visit once per occurrence (link text without the ^ sigil).
visit_tags
Walk every position a tag can appear in this directive, invoking visit once per occurrence (tag text without the # sigil).