Skip to main content

Module resolve

Module resolve 

Source
Expand description

Centralized cursor resolution.

goto_definition, goto_declaration, and hover all needed to answer the same question — “which declaration in this AST is named word?” — and each had its own near-identical statement walker (scan_statements, find_any_declaration, …). resolve_declaration is the single walker; it returns a borrowed handle to the matched node (Declaration) and leaves rendering (range vs. signature vs. abstract-filtering) to the caller.

The walker performs name matching, not full cursor-context classification: it matches a declaration whose name equals word, exactly as the three original copies did. Distinguishing “method call vs. class name at this offset” is a separate, behavior-changing concern and intentionally not done here.

Callers narrow the match with an accept predicate. Returning false means “skip this candidate and keep looking”, mirroring the _ => {} fall-through in the original walkers. This is what lets declaration’s two-pass logic (abstract first, then any) reuse the same traversal.

Enums§

Container
Which type-like declaration a member belongs to. Lets callers reproduce per-container behavior (e.g. definition resolves enum constants differently from class constants) without re-walking the AST.
Declaration
A declaration node matched by name. Each variant borrows the matched AST node (arena-allocated, so it outlives the walk) plus the span(s) callers need to compute a precise name range.

Functions§

resolve_declaration
Find the first declaration named word that accept approves, scanning stmts in source order and recursing into braced namespaces.