microsoft / microsoft/monaco-editor

[Bug] CodeActionProvider text edits doesn't work correctly with flag insertAsSnippet

Open
#4,335 0 comments 0 reactions 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.45.0#XQAAAAIBAwAAAAAAAABBqQkHQ5NjdMjwa-jY7SIQ9S7DNlzs5W-mwj0fe1ZCDRFc9ws9XQE0SJE1jc2VKxhaLFIw9vEWSxW3yscw2wHrou-n-5ctzOK0Uo_7UZeSGEZyXuNcTAKKg0H9aCn_vMhLAdVZkZjBxVYmeblT2gHUWXqt5sXwcsjO-RGfHkUuWa0xD7enHCr9lsyIaczHt2VbTvJx3eBQnBGJUtudz7PJAnw4TDkA5Gl8-Hbp7UViKGDc5NJPzAghMaO61XTxS8eBugqSUakUN4H56vWynf0s0XdAIfwRlGACA8voiMYHfmtMsrrresXRRvleM5KtIo4gqVKTdvjPuosMj4zXv8f4ww2aMqGiLqhCWtC32iNhUHphCGS8jXoJfAEqzlZKr_sS0gcBV1MzGDbtRgFaUdat3BU1LXtU_IxGJ4qLkXD7Ezkq3ECOV3dzwn3h6A5BfcQwCaT5Hald3QJDEocN8Vg2jO3sNSl8atviCG2zw_jFb21N0dNei297RJw7lVqRDlHKwSzb0eQLdItPklXir3rjbp8sJZoLgqGruPmIECSlRWmAfdhDqNQ6WSXntaB_rMAsQyu3xziZ68UoM6w2g7lP_2CSiwA

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.registerCodeActionProvider("javascript", {
	provideCodeActions: (model, range, context) => {
		return {
			actions: [
				{
					title: "Test action",
					edit: {
						edits: [
							{
								resource: model.uri,
								textEdit: {
									range: {startLineNumber: 1, startColumn: 1, endLineNumber: 1, endColumn: 1},
									text: "const ${1:test};",
									insertAsSnippet: true,
								},
								versionId: undefined,
							}
						]
					}
				}
			],
			dispose: () => {}
		}
	}
});
Reproduction Steps

try to use code action

Actual (Problematic) Behavior

code action insert text marked as snipped without modifying

Expected Behavior

code action insert text marked as snipped similar to CompletionProvider snippets

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 and the provided CodeActionProvider reproduction. Compare the code-action text edit behavior with the expected CompletionProvider snippet behavior, then locate the relevant editor API implementation and tests; no specific files or tests are named in the issue. Done means applying the action inserts and activates the ${1:test} snippet rather than plain text.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.