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

Quarto: Virtual doc should have an option for only including the current chunk in the document #3233

Open
DavisVaughan opened this issue May 22, 2024 · 0 comments
Labels
area: quarto Issues related to Quarto category. bug Something isn't working

Comments

@DavisVaughan
Copy link
Contributor

DavisVaughan commented May 22, 2024

Opening this in Positron, because we will likely make the PR to Quarto's vs code extension.
See also quarto-dev/quarto#436

Currently, Quarto's virtual docs include all of that language's chunks in the document. For example, with a Quarto doc like this:

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

```{r}
1 + 1
2 + 2
3 + 3

```

a
asdf

```{r}
4 + 4
5 + 5
```

The virtual doc when your cursor is in the first chunk looks like this

# ---
# title: "Untitled"
# format: html
# ---
# 
# ```{r}
1 + 1
2 + 2
3 + 3

# ```
# a
# asdf
# ```{r}
4 + 4
5 + 5
# ```

This form trips up the statement range provider when the cursor is on 3 + 3, as it causes the cursor to jump down to 4 + 4, thinking that that is the next line of code to execute. The sequence of events is something like:

  • We find 3 + 3 and use that as our code to execute
  • The statement range provider code in Positron moves down 1 line to the newline still within the chunk, and executes the statement range provider again to find where to put the cursor
  • Because we are still in an R chunk, quarto gives us the R virtual doc and we jump down to 4 + 4 as the next line to execute

Notably, if you remove the newline after 3 + 3 this problem doesn't occur, because in the 2nd bullet from above when we move down 1 line we step out of the R chunk, so on the quarto side we aren't in an R virtual doc anymore, and Ark doesn't even get a chance to provide a statement range. That ends up putting us on the triple backtick line of the chunk, which is actually good behavior.

To fix the problem of jumping the cursor from one chunk to the next, I think Quarto's virtual docs should have an option to request that the virtual doc ONLY contain the current chunk, rather than all of them for that language. That would look like this

# ---
# title: "Untitled"
# format: html
# ---
# 
# ```{r}
1 + 1
2 + 2
3 + 3

# ```
# a
# asdf
# ```{r}
# 4 + 4
# 5 + 5
# ```

So now at 3 + 3 we'd move to the newline, but we'd see that there is no code to execute after that and we'd just stay on that line.

I imagine there may be other language features that could also benefit from tightly scoping the virtual doc to just the current chunk.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: quarto Issues related to Quarto category. bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant