Skip to content

FE-2426: Open a diagnostic's code at its line from the Diagnostics tab - #10708

Open
kube wants to merge 1 commit into
cf/fe-2425-diagnostics-tab-severityfrom
cf/fe-2426-diagnostics-open-code-at-line
Open

kube wants to merge 1 commit into
cf/fe-2425-diagnostics-tab-severityfrom
cf/fe-2426-diagnostics-open-code-at-line

Conversation

@kube

@kube kube commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Before this PR, clicking a diagnostic in the Diagnostics tab selected the entity that owns the code. The reader then had to find the code section in the Properties Panel and scroll to the line.

A click now opens the code itself. Its section fills the Properties Panel, the editor takes focus, and the cursor is where the problem starts, with that line in view.

10708.mp4

Links

Changes

  • Diagnostic click opens its code at the problem

    Section fills the Properties Panel and the caret lands where the diagnostic starts.
    With source code hidden, the click selects the entity.

  • open of useCodeNavigation takes a position and returns whether it opened

    A position asks the editor for focus with or without maximize.
    Asking twice for the same code moves the caret twice.

  • CodeEditor answers the focus request for its path

    FocusOnRequest is a child of the editor, so a change to the navigation's entries renders it alone.
    Place visualizer section drops its own copy of that effect.

  • Editor measures its container before it reveals the line

    Monaco learns its size from a resize observer after the frame in which it mounts.
    Without the measure, the line is centred in the 5 px the editor starts with.

  • Section that fills its panel leaves focus in its content

    Header control takes focus only when focus is not already below the header.
    Holds for every section that can fill its panel.

Test coverage

  • diagnostics.test.tsx:

    A click opens the diagnostic's code maximized at its start, and selects the entity when the code does not open.

  • focus-on-request.test.tsx:

    Measure, caret, reveal and focus, in that order, for a request with a position.
    Focus alone for a request without one.
    A request for another path, or to a disposed editor, stays unanswered.

  • code-navigation-provider.test.tsx:

    A position leaves a focus request with or without maximize, and asking again leaves a new one.
    open returns false in the preview and for code that does not exist.

  • vertical-sub-views-container.test.tsx:

    Focus in a section's content stays there as the section fills the container.

  • Manual run on the demo site:

    Clicks on kernel, lambda and visualizer diagnostics, with the section closed, visible and already filling the panel. Each puts the caret on the culprit, with the editor focused and the line in view.

How to test

  • Open Petrinaut preview on Vercel
  • Menu > Load example > Probabilistic Satellite Launcher
  • Select transition LaunchSatellite
  • Add const spare = missing; as last line of Transition Results code
  • Select transition Crash
  • Replace distance with missing in last line of Firing Time code
  • Select place Space
  • Open Diagnostics tab
  • Click the row under LaunchSatellite

    Expect Transition Results filling the Properties Panel, cursor on missing in line 16, that line in view

  • Type a letter

    Expect it in the code at the cursor

  • Click the row under Crash

    Expect Firing Time filling the Properties Panel, cursor on missing in line 11

@vercel

vercel Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
hash Ready Ready Preview Dec 3, 2026 10:14pm UTC
petrinaut Ready Ready Preview Dec 3, 2026 10:14pm UTC
petrinaut-docs Ready Ready Preview Dec 3, 2026 10:14pm UTC
1 Skipped Deployment
Project Deployment Actions Updated
hashdotdesign-tokens Ignored Ignored Preview Dec 3, 2026 10:14pm UTC

Request Review

@kube
kube added this pull request to stack #10709 December 3, 2026 18:55
@github-actions github-actions Bot added area/infra Relates to version control, CI, CD or IaC (area) area/libs Relates to first-party libraries/crates/packages (area) type/eng > frontend Owned by the @frontend team labels Dec 3, 2026
@kube kube self-assigned this Dec 3, 2026
Clicking a diagnostic selected its entity and left the reader to find the code and the line. It now opens the code section over the properties panel, with the caret where the diagnostic starts and that line in view.

The shared code editor answers a focus request for its path, so no section handles one itself. A section that fills its panel leaves focus in its content when the editor already took it.
@kube
kube force-pushed the cf/fe-2426-diagnostics-open-code-at-line branch from 79977a8 to 45a181a Compare December 3, 2026 22:10
@kube
kube marked this pull request as ready for review December 4, 2026 01:09
@kube
kube requested a review from a team as a code owner December 4, 2026 01:09
Copilot AI balanced review requested due to automatic review settings December 4, 2026 01:09
@cursor

cursor Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
UI-only navigation and editor focus behavior in Petrinaut; no auth, persistence, or simulation execution changes.

Overview
Clicking a problem in the Diagnostics tab now jumps straight into the source: the matching code section fills the Properties Panel, the Monaco editor takes focus, and the caret lands on the diagnostic’s start with that line scrolled into view. If code cannot be opened (for example preview without source), behavior falls back to selecting the entity only.

Code navigation gains an optional position on useCodeNavigation().open(), a boolean return when nothing can open, and focus requests that carry line/character. FocusOnRequest on CodeEditor (by document path) centralizes answering those requests—layout, caret, reveal, focus—and replaces ad hoc focus handling in the place visualizer section.

Section maximize no longer steals focus from content already focused below the header, so navigation into an editor during fill-panel animation keeps the caret in the code editor.

Reviewed by Cursor Bugbot for commit 45a181a. Bugbot is set up for automated code reviews on this repo. Configure here.

@veria-ai

veria-ai Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

PR overview

No security issues were found in this pull request.

Reviews

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are recorded for the diagnostic-to-code navigation change.

No open issues 🎉

What changed in this PR

This PR connects Petrinaut diagnostics directly to their code, opening the relevant Properties Panel section with the editor focused at the problem.

Changes:

  • Adds position-aware code navigation, with entity-selection fallback when code cannot open.
  • Centralizes editor focus handling and preserves content focus during maximization.
  • Adds regression tests, documentation updates, and a patch changeset.
File Description
libs/​@hashintel/​petrinaut/​src/​ui/​views/​Editor/​panels/​PropertiesPanel/​place-properties/​subviews/​place-visualizer/​subview.tsx Removes duplicate focus handling.
libs/​@hashintel/​petrinaut/​src/​ui/​views/​Editor/​panels/​BottomPanel/​subviews/​diagnostics.tsx Opens code at the diagnostic position.
libs/​@hashintel/​petrinaut/​src/​ui/​views/​Editor/​panels/​BottomPanel/​subviews/​diagnostics.test.tsx Tests navigation and selection fallback.
libs/​@hashintel/​petrinaut/​src/​ui/​views/​Editor/​editor-view/​code-navigation-provider.tsx Issues position-aware focus requests and returns success.
libs/​@hashintel/​petrinaut/​src/​ui/​views/​Editor/​editor-view/​code-navigation-provider.test.tsx Tests repeated requests and navigation results.
libs/​@hashintel/​petrinaut/​src/​ui/​sub-view/​vertical-sub-views-container/​use-sub-view-maximization.ts Preserves focus within section content.
libs/​@hashintel/​petrinaut/​src/​ui/​sub-view/​vertical-sub-views-container.test.tsx Tests focus preservation during maximization.
libs/​@hashintel/​petrinaut/​src/​ui/​sub-view/​sub-views.mdx Documents content-focus preservation.
libs/​@hashintel/​petrinaut/​src/​ui/​monaco/​monaco.mdx Documents position navigation and editor measurement.
libs/​@hashintel/​petrinaut/​src/​ui/​monaco/​code-navigation-context.ts Defines positions and navigation success results.
libs/​@hashintel/​petrinaut/​src/​ui/​monaco/​code-editor/​focus-on-request.tsx Measures, positions, reveals, and focuses the editor.
libs/​@hashintel/​petrinaut/​src/​ui/​monaco/​code-editor/​focus-on-request.test.tsx Tests focus-request handling and operation order.
libs/​@hashintel/​petrinaut/​src/​ui/​monaco/​code-editor.tsx Integrates shared focus handling.
libs/​@hashintel/​petrinaut/​docs/​petri-net-extensions.md Updates diagnostic-click documentation.
libs/​@hashintel/​petrinaut/​docs/​code-editor.md Describes opening code from diagnostics.
.changeset/​diagnostics-open-code-at-line.md Records the Petrinaut patch release change.

Review effort: Balanced

This branch was successfully deployed

3 active deployments
Preview – hash — 45a181a7 Deployed Dec 3, 2026 by vercel[bot]
Preview – petrinaut — 45a181a7 Deployed Dec 3, 2026 by vercel[bot]
Preview – petrinaut-docs — 45a181a7 Deployed Dec 3, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/infra Relates to version control, CI, CD or IaC (area) area/libs Relates to first-party libraries/crates/packages (area) type/eng > frontend Owned by the @frontend team

Development

Successfully merging this pull request may close these issues.

2 participants