Skip to main content

Module index_queries

Module index_queries 

Source
Expand description

v0.25 (ADR 0053): pure queries over the project binding index.

Everything here is a pure function over ProjectIndex + analysed snapshot texts — the unit-testable core behind textDocument/references and rename/prepareRename. Transport-side handlers in main.rs only convert positions and package results.

Rename is validated two ways, both correct-by-construction:

  1. Collisions — apply the edits to an overlay, re-run diagnose_project, refuse if a new diagnostic appears (no_new_diagnostics).
  2. Capture/escape — re-analysis alone misses silent re-binding (declared fns shadow fn-typed locals in call position), so the re-built index must equal the pre-index modulo the rename (index_unchanged_modulo_rename).

Structs§

CallRelation
v0.34 (ADR 0067): one end of a call-hierarchy relation — the related symbol (key + its definition site) and the call sites linking it to the queried symbol. For incoming calls key is a caller and sites are where it calls the queried symbol; for outgoing, key is a callee and sites are where the queried symbol calls it. The sites double as the LSP fromRanges (identical for both directions).
RenamePlan
A planned rename: every name-segment edit, grouped per file, spans ascending. The definition site is edited along with every reference.

Constants§

MOD_DECLARATION 🔒
MOD_OPAQUE 🔒
MOD_PLATFORM_NATIVE 🔒
MOD_REFINED 🔒
TOK_LOCAL 🔒
Legend index of the variable token type (locals; ADR 0064).

Functions§

apply_edits
Apply one file’s edits (spans ascending) to its snapshot text.
code_lenses
v0.33 (ADR 0066): codeLens — one reference-count lens per top-level definition in path, as (def site, reference sites). The count is refs.len(); the reference sites feed the showReferences action. Sorted by definition position (a stable, top-to-bottom lens order).
definition_at
The definition site for the symbol at the cursor (an index-backed, binding-correct go-to-definition).
document_highlights
v0.26 rider (ADR 0055): documentHighlight — the symbol-at-cursor’s occurrences within that same file (the references query, file-scoped). The index does not distinguish read from write references, so the LSP layer omits the highlight kind.
group_calls 🔒
Group edges by the key returned by pick, attach each grouped symbol’s definition, and collect the call sites — the shared core of incoming and outgoing calls. Groups with no indexed definition are dropped (defensive; every call-edge endpoint is an index symbol by construction). Groups are ordered by definition position for a stable, top-to-bottom listing.
implementations
v0.35 (ADR 0068): textDocument/implementation — the definition sites of every provider implementing the capability key, sorted by definition position. Empty for a non-capability or unknown key (the request then falls through; goto-def still serves the reverse, provider → capability).
incoming_calls
v0.34 (ADR 0067): callHierarchy/incomingCalls — the callers of key, each with the call sites at which it calls key.
index_unchanged_modulo_rename
Validator (2): the re-built index must equal the pre-index modulo the rename — every other symbol’s reference set identical (after remapping shifted spans), the renamed symbol’s sites exactly the edited ones. Catches silent re-binding (capture/escape) that produces no diagnostic.
key_segment 🔒
The member segment of a (possibly compound) key name — the text the rename actually edits (every site span covers exactly this).
modifier_bits 🔒
named_type_target
The user-declared type a value’s type points at, for go-to-type-definition: a Named directly, or the element of a single-parameter container (Option/Effect/List/HttpResult) unwrapped to it. Built-in, function, actor, and two-parameter (Result/Map) types have no single type-declaration target and yield None.
no_new_diagnostics
Validator (1): refuse when the edited project carries a diagnostic the original did not — compared as per-(file, category) counts, robust to span shifts. Removals are tolerated; additions refuse.
outgoing_calls
v0.34 (ADR 0067): callHierarchy/outgoingCalls — what key calls, each with the call sites within key at which the callee is called.
plan_rename
Build the rename plan for the symbol at the cursor. Errors are human-readable strings surfaced as LSP request failures.
prepare_call_hierarchy
v0.34 (ADR 0067): prepareCallHierarchy — the symbol under the cursor and its definition site (the goto-def resolution; an item is anchored on the definition). None for out-of-scope positions.
prepare_rename
prepareRename: the renameable range under the cursor, or None for out-of-scope symbols (locals, unit names) — the request is refused rather than falling through to a partial rename.
remap_site
The post-edit position of a pre-edit site — rename edits shift spans within edited files. An edited span maps to the new name’s span.
renamed_key_name 🔒
The post-rename value of a (possibly compound) key name: for a member key "Type.method", replace the segment after the last .; for a bare name, the new name as-is.
semantic_tokens
Semantic tokens for path, delta-encoded over the frozen legend — a pure read of the cached index’s two sources: symbols (user defs+refs; a def site carries declaration) and foreign_refs (first-party references). range (byte offsets into text, the analysed snapshot) filters to overlapping tokens for the …/range request; None is the full document.
semantic_tokens_legend
The frozen semantic-tokens legend. Array order is the wire encoding (clients index into these arrays): entries are append-only, never reordered — pinned by the legend-stability test. Token types: standard where faithful (type, function), custom for the Bynk-distinctive kinds (capability, service, agent, provider).
sites_for
Definition first, then references — the references surface.
token_type_index 🔒
Legend indices/bits — must mirror semantic_tokens_legend’s order.
type_definitions_named
Slice 6: textDocument/typeDefinition — the definition site(s) of the type named name (a Type symbol). The checker’s Ty::Named.name and the index both use bare names, so this is a bare-name match; a name shared across units yields several locations (the LSP-conventional resolution — the client lets the user choose). Sorted by definition position.
validate_new_name
A new name must lex as exactly one identifier (keywords lex as their own token kinds, so they fail this check).
workspace_symbols
v0.26 rider (ADR 0055): workspace/symbol — every index definition whose name contains the query, case-insensitive (an empty query lists all), sorted by (name, unit) for a stable order.