Repository navigation
feat(lineage): text→graph navigation — reveal node at cursor (#24) - #36
Merged
Merged
Conversation
Closes #24. Builds on the nameSpans / bodySpan fields shipped in #20 and mirrors the graph→text navigation wired in #23. Behavior: - SqlView tracks the caret via a CodeMirror update listener. When the cursor sits inside any indexed nameSpan or bodySpan, a "Reveal in lineage" floating action button renders above the editor; right-click raises the same action at the click position. - Clicking the action selects the target node, centers the graph viewport on it (fitView, 500ms animation), and pulses its outline via a 1.2s CSS keyframe. - Cursor in whitespace keeps the action disabled/hidden. - Works in both uncontrolled mode (standalone LineageExplorer) and controlled mode (the demo app's EditorArea). Core lookup rules (revealInGraph.ts): - Spans are half-open [start, end) to match analyzer byte-offset conventions. - Name matches beat body matches so placing the cursor on a CTE name inside its own definition focuses that CTE, not the enclosing one. - Among matches of the same kind, the smallest containing span wins — nested CTE bodies resolve to the innermost CTE. Store: - New revealRequest: { nodeId, nonce } field + revealNodeInGraph() / clearRevealRequest() actions. The nonce forces re-triggering when the same node is revealed twice so the pulse restarts. GraphView's RevealHandler observes the request and drives fitView plus the pulse class lifecycle. Index: - buildSpanIndex walks the flat node list once, dedupes by id, and reuses findMergedNodeById so shared nodes across statements contribute every occurrence exactly once. Linear-scan lookup; fast enough for realistic node counts. Tests: 10 new vitest cases covering the lookup contract (whitespace, name precedence, nested-body resolution, half-open boundaries) and the store action (selection update, nonce increment, clear). Refs #17, #20, #23.
Regenerates wasm bindings against current Rust sources so downstream TypeScript consumers see the up-to-date types. No behavior change.
…editor bounce Two follow-ups to #24 surfaced while exercising the feature end-to-end: 1. Reveal hits could reference a lineage node that isn't rendered in the current graph mode (e.g. a column when column edges are hidden, or a CTE while viewing script mode). Introduce `resolveRevealGraphTarget` + `buildRevealLookup` to map each hit to the actual React Flow node id in the active view, falling back from a column to its owning relation via ownership edges. Track the visible node id set in the store (`visibleGraphNodeIds`, populated by GraphView after each build) so the resolver can return null when the mapped target is filtered out — the SqlView button then stays hidden instead of promising a reveal that wouldn't land anywhere. 2. The existing graph→editor navigation effect fires whenever `selectedNodeId` changes, which on a reveal click immediately scrolls the editor to the first `nameSpan` occurrence — bouncing the user away from the cursor position that triggered the reveal. Add a one-shot `suppressNextSelectedNodeNavigation` flag, set by `revealNodeInGraph` and consumed by the effect via `consumeSelectedNodeNavigationSuppression`, so the editor stays put after a reveal while normal click selection continues to navigate. Also simplifies `buildSpanIndex` to a single-pass merge via `mergeNodesForNavigation` instead of calling `findMergedNodeById` per id — same result without rescanning `result.nodes` N times. Tests: 6 new vitest cases covering the column→table fallback, the script-mode hybrid id mapping, the visibility gate, and the one-shot suppression lifecycle. Refs #17, #20, #23.
- Centralize hybrid table node id via hybridTableNodeIdFromKey helper - Share NODE_FOCUS_DELAY_MS + REVEAL_PULSE_* timing constants - Expose visibleGraphNodeIds as ReadonlySet; document reveal-related store APIs - Drop context-menu hijack in SqlView; add Alt+click shortcut + aria-label - Clean up stale pulse timers when nodes leave the filtered graph - Add .prettierignore for generated wasm-bindgen artifacts
- Fold suppressNavigation into revealRequest and key suppression off the nonce in GraphView so each reveal skips at most one graph→editor bounce. Removes the standalone flag + consume action that races under rapid reveals. - Align visibleGraphNodeIds to ReadonlySet and short-circuit equality check without allocating an intermediate array. - Guard hybridTableNodeIdFromKey against colon-containing keys in dev. - Ignore Alt+click on the reveal button itself so it doesn't retrigger. - Add cross-module sync notes at hybrid id use sites. - Add a multi-byte UTF-8 test covering charOffsetToByteOffset + findNodeAtByteOffset composition.
The bounce effect had `revealRequest` in its deps, so when RevealHandler's 100ms setTimeout cleared the request, the effect re-fired with the reveal-originated selectedNodeId and a null revealRequest — bypassing the suppression and navigating to the target. Read revealRequest via a ref so the effect only fires on real selection changes; the consumed-nonce ref still guarantees each reveal suppresses at most one bounce.
The equality check `sqlText !== analyzedSql` unconditionally disabled reveal in hosts that build `analyzedSql` as a concatenated corpus (e.g. the demo app's `-- File: x.sql\n<content>` join), because the editor only shows one source at a time. But when `analyzedSourceName` is provided, span byte offsets are already scoped to that source, so the full-corpus equality is structurally wrong. Reorder the checks so a valid `analyzedSourceName` enables reveal without the equality check; callers own staleness detection when they choose to pass a source name. The equality + single-source guards still cover the no-source controlled case.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
revealRequestnonce so repeat reveals retrigger the pulse animation.Behavior
[start, end)to match the analyzer's byte-offset convention.Implementation notes
packages/react/src/utils/revealInGraph.tsowns the index + lookup and reusesfindMergedNodeByIdso cross-statement occurrences are captured exactly once.SqlViewsubscribes to CodeMirror selection changes viaEditorView.updateListenerand converts char→byte offsets via the existingcharOffsetToByteOffsethelper.GraphViewgrows aRevealHandlercomponent that consumesrevealRequestfrom the store and applies a transientflowscope-reveal-pulseclass to the target React Flow node for 1.3s, then strips it.SqlViewmodes — the store'sresultis always authoritative.Test plan
just typecheckclean across all four TS workspacesjust lint-tscleanjust test-ts— 144/144 pass (10 new:revealInGraph.test.ts,revealNodeInGraph.test.ts)users→ reveal centers onwarehouse_db.core.users, occurrence cycler shows 1/7products→ reveal centers onwarehouse_db.core.products, 1/4Refs #17, #20, #23.