Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does VSCode not recognize the JavaScript spread operator and autocompletes instead?

I have been struggling with a really annoying behaviour of Visual Studio Code recently.

Whenever I try to use the JavaScript spread syntax VSCode automatically autocompletes the next piece of code (wrongly). Note I am NOT hitting TAB. Here's a demonstration of what I'm talking about:

Annoying autocomplete behaviour demonstration

Is there a way to disable this? This is really driving me mad... I am using Visual Studio Code 1.59.0 (which should be the latest release at the time of authoring this question).

like image 827
Behemoth Avatar asked Aug 09 '21 17:08

Behemoth


People also ask

How do I display JavaScript output code in Visual Studio?

Open the JavaScript code file in Text Editor, then use shortcut Control + Alt + N (or ⌃ Control + ⌥ Option + N on macOS), or press F1 and then select/type Run Code , the code will run and the output will be shown in the Output Window.

Can you run JavaScript in VS Code?

JavaScript in Visual Studio Code. Visual Studio Code includes built-in JavaScript IntelliSense, debugging, formatting, code navigation, refactorings, and many other advanced language features. Most of these features just work out of the box, while some may require basic configuration to get the best experience.

Why is VS Code not working with my JavaScript or TypeScript project?

However, there are some cases where VS Code is limited to working only with your currently opened files and is unable to load the other files that make up your JavaScript or TypeScript project. This can happen in a few instances: You are working with JavaScript or TypeScript code on vscode.dev or github.dev and VS Code is running in the browser.

What advanced JavaScript features are supported by Visual Studio Code?

This topic describes some of the advanced JavaScript features supported by Visual Studio Code. Using the TypeScript language service, VS Code can provide smart completions (IntelliSense) as well as type checking for JavaScript.

How to work with JavaScript in Visual Studio Code?

Working with JavaScript 1 IntelliSense #. Visual Studio Code's JavaScript IntelliSense provides intelligent code completion, parameter info, references search, and many other advanced language features. 2 JavaScript projects (jsconfig.json) #. ... 3 Type checking JavaScript #. ... 4 Using tasks #. ... 5 Disable JavaScript support #. ...

What is VSVs code?

VS Code allows you to leverage some of TypeScript's advanced type checking and error reporting functionality in regular JavaScript files. This is a great way to catch common programming mistakes. These type checks also enable some exciting Quick Fixes for JavaScript, including Add missing import and Add missing property.


4 Answers

As I mentioned in my comment elsewhere, the github issue is Typing repeated dots in js expands to first suggestion.

In that issue a couple of temporary fixes are mentioned:

"editor.suggest.showWords": false

or

"editor.acceptSuggestionOnCommitCharacter": false

The .'s are commit characters in javascript and so one of the suggestions will be selected that you do not want.

[You might be able to increase the quick suggestions delay time as a possible fix, but I can't test that since I can't actually repro this bug on my setup.]

[If you still are facing this problem make sure to upgrade to v1.59.1, which included a fix. If that doesn't fix it for you, file an issue.]

like image 163
Mark Avatar answered Oct 27 '22 02:10

Mark


It appears to be an issue introduced in the latest update to VSCode.

I have one laptop running the latest version that is exhibiting the issue. And another laptop that was running an older version and did not exhibit the issue. Upon updating the laptop with the older version to the latest it too now has this annoying bug...

EDIT:
As a temporary fix I just reinstalled version 1.58.2 on my laptops which has resolved the issue. https://code.visualstudio.com/updates/v1_58

like image 22
Reid187 Avatar answered Oct 27 '22 01:10

Reid187


I made a user snippet to work around the issue for now:

  "Spread": {
    "scope": "javascript,typescript",
    "prefix": "spd",
    "body": ["...$1"],
    "description": "spread rest operator vs code fix"
  }

Basic but does the job. Just create a snippet and drop it in.

like image 24
Cody Avatar answered Oct 27 '22 02:10

Cody


This appears to be fixed in the latest commit, which is 1.59.1.

like image 22
Chicago Dad Avatar answered Oct 27 '22 02:10

Chicago Dad