Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Code Intellisense not working for Javascript

I am using Visual Studio Code (VSC) 0.10.11 on Windows and Mac. For the purpose of this question I have this small JavaScript snippet:

'use strict';  const os = require('os'); console.log(os.homedir()); 

I followed John Papa on Visual Studio Code (Blog entry and Pluralsight Visual Studio Code JavaScript Intellisense - for those who have an account) and therefore I would expect that VSC provides Intellisense and Quick fix options when typings are available.

In the snippet above VSC recognizes console and log() (I use hoover, but it is the same with Intellisense):

console log

but not os and homedir():

os homedir

But all 4 typings are available in typings/main/ambient/node/index.d.ts. I know that the difference is the require in the case of os, but in John Papa's video course VSC also provided IntelliSense for required modules. A difference is that John Papa used tsd while I am using typings.

So my questions are

  • how can I enable Intellisense for all known typings?
  • what do I have to do that VSC offers me Quick fix (green line under moduls with missing typings)?
like image 206
ChrLipp Avatar asked Mar 26 '16 12:03

ChrLipp


People also ask

Why is IntelliSense not working in VS Code?

Why is VS Code suggestions not working? If you're coding in JavaScript or TypeScript and finds that VSCode IntelliSense does work but does not behave properly, it's likely that you've selected the wrong language mode. TypeScript and JavaScript share the same language service, so you need to select the right language.

Does JavaScript work on Visual Studio 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.

How do I enable IntelliSense in Visual Studio?

To access this options page, choose Tools > Options, and then choose Text Editor > C# > IntelliSense.


2 Answers

The above links are outdated. In older versions of VS Code you needed to reference your typings like /// <reference path> for somelibrary.d.ts.

With new version you need to initialize your project by creating jsconfig.json at the root of your project and add the following inside:

{     "compilerOptions": {         "target": "es5",         "module": "commonjs"     },     "exclude": [       "node_modules"     ] } 

Next install typing you need. You can use either tsd or typings. In your case you need to install tsd install node or typings install node --ambient. Make sure you have typings/tsd installed. Restart project.

Please refer to docs:

  1. Setup JS project - https://code.visualstudio.com/docs/languages/javascript
  2. Node.js - https://code.visualstudio.com/docs/runtimes/nodejs
  3. Debugging - https://code.visualstudio.com/docs/editor/debugging

Update:

Since version 1.7 there is no need to manually install typings, they should be downloaded automatically. Better JavaScript IntelliSense

like image 139
Dauren Akilbekov Avatar answered Oct 08 '22 11:10

Dauren Akilbekov


There is a built-in extension called TypeScript and JavaScript Language Features (vscode.typescript-language-features) that is disabled.

In order to enable it, open Extensions panel, search for "@built-in JavaScript", and enable the required extension.

Now you should be able to use the autocomplete feature.

like image 25
underfox Avatar answered Oct 08 '22 10:10

underfox