Skip to content

Feat/session aware plot viewer - #1932

Draft
Fred-Wu wants to merge 30 commits into
REditorSupport:mainfrom
Fred-Wu:feat/session-aware-plot-viewer
Draft

Fred-Wu wants to merge 30 commits into
REditorSupport:mainfrom
Fred-Wu:feat/session-aware-plot-viewer

Conversation

@Fred-Wu

@Fred-Wu Fred-Wu commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Closes #1780

Summary

This PR makes standalone R plot viewers session-aware across the JGD, httpgd, and standard backends. Plots remain associated with their originating R process, multiple devices share their session’s history, and retained plots can be reopened after VS Code reloads while R remains running.

New features

  • Separate plot viewers for each R session. JGD and standard viewers are associated with their owning session; httpgd devices belonging to the same session share one viewer.
  • Shared history across graphics devices. JGD and httpgd plots appear in a session-wide timeline, preserving their order across device changes. Navigation, resizing, export, and removal target the appropriate device.
  • Plot restoration after VS Code reload. JGD history and selection are persisted. httpgd retains rendered SVGs, plot order, selection, hidden plots, and connection information. Standard viewers retrieve the latest plot from the reattached R session.
  • History survives graphics-device closure. Previously received JGD and httpgd plots remain available for navigation while the owning R process continues running. Cached httpgd plots can also be exported as SVG after their server becomes unavailable.
  • Session information in plot viewers. A shared information indicator displays the owning session’s R version and process ID.

What changed

  • Show Viewers targets the active attached R session, rather than revealing every available plot viewer. Toolbar commands target the focused viewer.
  • Viewer ownership uses the session ID, host, and PID. Device identifiers and httpgd credentials remain associated with their individual devices.
  • Closing a JGD or httpgd panel retains its history. Updates to existing plots refresh retained content without reopening the panel; new plots or an explicit Show Viewers action can reopen it.
  • Reload and transport cleanup preserve restorable plot state. A confirmed R-process exit releases clients, history, and saved connection information while leaving an already rendered tab visible.
  • R runtime reconnection preserves graphics state. VS Code JGD devices are reopened against the new renderer socket with their logical identities, dimensions, DPI, and current plots restored. Existing httpgd servers are rediscovered.
  • Explicit httpgd::hgd() calls are registered with the viewer alongside devices opened through the default graphics-device factory.
  • Inactive httpgd devices use cached scaling to avoid replaying into another active R device. Deferred geometry is rendered when the owning device becomes active and the plot is selected.
  • History checkpoints run during normal operation and shutdown. Navigation updates save selection metadata separately from plot content, and httpgd URLs containing tokens are stored in SecretStorage.
  • Shared viewer registration and lifecycle handling replace duplicated management logic. Obsolete httpgd webview assets are removed, and the bundled sess version advances to 3.4.0.9005.

Fixes

  • Prevent standard plot notifications and viewer commands from acting on another R session’s plots.
  • Preserve plot history across editor reloads instead of losing it when the extension host and renderer restart.
  • Restore all applicable VS Code JGD devices, including explicitly opened devices, while leaving devices belonging to other renderers untouched.
  • Prevent reused R device numbers from inheriting stale device registrations.
  • Correct JGD resize handling for large plots and historical replay, and redraw retained JGD tabs when they become visible again.
  • Prevent JGD and httpgd panels from reopening merely because an existing plot receives an annotation or refresh.
  • Serialize httpgd refreshes and isolate individual render failures so successful updates remain usable.
  • Refresh changed httpgd content, including final annotations on the preceding plot, while reusing unchanged cached images.
  • Preserve plot notifications received during asynchronous session attachment.
  • Stop httpgd requests during session teardown and suppress cancellation-related refresh errors.

Testing

  • Add regression coverage for session isolation, device ownership, navigation, resizing, restoration, device closure, and process-exit cleanup.
  • Add live-R lifecycle tests and a dedicated plot-lifecycle extension-test profile. CI requires the relevant R dependencies and runs the profile across its platform matrix.
  • Verified locally on macOS: TypeScript compilation, 199 plot-lifecycle extension tests, and 28 focused Node/live-R tests.

