Skip to content
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

execute() hook for Positron can run blocks out of order #509

Closed
DavisVaughan opened this issue Aug 6, 2024 · 1 comment · Fixed by #510
Closed

execute() hook for Positron can run blocks out of order #509

DavisVaughan opened this issue Aug 6, 2024 · 1 comment · Fixed by #510

Comments

@DavisVaughan
Copy link
Collaborator

See posit-dev/positron#4231

Check out the following video. If you "run all above" and then very quickly run another code block, then the blocks have the potential to be run out of order.

broken.mov

This is due to the way this execute() hook works for Positron

execute: async (blocks: string[], _editorUri?: vscode.Uri) : Promise<void> => {
for (const block of blocks) {
let code = block;
if (language === "python" && isKnitrDocument(document, engine)) {
language = "r";
code = pythonWithReticulate(block);
}
await hooksApi()?.runtime.executeCode(language, code, false);
}
},

Note that the await happens within the loop at each iteration. That means that after the first await, we can switch away to some other code - in particular someone else could call execute() and we could execute their code before we finish executing all of the blocks that we need to run.

@lionel- and I have a patch that only performs the await on the last code block. That ensures that we can sequentially fire off all of the blocks without the potential of having someone else execute code in between two of our blocks. I'll send in a PR for this.


---
title: "Untitled"
format: html
---


```{r}
library(tidyverse)
library(phyloseq)
library(decontam)
```


```{r}
x <- 1
```

```{r}
y <- x
```

```{r}
z <- y
```

```{r}
a <- z
```


```{r}

```


@DavisVaughan
Copy link
Collaborator Author

I can confirm that this is an issue for more than just Positron. Here is a video of the Quarto extension in VS Code with VSCode-R, same problem. So that suggests we should use the new TaskQueueManager anywhere we need to execute code for a particular language (We should probably give VSCode-R and Positron's native R different keys in the TaskQueueManager if we do this).

issue.mov

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 a pull request may close this issue.

1 participant