Skip to content

Simplify .Last.value handling#1062

Merged
DavisVaughan merged 4 commits intomainfrom
feature/simpler-last-value
Mar 5, 2026
Merged

Simplify .Last.value handling#1062
DavisVaughan merged 4 commits intomainfrom
feature/simpler-last-value

Conversation

@DavisVaughan
Copy link
Contributor

@DavisVaughan DavisVaughan commented Feb 26, 2026

While reviewing some of @lionel-'s tweaks to variables.rs, it occurred to me that the .Last.value handling is quite complicated and could be heavily simplified

I think the existing tests were also actually wrong. If the .Last.value is being shown and was set to NULL and after executing another R statement it is still NULL, then we should not get an update for that. The pointer value didn't change, so nothing should update.

The only way to actually test ^ is to really send R code through r_read_console() so I've switched to using frontend powered tests for .Last.value testing.

pub enum LastValue {
/// Always show the .Last.value variable in the Variables pane. This is used
/// by tests to show the value without changing the global option.
Always,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only used by tests before, but we don't use this now. We literally set the option like an R user would.

Comment on lines 220 to 222
let mut variables: Vec<Variable> = vec![];
r_task(|| {
if let Some(last_value) = self.last_value() {
variables.push(last_value.var());
}

for binding in self.current_bindings.get() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought it was very strange that we had all this special handling around .Last.value.

I realized it could be greatly simplified by shoving .Last.value handling into bindings().

Either:

  • The option is on, and .Last.value is returned from bindings()
  • The option is off, and .Last.value is not returned from bindings()

Everything else (including assigned and removed handling below) just correctly falls out from this.

Comment on lines +635 to +639
if self.show_last_value() {
if let Some(last_value) = Self::last_value().log_err() {
bindings.push(last_value);
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the one special place we handle it now

@DavisVaughan DavisVaughan force-pushed the feature/simpler-last-value branch from a6f392c to 41538eb Compare February 27, 2026 16:53
@DavisVaughan DavisVaughan requested a review from lionel- February 27, 2026 17:08
Copy link
Contributor

@lionel- lionel- left a comment

Choose a reason for hiding this comment

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

Nice simplification!

This magically works because the ark_test side has the `self.recv_iopub_busy()` and `self.recv_iopub_idle()` overrides that buffer Variables messages
So they all get proper buffering
It runs R code, so is very R specific
@DavisVaughan DavisVaughan force-pushed the feature/simpler-last-value branch from 41538eb to b535d96 Compare March 5, 2026 19:18
@DavisVaughan DavisVaughan merged commit 3f80fb7 into main Mar 5, 2026
8 checks passed
@DavisVaughan DavisVaughan deleted the feature/simpler-last-value branch March 5, 2026 19:20
@github-actions github-actions bot locked and limited conversation to collaborators Mar 5, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants