feat(data viewer): Allow reusing data viewer instead of opening a new…#1707
Merged
renkun-ken merged 2 commits intoMay 12, 2026
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the VS Code R data viewer workflow so repeated View() calls for the same data title reuse an existing viewer panel (via a stable view_id) and refresh its contents, instead of opening a new panel each time.
Changes:
- VS Code: Track dynamic data viewer webview panels by
view_id, reveal an existing panel when possible, and reload the webview content to fetch updated data. - sess (R): Introduce a per-session
dataview_registryto reuse the same generatedview_idfor the sameView()title, and allowdataview_register()to accept an explicitview_id. - sess (R) → VS Code: Include
total_rowsin the dataview notification so the panel title can be restored to the(rows: n)format when reusing.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/session.ts | Reuse dynamic data viewer panels by view_id, reveal existing panels, and reload webview HTML to refresh data/title. |
| sess/R/server.R | Initialize a session-level dataview_registry environment for stable view_id reuse. |
| sess/R/hooks.R | Reuse view_id per View() title and include total_rows in dataview notifications. |
| sess/R/handlers.R | Add dataview_new_id() and allow dataview_register(data, view_id=...) to overwrite/update existing state. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+265
to
+271
| repeat { | ||
| ts <- gsub("[^0-9]", "", format(Sys.time(), "%Y%m%d%H%M%OS6"), perl = TRUE) | ||
| view_id <- sprintf("dv_%s_%06d", ts, sample.int(999999L, 1L)) | ||
| if (is.null(.sess_env$dataviews) || is.null(.sess_env$dataviews[[view_id]])) { | ||
| return(view_id) | ||
| } | ||
| } |
Comment on lines
+274
to
285
| dataview_register <- function(data, view_id = NULL) { | ||
| if (is.null(.sess_env$dataviews)) { | ||
| .sess_env$dataviews <- list() | ||
| } | ||
| ts <- gsub("[^0-9]", "", format(Sys.time(), "%Y%m%d%H%M%OS6"), perl = TRUE) | ||
| view_id <- sprintf("dv_%s_%06d", ts, sample.int(999999L, 1L)) | ||
|
|
||
| if (is.null(view_id)) { | ||
| view_id <- dataview_new_id() | ||
| } | ||
|
|
||
| state <- dataview_to_state(data) | ||
| .sess_env$dataviews[[view_id]] <- state | ||
| list( |
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.
This PR makes the data viewer to reused the viewer panels by view_id so repeated View() calls for the same data name refresh the existing viewer instead of opening a new one.
The
sessside now reuses the same generated view_id for the same title while replacing the stored data state. The vscode side tracks open viewers by view_id, reveals the existing panel, restores the (rows: n) title, and reloads the webview so updated data is fetched.