microsoft / microsoft/monaco-editor
[Bug] The setMonarchTokensProvider rule matches incorrectly
Nobody has claimed this yet.
- 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 Link
I have a list of rules
const keywords = [Stop,.............]
monaco?.languages.setMonarchTokensProvider('cpp', {
tokenizer: {
root: [[new RegExp(`\\b(${keywords.join('|')})\\b`), 'keyword']]
},
keywords: [Stop,.............]
});
I expected all keywords to be highlighted, but now Stop is included in the keywords list, but words ending in Stop will still be highlighted
The effect at the beginning of Stop is correct, but the effect at the end of Stop is wrong and should be shown in black, not yellow
How do I make it highlighted as a keyword only for Stop words, it shouldn't be highlighted if there are letters or words before and after it
Monaco Editor Playground Code
monaco.languages.register({ id: "mySpecialLanguage" });
monaco.languages.setMonarchTokensProvider("mySpecialLanguage", {
tokenizer: {
root: [
[/(?<!\w)Stop(?!\w)/, 'keyword']
],
},
});
monaco.editor.defineTheme("myCoolTheme", {
base: "vs",
inherit: false,
rules: [
{ token: 'keyword', foreground: 'f1d710' },
],
colors: {
"editor.foreground": "#000000",
},
});
monaco.editor.create(document.getElementById("container"), {
theme: "myCoolTheme",
value: `Stop
QdStop
qdStop
11Stop
StopSS
Stop11
Stopdd
`,
language: "mySpecialLanguage",
});
Reproduction Steps
No response
Actual (Problematic) Behavior
No response
Expected Behavior
No response
Additional Context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked Monaco Editor Playground reproduction and the setMonarchTokensProvider tokenizer rule using the Stop regex. Verify how token boundaries behave for Stop, QdStop, StopSS, and similar values; done means only the standalone Stop token is highlighted as a keyword.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100