[Bug] ".ini" syntax's indented comments are not highlighted
Reproducible in vscode.dev or in VS Code Desktop?
- Not reproducible in vscode.dev or VS Code Desktop
Reproducible in the monaco editor playground?
- Not reproducible in the monaco editor playground
Monaco Editor Playground Link
Monaco Editor Playground Code
const value = /* set from `myEditor.getModel()`: */ `; Comment
key = value
; Comment
key = value
`;
// Hover on each property to see its docs!
const myEditor = monaco.editor.create(document.getElementById("container"), {
value,
language: "ini",
automaticLayout: true,
});
Reproduction Steps
- Create an ".ini" file in Monaco
- Add an un-indented line
; Comment, and observe that it is highlighted - Indent that line, such as
; Comment, and observe that it's no longer highlighted
Actual (Problematic) Behavior
Indented comments, such as ; Comment, are not highlighted
Expected Behavior
Indented comments should be highlighted, like is seen below in GitHub's syntax highlighting:
; Comment
; Comment
Additional Context
My agent says:
Root cause: Monaco's stock
ini.tsdefines the comment rule as/^\s*[#;].*$/inside the@whitespacestate. In monarchCompile.ts , any rule whose regex starts with^is flaggedmatchOnlyAtLineStart=true(and the^is stripped). In monarchLexer.ts the match loop gates every rule withif (pos === 0 || !rule.matchOnlyAtLineStart). For an indented comment; comment, the sibling whitespace rule/[ \t\r\n]+/consumes the leading spaces first, advancing pos to 2; the comment rule is then skipped (pos≠0 and it's line-start-only), nothing else matches ; , so Monaco applies defaultToken → the text renders white instead of comment-green. Non-indented comments work because pos is still 0 when the rule is reache
This issue is a pain for me because I'd very much like to indent our .ini files key/values and comments to make section headers foldable and easier to navigate, but if I attempt to do something like the below, our comments lose highlighting and wind up looking visually very similar to the key/value pairs:
[Section]
; Long comment explaining the reasons why we applied this
; setting, in what situations one might want to change it, and
; what the valid format for a new value is
key = value
Source: microsoft/monaco-editor