monaco-editor icon indicating copy to clipboard operation
monaco-editor copied to clipboard

[Bug] Inlay hints duplicate when editor value is updated

Open 0xMMA opened this issue 1 year ago • 1 comments

Reproducible in vscode.dev or in VS Code Desktop?

  • [X] 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

0xMMA avatar Oct 01 '24 13:10 0xMMA

Found this https://github.com/microsoft/monaco-editor/issues/4658 maybe related

0xMMA avatar Oct 02 '24 07:10 0xMMA

Image

I'm experiencing this with my own tool squirrel-explorer where the inlay hints are calculated ahead of time when I render bytecode to text, without updating the actual text in the buffer. This issue I got a screenshot of happens when just mousing over the existing inlay hints.

s5bug avatar Nov 06 '24 08:11 s5bug