Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to enable JS object intellisense in prototype accessors in Visual Studio Code?

When creating a JS object and defining some accessors, I found that I couldn't get the intellisense after this.

Example code :

function Obj(foo) {
    this.foo = foo;
}

Obj.prototype = {
    get bar() {
        return this.// No intellisense here
    },
    set bar(val) {
        this.foo = val
    }
};

But creating a method with Obj.prototype.test = function () {...} will get me the intellisense.

Is there any way to replicate the same lexical analysis for this case with the user settings, or is it an actual flaw / bug ?

Edit: here is an image of what VSCode shows : VSCode intellisense

As you can see, it only shows previously used words, and nothing else.

Edit (03/04/2019): After trying again today, with v1.32.2, I noticed VSCode is able to suggest the bar property, but still not foo. So something was improved, but my issue not solved.

like image 357
Seblor Avatar asked Aug 11 '17 12:08

Seblor


People also ask

How do I enable IntelliSense in VS code?

You can trigger IntelliSense in any editor window by typing Ctrl+Space or by typing a trigger character (such as the dot character (.) in JavaScript).

Why is IntelliSense not working in VSCode?

If the IntelliSense is installed and still not working then most of the time restarting/reloading the program will solve the issue. So give it a try. Step 1: To restart VS Code open VS Code and press Ctrl + Shift + P keys together to open the command palette and type Reload Window in the search.

How do I enable JavaScript in Visual Studio?

1) Take VSCode 2) Right click on the file in left pane 3) Click "Reveal in explorer" from context menu 4) Right click on the file -> Select "Open with" -> Select "Choose another program" 5) Check box "Always use this app to open . js file" 6) Click "More apps" -> "Look for another app in PC" 7) Navigate to node.


1 Answers

Microsoft recommends restarting VS to see if it helps. Or you could be missing type declarations if this happens with other libraries besides objects.

There's a link here that has some troubleshooting tips that you can follow.

There's a more specific link here that deals with JavaScript in Code.

Also, Code might not show it because there already is something showing up related to it. It sees that it already showed foo. Try renaming it and see if that helps

like image 148
Jimenemex Avatar answered Oct 26 '22 03:10

Jimenemex