Skip to content

feat: add native plot backend for R graphics devices - #1817

Open
eitsupi wants to merge 8 commits into
REditorSupport:mainfrom
eitsupi:feat/native-plot-backend-1806
Open

eitsupi wants to merge 8 commits into
REditorSupport:mainfrom
eitsupi:feat/native-plot-backend-1806

Conversation

@eitsupi

@eitsupi eitsupi commented Oct 4, 2026 •

Copy link
Copy Markdown
Member

Closes #1806

Summary

  • Add native to r.plot.backend and carry the choice through managed terminals, manual attach, the public session API, and reconnects.
  • In native, keep sess IPC and non-plot integrations while leaving R's graphics device option, plot hooks, plot task callback, and devices untouched.
  • Use one explicit backend value inside sess. Keep the public use_httpgd and use_jgd arguments as deprecated compatibility shims, and preserve the auto order: jgd, then httpgd, then the standard viewer.
  • Set the bundled sess version to 3.0.9000.9000 so existing installations receive the updated API.

Follow-up fix

  • Clear vscode-R's JGD_SOCKET terminal environment mutation when switching to native, standard, or httpgd. This leaves process.env.JGD_SOCKET and existing R processes untouched.
  • Add a setting-change test covering jgd/auto registration and native/standard/httpgd cleanup.

Plot backend settings and Settings Sync

  • Keep r.plot.backend and its deprecated compatibility setting r.plot.useHttpgd at window scope, and set ignoreSync: true on both. Backend availability depends on the local or remote R installation, so these values should not sync between machines.
  • Retain workspace-wide backend selection in multi-root workspaces. Folder-specific backend support can be added separately with consistent terminal startup and discovery/reconnect resolution.

Deprecated plot argument handling

  • Default use_httpgd and use_jgd to NULL in both connect() and register_hooks(). Treat non-NULL values, including FALSE, as use of the deprecated API and emit a warning.
  • If neither flag is supplied, use auto. If one flag is supplied, fill in the other with its legacy default (use_httpgd = TRUE, use_jgd = FALSE). An explicit plot_backend still takes precedence.
  • Add regression coverage for omitted and forwarded NULL flags, TRUE/FALSE/NA values, partial legacy calls, and explicit backend precedence in both public entry points. All 132 assertions in test-native-plot.R pass locally.

@eitsupi eitsupi changed the title Add native plot backend for R graphics devices feat: add native plot backend for R graphics devices Oct 4, 2026
@eitsupi
eitsupi requested a review from ThomasSoeiro October 4, 2026 07:06

@ThomasSoeiro ThomasSoeiro left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hey, I am unable to review your changes, but I just left a quick comment just in case :) Thanks!

Comment thread sess/R/hooks.R Outdated
Comment thread sess/R/server.R Outdated
@eitsupi
eitsupi marked this pull request as draft October 4, 2026 08:23
@eitsupi
eitsupi marked this pull request as ready for review October 4, 2026 08:31

@renkun-ken renkun-ken left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed a5f505a using this PR's bundled sess 3.0.9000.9000, installed in an isolated library and confirmed loaded inside the R terminal. The latest NULL handling for deprecated plot arguments looks correct.

One remaining P2 finding is attached inline: folder-level backend settings are ignored.

Validation: all 495 R assertions and 79 existing tests in the plotBackend, terminal, session, and sessInstall extension suites pass. A native-terminal probe also passes: the configured device is preserved, plotting opens no integrated viewer, and View() still works. Build, type checking, and CI pass. An additional regression using real multi-root configuration fails as described in the inline comment.

Comment thread src/plotViewer/index.ts

export function resolveBackend(): PlotBackend {
const selected = getMigratedSetting<string | boolean>(
config(),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[P2] Respect folder-level backend settings

The PR changes r.plot.backend and r.plot.useHttpgd to machine-overridable, which permits folder overrides, but resolveBackend() still calls config() without a resource. I reproduced this in a real multi-root VS Code workspace: folder A has r.plot.backend = native and the workspace has standard; getConfiguration('r', folderA.uri) returns native, but makeTerminalOptions(folderA.uri) emits SESS_PLOT_BACKEND = standard. As a result, plotting uses the integrated viewer despite the folder's native preference. Pass the terminal's resource through backend resolution and keep discovery generation consistent with that resolved backend. Please add a multi-root regression test covering different folder backend values. This reproduction used the updated sess 3.0.9000.9000 bundled in this PR.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thank you for pointing that out.
I've set the scope to window and configured ignoreSync.
I thought it would be more appropriate to implement machine-overridable in a subsequent PR.

@eitsupi
eitsupi marked this pull request as draft October 4, 2026 08:57
@eitsupi
eitsupi marked this pull request as ready for review October 4, 2026 09:00

@renkun-ken renkun-ken left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed the latest changes at a624bd2. No actionable issues found in this follow-up. The previously posted P2 finding is resolved: both r.plot.backend and r.plot.useHttpgd now use window scope with ignoreSync: true, keeping backend selection consistent across the workspace while excluding these settings from Settings Sync by default.

Verified using this PR's bundled sess 3.0.9000.9000, installed in an isolated library and confirmed loaded inside the R terminal:

  • In a real multi-root VS Code workspace, both folders receive the workspace backend correctly for standard, native, httpgd, and auto. Conflicting folder settings no longer override the window-scoped setting.
  • Native plotting preserves the configured graphics device, opens no integrated plot viewer, and retains View() integration.
  • Both focused integration probes pass. Type checking, the build, and all CI checks pass.

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.

Support for built-in plotting devices (e.g. Quartz) removed in latest release?

3 participants