Microsoft/monaco-editor

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

Open

#3,395 创建于 2022年11月5日

在 GitHub 查看
 (3 评论) (0 反应) (0 负责人)JavaScript (1,283 fork)batch import
buggrammarshelp wantedlanguages-basic

仓库指标

Star
 (14,836 star)
PR 合并指标
 (平均合并 6小时 26分钟) (30 天内合并 15 个 PR)

描述

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

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.

贡献者指南