microsoft / microsoft/monaco-editor

[Bug] Wrong syntax highlighting in c++'s attribute specifiers

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

Nobody has claimed this yet.

bug grammars help wanted languages-basic
Dominant language
JavaScript
Stars
46.8k
Forks
4.1k
Avg merge
17h 58m
Merged PRs (30d)
1

Description

Reproducible in vscode.dev or in VS Code Desktop?
  • Not reproducible in vscode.dev or VS Code Desktop
Reproducible in the monaco editor playground?
Monaco Editor Playground Code

[edit]

monaco.editor.create(document.getElementById('container'), {
	value: "[[nodiscard(\"is the word using highlighted? Yes it is and alignas too.\")]]\nint test() {\n    return 42;\n}",
	language: 'cpp'
});

[/edit]

Reproduction Steps
  • visit godbolt.org
  • Use C++ & x86-64 GCC 12.2
  • add this code snippet
[[nodiscard("is the word using highlighted? Yes it is")]]
int test() {
    return 42;
}

or the extended

#include <iostream>

[[nodiscard("is the word using highlighted? Yes it is")]]
int test() {
    return 42;
    std::cout << "but here it is okay to use the word using \n";
}

or just use this link https://godbolt.org/z/4cc31Wf4Y

Actual (Problematic) Behavior

Syntax highlighting is wrong when using specific keywords in string literals in attribute specifiers.
Found only the word "using" but properly there are more.
[edit]same for alignas[/edit]

The following (key)words don't have the problem:

  • volatile
  • static
  • mutable
  • const
  • return
  • int
  • "#include"

just see the color of the word "using"

image
same for the extended code
image

the other (key)words:
image

and for completion here the vscode version
image

Expected Behavior

Since it is a string literal, it should be the same color as other parts of the text.

Additional Context

When using godbolt, this bug appeared. The issue based on it is to be found at https://github.com/compiler-explorer/compiler-explorer/issues/4239

The suggestion was to create a issue here, since their syntax highlighting is monaco based.

relevant quotes:

RubenRBS
Hi! Thanks for the report. While we can probably patch this in our end, we ultimately rely on Microsof's own Monaco editor syntax highlighting for C++.
Can you report this issue in https://github.com/microsoft/monaco-editor?
If anyone wants to try and fix it, the offending file can be found in https://github.com/microsoft/monaco-editor/blob/main/src/basic-languages/cpp/cpp.ts

mattgodbolt
In fairness I think I patched support for this kind of stuff upstream in monaco 😊 so it could still be my fault... but yeah, probably an expert there (ie not me) should take a look.

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 with src/basic-languages/cpp/cpp.ts, identified in the issue as the syntax-highlighting source, and reproduce the examples in the Monaco Editor Playground. Check the attribute-specifier strings containing “using” and “alignas”; done means those words receive the same string-literal highlighting as the surrounding text without changing normal C++ keyword highlighting.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, typescript
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.