microsoft / microsoft/monaco-editor

[Bug] Inlay hints duplicate when editor value is updated

Open
#4,700 3 comments 1 reaction 0 assignees View on GitHub

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

https://microsoft.github.io/monaco-editor/playground.html?source=v0.33.0#XQAAAAL4BAAAAAAAAABBqQkHQ5NjdMjwa-jY7SIQ9S7DNlzs5W-mwj0fe1ZCDRFc9ws9XQE0SJE1jc2VKxhaLFIw9vEWSxW3yscw7ec0Eu-n-5ctzOK0Uo_7UZeSGEZyXuNcTAKKg0H9aCn_vMhLAdVZkZjBxVYmeblT2gHUWXqt5sXwcsjO-RGfHkUuWa0xD7enHCr9lsyIaczHt2VbTvJx3eBQnBGJUtudz7PJAnw4TDkA5Gl8-Hbp7UViKGDc5NJPzAghMaO61XTxS8eBugqSUakUN4H56vWynf1IZk5kYUCKYVRDruLHCXv8_sw43lle2e5PpCYaA8pOD-Or6PuFyyAupawRCOq6R4lovZijHSNhDDZeN2hMO-wD0rQbmqwY7JqdyUA1WKzmO1SSJm1BIfKpVTr3-EdkKeMh3laEC_pFuhKrll45vW8se-4BsQXododSN039TCS2OrAyL_vPRdf8ENWroXYNXwyrN3FC8DHYLfS6zoM9LiKilR2WW8OMYkagWaLsr1H2_CZGdxUkaaBpuGXfZ_ggpa60YlIBaxHP7wqeOSZmknBSK2ItWBfwJzI0hJEtuCUpBVx5hfqqFmpYHCOVWEskOThqoNJ05aF3Zpx9s4hA2-uTn_W53N9r2ru8AzGi79RtcVqky9jl3LJedTOCr-wnpalwN8dSJbrMQrYZWfDgtXC__jQkhw

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
  1. load the modified sample
  2. in "preview", click into line 2, right behind parameter "(a:"
  3. 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

image

Expected Behavior

hints are rendered only once, even if editor value is updated

{28735216-227C-47DB-AB99-9F4C9FD251BF}

Additional Context

No response

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.