Skip to content

Add reflow comments in cell command - #1087

Open
vezwork wants to merge 3 commits into
mainfrom
feature/reflow-comment-command
Open

Add reflow comments in cell command#1087
vezwork wants to merge 3 commits into
mainfrom
feature/reflow-comment-command

Conversation

@vezwork

@vezwork vezwork commented Aug 12, 2026

Copy link
Copy Markdown
Member

Fixes #408

Kapture.2026-08-12.at.16.01.03.mp4
  • Adds a command "Quarto: Reflow Comments in Cell" that breaks up long comment lines into multiple comment lines (by default 80 characters is considerered long, but that is configurable by quarto.cells.reflowColumn)

Tested lightly in both VSCode and Positron.

@posit-snyk-bot

posit-snyk-bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@vezwork vezwork changed the title Add reflow command Add reflow comments in cell command Aug 12, 2026
@vezwork
vezwork requested a review from juliasilge August 12, 2026 20:06

@juliasilge juliasilge left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is working well for most situations where I think people would want it! I ran reflowComments directly on some other comment shapes, and IMO it rewrites a few things people will not expect. The command walks the whole cell body, so the surprising edits are not always near the cursor. One invocation on this cell produces two separate edits:

```{r}
# This is a fairly long comment about the join that goes well past the eighty column mark and so it gets rewrapped
x <- 1

# TODO before release:
# - check the join keys
# - drop the temp columns
```

The first comment wraps, which is what the user asked for. The TODO list four lines below also collapses, into # TODO before release: - check the join keys - drop the temp columns.

Shapes that come out changed:

  • Bullet lists inside a comment join into one paragraph.
  • #!/usr/bin/env bash becomes # !/usr/bin/env bash. The prefix fallback in parseLine moves the ! into the text.
  • A cell indented inside a list item loses its indentation, because markdown-it returns dedented text.
  • A line that starts with # inside a multi-line string gets wrapped as though it were a comment.

None of these break a render and each one is a single undo, so I don't think the heuristic needs to learn every structure. How about we make an escape hatch? When there is a selection, reflow only the comment runs inside the selection. Then a user who hits one of these cases can select the paragraphs they want and leave the rest of the cell alone. I included an inline comment where I think this should happen.

const includeFence = false;

const tokens = this.engine_.parse(document);
const block = languageBlockAtLine(tokens, editor.selection.start.line, includeFence);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can this use the selection when there is one? Today it reflows every comment run in the cell, so a user who selects three comment lines still gets the whole cell rewrapped. Filtering reflows to the runs that intersect the selection would cover it. The context menu needs a change too: the when clause at apps/vscode/package.json:675 hides the command while a selection exists.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This seems like a good idea.

@vezwork

vezwork commented Aug 13, 2026

Copy link
Copy Markdown
Member Author

@juliasilge Thanks for the review! Those are nice examples for me to consider... I wonder, what would you think about changing the command behaviour so that it only splits long comment lines, never joins them? It could also not normalize lines that aren't split e.g. to avoid cases like where #!/usr/bin/env bash becomes # !/usr/bin/env bash.

I think that would address the examples you gave, except:

  • A line that starts with # inside a multi-line string gets wrapped as though it were a comment.

I think we'd have to look at token information to avoid this case... idk how to do this but I will look into it.

Alternatively, we could make it so the command only reflows a comment if it overlaps the cursor? Maybe that gives the user the most control of when to apply this tool to the point that these strange cases don't matter as much? But would it be tedious?

@juliasilge

Copy link
Copy Markdown
Collaborator

only splits long comment lines, never joins them

That seems like a good option to me!

we could make it so the command only reflows a comment if it overlaps the cursor

That would be an option, yes, or we could consider two commands if you don't want the command to behave differently in different situations:

  • Reflow Comments in Cell
  • Reflow Comments in Selection

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 this pull request may close these issues.

Add VS Code support for a rewrap or reflow action for comments

3 participants