-
Notifications
You must be signed in to change notification settings - Fork 25
Synchronise Positron's Variables pane with debug environment #1052
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
dd2f2b8
Track console environment in Variables pane
lionel- 43c19f0
Don't update env or bindings in `List` RPC handler
lionel- 25cd812
Remove AGENTS advice about test cleanup
lionel- f7caaa5
Only buffer Idle messages while waiting for comm messages
lionel- d15360b
Consume all Variables messages in tests
lionel- File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -112,6 +112,22 @@ fn test_variables_list() { | |
| Rf_defineVar(sym, Rf_ScalarInteger(42), *test_env); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| }); | ||
|
|
||
| // Simulate a prompt signal so `update()` picks up the new variable | ||
| EVENTS.console_prompt.emit(()); | ||
| let msg = iopub_rx.recv_comm_msg(); | ||
| let data = match msg { | ||
| CommMsg::Data(data) => data, | ||
| _ => panic!("Expected data message"), | ||
| }; | ||
| let evt: VariablesFrontendEvent = serde_json::from_value(data).unwrap(); | ||
| match evt { | ||
| VariablesFrontendEvent::Update(params) => { | ||
| assert_eq!(params.assigned.len(), 1); | ||
| assert_eq!(params.assigned[0].display_name, "everything"); | ||
| }, | ||
| _ => panic!("Expected update event"), | ||
| } | ||
|
|
||
| // Request a list of variables | ||
| let request = VariablesBackendRequest::List; | ||
| let data = serde_json::to_value(request).unwrap(); | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| // | ||
| // variables_debug.rs | ||
| // | ||
| // Copyright (C) 2026 Posit Software, PBC. All rights reserved. | ||
| // | ||
| // | ||
|
|
||
| use amalthea::fixtures::dummy_frontend::ExecuteRequestOptions; | ||
| use ark_test::DummyArkFrontend; | ||
|
|
||
| /// When entering debug mode (browser), the variables pane should switch to | ||
| /// showing the debug environment's bindings. When exiting, it should switch | ||
| /// back to the global environment. | ||
| #[test] | ||
| fn test_variables_pane_shows_debug_env() { | ||
| let frontend = DummyArkFrontend::lock(); | ||
|
|
||
| // Set up a global variable before opening the variables comm | ||
| frontend.execute_request_invisibly("test_gv <- 'hello'"); | ||
|
|
||
| // Open the variables comm and receive the initial Refresh | ||
| let initial = frontend.open_variables_comm(); | ||
| let names: Vec<&str> = initial | ||
| .variables | ||
| .iter() | ||
| .map(|v| v.display_name.as_str()) | ||
| .collect(); | ||
| assert!(names.contains(&"test_gv")); | ||
|
|
||
| // Enter browser with a local variable | ||
| frontend.send_execute_request( | ||
| "local({ debug_var <- 42; browser() })", | ||
| ExecuteRequestOptions::default(), | ||
| ); | ||
| frontend.recv_iopub_busy(); | ||
| frontend.recv_iopub_execute_input(); | ||
| frontend.assert_stream_stdout_contains("Called from:"); | ||
| frontend.recv_iopub_idle(); | ||
| frontend.recv_shell_execute_reply(); | ||
|
|
||
| // The variables pane should have sent a Refresh with the debug env | ||
| let refresh = frontend.recv_variables_refresh(); | ||
| let names: Vec<&str> = refresh | ||
| .variables | ||
| .iter() | ||
| .map(|v| v.display_name.as_str()) | ||
| .collect(); | ||
| assert_eq!(names, vec!["debug_var"]); | ||
|
|
||
| // Quit the debugger | ||
| frontend.send_execute_request("Q", ExecuteRequestOptions::default()); | ||
| frontend.recv_iopub_busy(); | ||
| frontend.recv_iopub_execute_input(); | ||
| frontend.recv_iopub_idle(); | ||
| frontend.recv_shell_execute_reply(); | ||
|
|
||
| // Should be back to showing the global environment | ||
| let refresh = frontend.recv_variables_refresh(); | ||
| let names: Vec<&str> = refresh | ||
| .variables | ||
| .iter() | ||
| .map(|v| v.display_name.as_str()) | ||
| .collect(); | ||
| assert!(names.contains(&"test_gv")); | ||
| assert!(!names.contains(&"debug_var")); | ||
|
|
||
| // Clean up | ||
| frontend.send_execute_request("rm(test_gv)", ExecuteRequestOptions::default()); | ||
| frontend.recv_iopub_busy(); | ||
| frontend.recv_iopub_execute_input(); | ||
| frontend.recv_iopub_idle(); | ||
| frontend.recv_shell_execute_reply(); | ||
|
|
||
| // Consume the Update triggered by the rm() | ||
| let _update = frontend.recv_variables_update(); | ||
| } | ||
|
|
||
| /// When entering debug via a function call, the variables pane should show | ||
| /// the function's environment with its arguments. | ||
| #[test] | ||
| fn test_variables_pane_shows_function_debug_env() { | ||
| let frontend = DummyArkFrontend::lock(); | ||
|
|
||
| // Set up a global variable before opening the variables comm | ||
| frontend.execute_request_invisibly("test_gv2 <- 'world'"); | ||
|
|
||
| let _initial = frontend.open_variables_comm(); | ||
|
|
||
| // Define a function and call it so browser() triggers inside | ||
| frontend.send_execute_request( | ||
| "f <- function(my_arg) { browser(); my_arg }; f(99)", | ||
| ExecuteRequestOptions::default(), | ||
| ); | ||
| frontend.recv_iopub_busy(); | ||
| frontend.recv_iopub_execute_input(); | ||
| frontend.assert_stream_stdout_contains("Called from: f(99)"); | ||
| frontend.recv_iopub_idle(); | ||
| frontend.recv_shell_execute_reply(); | ||
|
|
||
| // The debug env should show `my_arg` | ||
| let refresh = frontend.recv_variables_refresh(); | ||
| let names: Vec<&str> = refresh | ||
| .variables | ||
| .iter() | ||
| .map(|v| v.display_name.as_str()) | ||
| .collect(); | ||
| assert_eq!(names, vec!["my_arg"]); | ||
|
|
||
| // Quit the debugger | ||
| frontend.send_execute_request("Q", ExecuteRequestOptions::default()); | ||
| frontend.recv_iopub_busy(); | ||
| frontend.recv_iopub_execute_input(); | ||
| frontend.recv_iopub_idle(); | ||
| frontend.recv_shell_execute_reply(); | ||
|
|
||
| // Should be back to showing the global environment | ||
| let refresh = frontend.recv_variables_refresh(); | ||
| let names: Vec<&str> = refresh | ||
| .variables | ||
| .iter() | ||
| .map(|v| v.display_name.as_str()) | ||
| .collect(); | ||
| assert!(names.contains(&"test_gv2")); | ||
| assert!(!names.contains(&"my_arg")); | ||
|
|
||
| // Clean up | ||
| frontend.send_execute_request("rm(test_gv2, f)", ExecuteRequestOptions::default()); | ||
| frontend.recv_iopub_busy(); | ||
| frontend.recv_iopub_execute_input(); | ||
| frontend.recv_iopub_idle(); | ||
| frontend.recv_shell_execute_reply(); | ||
|
|
||
| // Consume the Update triggered by the rm() | ||
| let _update = frontend.recv_variables_update(); | ||
| } |
Oops, something went wrong.
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.

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the
Listrequest used to request a bindings update, but we don't want to do that anymore? We are trusting that it should be update to date because it would have updated after every top level eval?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep