microsoft / microsoft/monaco-editor

[Bug] Invalid code action provided when selecting all text

Open
#4,269 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug typescript
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.44.0#XQAAAAI1BAAAAAAAAABBqQkHQ5NjdMjwa-jY7SIQ9S7DNlzs5W-mwj0fe1ZCDRFc9ws9XQE0SJE1jc2VKxhaLFIw9vEWSxW3yscw5c1BeH9Lk6dVRoGmlOsCWG55Tgtd-zhH9YwpoMsaCfCS71ss8FFzmIcOqARoRAb6HRMoOcO786l8L5tdMWyELs2N70bS103gid3b3_0bnQLLkmrpmGu_EhWoCLAoYpMsKJ1_sF2QrE9LqFkcPYhAh20p3TLvT4dhIRnmTi-AZrMNlKfuxVcXl_aBBSoYGzPR9YE6ils5aNRtorDgUxS5WUMSIfaTlEiKa2KOPZjns9VjM_HbKci7PUEvUQaUGNhscJcRV-e91TlgSptyeuVQWVE_i-5hhLLUAozbqjZaodtEq1No6jEnGBOawY1JacLPYFZ-_P66DiTKF3LLwUMNUsevNQcJa7yjWZ16ayofkN4ME4lqW8oEdZebTKMLpgcnvB2zOqHPe8ulYmf6C8pU1mJKjRkK8bCAzBuE6ghcK7FOd8ChhnEhG2wzEudHqHC89Vu2OQGZIgwCBUo2mYT5D7iXvCjLqlekduysfmkyz3Ljg13uTvU2okQTV-ikDQwXKQFVDlGJrGrOzuDblPJJm5Ehiur4ECenz6QlTrf6E4LrvsF6_yTQy5aEmxVpC9zK0tUlSB-jfva9XfdUIGwxif_lPiwJ9mbdQ-bpvTFmyCkZFTrf5XuNs3MWbB3LUiSaF5OubSG1zQkwTmzHcJOqQb_5keqJetBD19jmstj6I5L2c5Lkh4ULoStuAGnWV__pnSf3s0EX7mDfzhnc9LmbZRb8_-JAl5meYxegJZjy94lPcvUb_5Ck0Cg

Monaco Editor Playground Code
// Add additional d.ts files to the JavaScript language service and change.
// Also change the default compilation options.
// The sample below shows how a class Facts is declared and introduced
// to the system and how the compiler is told to use ES6 (target=2).

// validation settings
monaco.languages.typescript.javascriptDefaults.setDiagnosticsOptions({
	noSemanticValidation: true,

});

// compiler options
monaco.languages.typescript.javascriptDefaults.setCompilerOptions({
	target: monaco.languages.typescript.ScriptTarget.ES2015,
	lib: ['ES6'],
	allowNonTsExtensions: true,
	allowJs: true,
});

var jsCode = `const promise1 = Promise.resolve(3);
const promise2 = 42;
const promise3 = new Promise((resolve, reject) => {
  setTimeout(resolve, 100, 'foo');
});

Promise.all([promise1, promise2, promise3]).then((values) => {
  console.log(values);
});
// Expected output: Array [3, 42, "foo"]
`;

monaco.editor.create(document.getElementById("container"), {
	value: jsCode,
	language: "javascript",
});
Reproduction Steps

Using the code above, if I select the entire content (using Ctrl+A), the lightbulb icon is shown. This suggests a quickfix of removing the variable statement
image

Actual (Problematic) Behavior

While there is no apparent issue with the code, the quick fix suggests to remove the entire statement, thus leaving the remaining code invalid.

Expected Behavior

The quickfix shouldn't pop up

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 reproduction and run the provided JavaScript sample. Select all text with Ctrl+A, inspect the lightbulb's remove-variable quickfix, and trace why it is offered for the full selection. Done means the quickfix does not appear for this selection while valid code remains unaffected.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.