REditorSupport / REditorSupport/languageserver

Bug Report: R Language Server emits spurious `comment` semantic tokens for first character of every line in `.qmd` files

Open
#735 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
R
Stars
675
Forks
118
Avg merge
1d 37m
Merged PRs (30d)
11

Description

Summary

When a .qmd file contains one or more R code chunks, the R Language Server (or Quarto VS Code extension) emits a comment semantic token covering the first character of every line in the document — including YAML front matter keys, markdown prose, headings, and LaTeX math delimiters. This colors all those first characters green (#008000), overriding the correct TextMate grammar colors.

Environment

  • Editor: Cursor (VS Code-based)
  • Quarto extension: quarto.quarto (version: 1.133.0)
  • R languageserver: 0.3.18
  • OS: Windows 11

Steps to Reproduce

  1. Create a .qmd file with a standard YAML front matter and at least one R code chunk, e.g.:
---
title: "Test"
bibliography: refs.bib
format:
  html:
    toc: true
---

# Section heading

This is a paragraph of text.

$$
x = y + z
$$ {#eq-test}

```{r}
#| echo: false
print("hello")
```
  1. Open the file in VS Code / Cursor with the Quarto extension installed and an R Language Server active.
  2. Observe that the first character of every line (the t in title, the # in # Section heading, the T in This is a paragraph, the $ of $$, etc.) is colored green.
  3. Use Developer: Inspect Editor Tokens and Scopes (Ctrl+Shift+P) with the cursor on any affected first character.

Observed Token Info (from Inspect Editor Tokens and Scopes)

Example: first character t of YAML key title:

language          yaml
standard token    String
foreground        #008000
semantic token    comment
  foreground      comment → { "foreground": "#008000" }
textmate scopes   entity.name.tag.yaml
                  string.unquoted.plain.out.yaml
                  meta.embedded.block.frontmatter
                  text.html.quarto
  foreground      meta.embedded.block.frontmatter entity.name.tag.yaml → { "foreground": "#800000" }

Example: first $ of a display math block $$:

language          quarto
standard token    Other
foreground        #008000
semantic token    comment
  foreground      comment → { "foreground": "#008000" }
textmate scopes   keyword.control.import.math.begin.quarto
                  markup.math.block.quarto
                  text.html.quarto
  foreground      keyword.control → { "foreground": "#0000FF" }

The semantic comment token (green, #008000) overrides the correct TextMate colors for every affected character.

Expected Behaviour

The comment semantic token should only be emitted for actual R comments (lines beginning with # inside R code chunks). It should not be applied to:

  • YAML front matter keys
  • Markdown prose
  • Heading markers
  • LaTeX math delimiters ($, $$)
  • Any other non-R content

Actual Behaviour

The comment semantic token is applied to the first character of every line in the document whenever at least one R code chunk is present.

Key Observations

  • The issue is absent when the .qmd file contains no R code chunks.
  • Removing all R code chunks from an affected file immediately resolves the green coloring.
  • A .qmd file with identical front matter and body but no R chunks shows no issue.
  • The issue is therefore triggered by R Language Server activation, not by the YAML or Quarto language servers alone.
  • This behaviour was not present in earlier versions; it appears to be a recent regression.

Workaround

Add the following to .vscode/settings.json in the workspace to suppress the spurious color while preserving correct R comment coloring:

{
  "editor.semanticTokenColorCustomizations": {
    "rules": {
      "comment:yaml": "#800000",
      "comment:quarto": "#000000",
      "comment:r": "#008000"
    }
  }
}

Suggested Fix

The R Language Server (or the Quarto extension's LSP bridge) should scope semantic token emission to the language region of each token — i.e., comment tokens should only be emitted within R code block ranges, not propagated to the surrounding markdown/YAML document.

Contributor guide

No contributing guide indexed for this repository

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

Reproduce the issue in VS Code or Cursor using the provided .qmd example and inspect semantic tokens with Developer: Inspect Editor Tokens and Scopes. Trace comment-token emission in the R Language Server or Quarto extension's LSP bridge, focusing on R code chunk ranges. Done means comment tokens remain on actual R comments without coloring YAML, markdown, headings, or math content.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.