posit-dev / posit-dev/positron

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

Open
#3,233 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area: kernels area: quarto bug support
Dominant language
TypeScript
Stars
4.3k
Forks
184
Avg merge
1d 11h
Merged PRs (30d)
206

Description

Opening this in Positron, because we will likely make the PR to Quarto's vs code extension.
See also https://github.com/quarto-dev/quarto/pull/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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing Quarto's virtual-document behavior for a cursor inside a language chunk and Positron's statement range provider, using the linked Quarto pull request as context. Done when an option can request a virtual document containing only the current chunk and the cursor remains on the trailing newline instead of jumping to the next chunk.

Written by the indexing model from the issue text.

Assessment

Tech stack
r, typescript, vscode
Domain
developer-experience, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.