Skip to content

Fix first character of non-code lines highlighted as a comment - #1155

Merged
juliasilge merged 4 commits into
quarto-dev:mainfrom
RDust4:fix/semantic-tokens-filler-lines
Sep 30, 2026
Merged

juliasilge merged 4 commits into
quarto-dev:mainfrom
RDust4:fix/semantic-tokens-filler-lines

Conversation

@RDust4

@RDust4 RDust4 commented Sep 27, 2026

Copy link
Copy Markdown
Contributor

Fixes #985.

Semantic tokens for code cells come from a virtual doc where every non-cell line is a # filler.
Language servers that emit comment tokens colored the first character of each paragraph, heading and YAML line as a comment.

Now only tokens on lines inside the language's code cells are kept.
This also drops tokens on the virtual doc's injected header lines (e.g. # type: ignore), which mapped to negative lines and made the provider throw, losing semantic highlighting for Python cells.

Adds a unit test for unadjustedSemanticTokens.

@posit-snyk-bot

posit-snyk-bot commented Sep 27, 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.

@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.

Thank you so much for this contribution! I think we still have a problem with magics, but with a bit of followup, this will be good to go. 🙌

Comment thread apps/vscode/src/providers/semantic-tokens.ts Outdated
Comment thread apps/vscode/src/vdoc/vdoc.ts Outdated
Comment thread apps/vscode/src/test/semanticTokens.test.ts
Johannes Piermeier and others added 2 commits September 30, 2026 14:24
The virtual doc replaces IPython magic lines (`%`, `%%`, `!`) with `#`
filler, but the semantic tokens provider treated every line between the
fences as code, so comment tokens on that filler were applied to the
real document (#985 inside a code cell).

`virtualDocForLanguage` now returns `codeLines`, the lines it filled with
real code, so the vdoc builder owns the rule. `unadjustedSemanticTokens`
takes the lines as a required parameter.

Tests go through `embeddedSemanticTokensProvider` with a fake python
provider, covering YAML, prose, fences, an R cell and magic lines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…iller-lines

# Conflicts:
#	apps/vscode/CHANGELOG.md
@RDust4

RDust4 commented Sep 30, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review! Updated:

  • Magics: went with your second option. virtualDocForLanguage now returns codeLines, the lines fillLinesFromBlock filled with real code, so the vdoc builder owns the rule for which lines are real code. Magic lines become # filler and are never in the set. The fence loop in the provider is gone.
  • lines is now required in unadjustedSemanticTokens. I removed the !lines || check and updated the doc comment.
  • a fake Python semantic tokens provider marks column 0 of every non-empty virtual-doc line, filler included, which is a bit stricter than # lines only. It runs against a new semantic-tokens.qmd (YAML, heading, paragraph, two Python cells with prose between them, an R cell) and against vdoc/magics.qmd. Tokens only land on the code lines of the Python cells. I checked that the magics test fails if magic lines are counted as code.

@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.

Thank you!

@juliasilge
juliasilge merged commit b6bbb4e into quarto-dev:main Sep 30, 2026
8 checks passed
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.

Syntax highlighting: First character of line treated as comment

3 participants