REditorSupport/vscode-R

When help is triggered, a closed plot window opens in addition to the help window.

Opened this issue · 2 comments

Describe the bug

Sometimes the plot window pops up triggered by some command other than plot such as ? or traceback.

To Reproduce
I haven't figured out the exact repro steps. It seems to happen when a source a script that has both a plot and a warning or error in it. However, it doesn't happen 100% of the time even in this situation.

It's something along the lines of these steps, but again only happens sometimes, and I haven't managed to figure out why:

  • source a script with both a plot and a warning
  • close the plot window
  • run ?mean
    Result: both plot window and help window open.

I'll post an MRE once I'm able to identify the exact trigger. Figured it would be good to open an issue even without one in case others are having the same issue, they can post here.

Can you fix this issue by yourself? (We appreciate the help)

Not sure. If the problem is in R, then probably. If the problem is in typescript, probably not.

Expected behavior

Only help window to open.

Screenshots
If applicable, add screenshots to help explain your problem.
You can show the keyboard contents by pressing F1 and Developer: toggle screencast mode

Environment (please complete the following information):

  • OS: using "Remotes" extension, local is MacOS, remote is linux
  • VSCode Version: 1.95.1
  • R Version: 4.3.2
  • vscode-R version: 2.8.4

Additional context
Add any other context about the problem here.

Ok, I've been able to reproduce something like this. When a script has a plot and then an error, somehow the the plot doesn't get bumped. You can manually bump it with dev.next(). I'm not sure the technical terms for what's happening here, but hopefully it's clear in my screen recording. I put the two short scripts in this repo:

https://github.com/katrinabrock/minimal-r-package

Screen.Recording.2024-11-19.at.15.51.28.mov

After doing some digging, I think the problem is here:

addTaskCallback(update_plot, name = "vsc.plot")

When a script is sourced, the update_plot function gets called at the end. If there is an error in the script, it doesn't get called. I validated this by adding a print statement to my local copy like this:


    update_plot <- function(...) {
        print('Update Plot Has Been Called')
        tryCatch({

The result was this:


R version 4.3.2 (2023-10-31) -- "Eye Holes"
Copyright (C) 2023 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

.vsc.attach()
[1] "Update Plot Has Been Called"
[1] "Update Plot Has Been Called"
> .vsc.attach()
[1] "Update Plot Has Been Called"
> source('plot_and_succeed.R')
[1] "A"
[1] "no problems here"
[1] "Update Plot Has Been Called"
> source('plot_and_fail.R')
[1] "B"
Error in eval(ei, envir) : theres a problem
> dev.cur()
pdf 
  2 
[1] "Update Plot Has Been Called"

with basically the same plotting outcome as in the video above.

Using addTaskCallback goes back really far. Looks like it was introduced here: a032fd4 I'm surprised no one else has it this issue.