Fred-Wu and others added 30 commits November 11, 2026 12:15
- Bind standard plot viewers to their originating R sessions
- Add JGD session selection and isolate resize requests by device
- Restore httpgd connections and request standard plots from live sessions
- Persist JGD frames and selection for reload restoration
- Add session isolation and restoration tests
Give each JGD session its own viewer and remove the session dropdown.
Keep history, navigation, resize, and text measurement scoped to each
session, and restore separate viewers after VS Code reload.

Avoid redundant plot requests and toolbar updates, and prevent httpgd
restoration from overwriting newer connection credentials.
Reuse the list/data viewer indicator in standard, httpgd, and JGD
viewers, showing R <version>: <PID> on hover or keyboard focus.

Preserve session identity across reloads, handle late attachments,
and update indicators when the owning R process exits.
- Persist restoration state during normal operation
- Preserve live R plot state and reconnect JGD devices with stable identities
- Limit Show Viewer to the active session and prevent duplicate or empty tabs
- Keep closed viewers closed during reattachment across all plot engines
- Bump sess to 3.4.0.9001
- Add session isolation and live reconnection regression tests
… session disconnects, without showing shutdown-related error popups.
- Preserve saved httpgd credentials when loading fails and report the error
- Stop selecting an arbitrary restored JGD device
- Always send JGD session identity metadata
- Remove the unbound standard viewer and unused history/resize code
- Bump sess to 3.4.0.9005

Validated all three plot backends across repeated VS Code reloads.
- Refresh open standard plot viewers after sess reconnect without reopening closed panels
- Fetch the latest standard plot when showing an existing viewer
- Retain httpgd viewport changes during disconnects and ignore stale render dimensions
- Preserve httpgd divider height when reopening in a resized editor group
- Restore JGD devices using captured dimensions and DPI without hardcoded defaults
- Add regression coverage for reconnects, device settings, and both httpgd layouts
- Share plot ownership, viewer reuse, and exit cleanup across engines
- Delete in-memory history and saved state on permanent R exit while
  leaving rendered plots and viewer tabs untouched
- Preserve restoration across VS Code reloads and live R reconnects
- Combine httpgd devices into one viewer with collision-safe plot IDs
  and device-specific rendering, export, and deletion
- Coalesce httpgd refreshes, discard stale responses, and avoid
  rerendering inactive devices at new sizes
- Discover explicit httpgd devices without taking lifecycle ownership
- Prevent commands from ended viewers from targeting another session
- Add regression coverage for cleanup, device reuse, and restoration
- Remove legacy html/httpgd files replaced by src/plotViewer/webview
- Remove unused getNewestViewer method and MaybePromise type
- Remove write-only plotWidth and plotHeight viewer fields
- Update the shared webview message types comment

Validation: 152 VS Code tests and 20 Node tests passed; build,
type checking, lint, and formatting passed.
Remove incorrect viewer identification derived from resource URLs.
Route toolbar actions to the focused live viewer without falling
back to another session when an ended session's tab remains open.

Add regression coverage for consecutive httpgd plots and toolbar
command routing.

Validation: real toolbar clicks and 152 regression tests passed.
…ation

- Refresh changed inactive plots while reusing unchanged cached content
- Isolate failed plot fetches and avoid redundant retries
- Defer httpgd restoration notifications until runtime setup completes
- Add regression coverage for stale plots, fetch failures, and cleanup
- Restore interleaved plot history using saved ordering metadata
- Switch to the next available server when the selected device closes
- Avoid resize errors after the last device closes
- Fix divider jumps caused by the session header
- Add live R and VS Code regression coverage
- Persist httpgd SVGs, plot order, selection, and hidden plots
- Preserve navigation and SVG export after devices close
- Refresh annotations on previous and hidden plots
- Keep restored thumbnails in session timeline order
- Align JGD and httpgd viewer reopening behavior
- Consolidate received SVGs into one authoritative collection
- Clean up retained content and credentials on confirmed R exit
- Add lifecycle regression tests and dedicated cross-platform CI
- Require live R test dependencies and enable CI for master

Validated with 198 extension tests, 38 Node tests, compilation,
lint, formatting, and manual httpgd/JGD lifecycle checks.
- Update JGD fixtures for device tracking and session metadata
- Use Windows-compatible interactive R flags in plot tests
- Handle connection resets and cleanup in HTTP recovery tests
- Install libtiffxx6 on Linux and expose dependency load errors

This branch has not been deployed

No deployments
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.

(feat) Make plot viewer session-aware.

1 participant