Summary
DefinitionProvider.resolve_global_macro_only and DefinitionProvider.resolve_non_macro_symbols both follow the same pattern for each reachable-pool symbol kind (globals, programs, scalars, matrices):
- Walk
resolved_scope.chain, collecting hits from each entry's symbol table.
- Walk
resolved_scope.forward_call_symbols, collecting hits from each site's symbol table.
- Call
collect_related_definition_locations(document.uri, word, kind, workspace_indexer), which iterates workspace_indexer.find_symbol_definitions(word, kind) and filters by get_related_uris(document.uri).
dedupe_locations at the end of each block keeps the result correct.
Why this is duplicative
WorkspaceIndexer.get_related_uris(uri) returns the bidirectional dep-graph closure (callee_to_callers ∪ caller_to_callees). Any URI visited by the chain walk (parents via done-by / included-by) or by the forward-call walk (callees via do / run / include) is in that set. Step 3 is therefore a superset of steps 1 and 2 for the set of files touched.
Subtlety: steps 1 and 2 read from resolved_scope's per-entry symbol tables (which reflect call-site filtering and directive-mediated visibility), while step 3 reads from the indexer's raw find_symbol_definitions. For go-to-definition under issue #135's Rule 1 (same name + same kind within the reachable set = one identity), the identity model already pools all declaration sites in reachable files — so the read-source difference does not change the result. Any behavioral difference would be a bug either way.
Call sites
- `src/providers/definition.ts` `resolve_global_macro_only` — block around lines 290–327
- `src/providers/definition.ts` `resolve_non_macro_symbols` — block around lines 411–446 (program), 448–481 (scalar), 483–516 (matrix)
Four near-identical 30-line blocks.
Performance
- Extra cost per go-to-def: O(|chain|) + O(|forward_sites|) Map.get calls across two loops.
- Go-to-definition is a user-triggered path (F12 / click), not a per-keystroke path.
- No reported perf issue. This is a code-clarity finding, not a measured regression.
Suggested refactor
Extract a single helper that:
- Takes a resolved_scope, the primary symbol (already in hand), the symbol kind, a workspace_indexer, and the current document URI.
- Starts with the primary's own locations.
- Appends `collect_related_definition_locations(document_uri, word, kind, workspace_indexer)`.
- Returns the deduped result.
Then collapse the four blocks to helper calls.
Scope / risk
- Behaviorally equivalent — `dedupe_locations` already handles the overlap today.
- Covered by existing tests: `tests/integration/goto-def-identity-redeclared.test.ts`, `tests/integration/cross-file-awareness.test.ts`, `tests/unit/providers/definition.test.ts`.
- Low risk; mostly mechanical.
Defer / priority
Origin
Surfaced as finding M-6 in the issue #135 second-pass code review. See commit `2517c0e` for the other findings addressed inline.
Summary
DefinitionProvider.resolve_global_macro_onlyandDefinitionProvider.resolve_non_macro_symbolsboth follow the same pattern for each reachable-pool symbol kind (globals, programs, scalars, matrices):resolved_scope.chain, collecting hits from each entry's symbol table.resolved_scope.forward_call_symbols, collecting hits from each site's symbol table.collect_related_definition_locations(document.uri, word, kind, workspace_indexer), which iteratesworkspace_indexer.find_symbol_definitions(word, kind)and filters byget_related_uris(document.uri).dedupe_locationsat the end of each block keeps the result correct.Why this is duplicative
WorkspaceIndexer.get_related_uris(uri)returns the bidirectional dep-graph closure (callee_to_callers∪caller_to_callees). Any URI visited by the chain walk (parents viadone-by/included-by) or by the forward-call walk (callees viado/run/include) is in that set. Step 3 is therefore a superset of steps 1 and 2 for the set of files touched.Subtlety: steps 1 and 2 read from
resolved_scope's per-entry symbol tables (which reflect call-site filtering and directive-mediated visibility), while step 3 reads from the indexer's rawfind_symbol_definitions. For go-to-definition under issue #135's Rule 1 (same name + same kind within the reachable set = one identity), the identity model already pools all declaration sites in reachable files — so the read-source difference does not change the result. Any behavioral difference would be a bug either way.Call sites
Four near-identical 30-line blocks.
Performance
Suggested refactor
Extract a single helper that:
Then collapse the four blocks to helper calls.
Scope / risk
Defer / priority
Origin
Surfaced as finding M-6 in the issue #135 second-pass code review. See commit `2517c0e` for the other findings addressed inline.