microsoft / microsoft/monaco-editor
[Bug] Inlay hints duplicate when editor value is updated
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?
- Not reproducible in the monaco editor playground
Monaco Editor Playground Link
seems to be broken from 0.33 onwards
Monaco Editor Playground Code
const value = `
const f = (a, b) => a + b;
const result = f(2, 5);
`;
const editor = monaco.editor.create(document.getElementById("container"), {
value,
language: "javascript",
});
monaco.languages.registerInlayHintsProvider("javascript", {
provideInlayHints(model, range, token) {
return {
hints: [
{
kind: monaco.languages.InlayHintKind.Type,
position: { column: 13, lineNumber: 4 },
label: `: Number`,
},
{
kind: monaco.languages.InlayHintKind.Type,
position: { column: 13, lineNumber: 2 },
label: `: Number`,
},
{
kind: monaco.languages.InlayHintKind.Type,
position: { column: 16, lineNumber: 2 },
label: `: Number`,
whitespaceBefore: true, // see difference between a and b parameter
},
{
kind: monaco.languages.InlayHintKind.Parameter,
position: { column: 18, lineNumber: 4 },
label: `a:`,
},
{
kind: monaco.languages.InlayHintKind.Parameter,
position: { column: 21, lineNumber: 4 },
label: `b:`,
whitespaceAfter: true, // similar to whitespaceBefore
},
],
dispose: () => {},
};
},
});
setTimeout(() => {
editor.setValue(value + " test235");
}, 2000);
Reproduction Steps
- load the modified sample
- in "preview", click into line 2, right behind parameter "(a:"
- you should see that the hints are now duplicated
addition:
if you increaste the amount of "editor.setValue" call the amount of hint duplication stacks accordingly
Actual (Problematic) Behavior
duplicte hints are shown, after the editor value has been set to a new value
Expected Behavior
hints are rendered only once, even if editor value is updated
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 sample and reproduce the issue by calling editor.setValue repeatedly. Inspect the inlay hints provider lifecycle and how hints are refreshed after the editor value changes. Done means the sample renders each hint only once after every value update.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100