Skip to content

feat(lineage): text→graph navigation — reveal node at cursor (#24) - #36

Merged
melonamin merged 8 commits into
masterfrom
feat/issue-24-text-to-graph-nav
Apr 16, 2026
Merged

melonamin merged 8 commits into
masterfrom
feat/issue-24-text-to-graph-nav

Conversation

@melonamin

Copy link
Copy Markdown
Member

Summary

  • New "Reveal in lineage" action in the SQL editor centers the graph on the node under the caret and pulses its outline. Closes Navigation: text → graph (reveal node at cursor) #24.
  • Works from a floating action button above the editor and from a right-click context menu. Disabled when the cursor is in whitespace.
  • Introduces a span interval index built once per analysis result, plus a store-level revealRequest nonce so repeat reveals retrigger the pulse animation.

Behavior

  • Cursor inside a column/table/CTE name → that node focuses and pulses.
  • Cursor inside a CTE body (not on a name) → the enclosing CTE node focuses. Nested CTE bodies resolve to the innermost CTE (smallest containing span wins).
  • Name matches take precedence over body matches — placing the cursor on a CTE name inside its own definition focuses that CTE, not the enclosing one.
  • Span boundaries are half-open [start, end) to match the analyzer's byte-offset convention.

Implementation notes

  • packages/react/src/utils/revealInGraph.ts owns the index + lookup and reuses findMergedNodeById so cross-statement occurrences are captured exactly once.
  • SqlView subscribes to CodeMirror selection changes via EditorView.updateListener and converts char→byte offsets via the existing charOffsetToByteOffset helper.
  • GraphView grows a RevealHandler component that consumes revealRequest from the store and applies a transient flowscope-reveal-pulse class to the target React Flow node for 1.3s, then strips it.
  • Works in both controlled and uncontrolled SqlView modes — the store's result is always authoritative.

Test plan

  • just typecheck clean across all four TS workspaces
  • just lint-ts clean
  • just test-ts — 144/144 pass (10 new: revealInGraph.test.ts, revealNodeInGraph.test.ts)
  • Manual browser verification against the demo app (E-commerce Analytics fixture):
    • Cursor on users → reveal centers on warehouse_db.core.users, occurrence cycler shows 1/7
    • Cursor on products → reveal centers on warehouse_db.core.products, 1/4
    • Cursor on whitespace → button hidden
  • Reviewer: exercise the feature in VS Code webview and confirm pulse visibility on the active theme

Refs #17, #20, #23.

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.
@melonamin
melonamin merged commit 808fe2f into master Apr 16, 2026
@melonamin
melonamin deleted the feat/issue-24-text-to-graph-nav branch April 16, 2026 23:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Navigation: text → graph (reveal node at cursor)

1 participant