vscode icon indicating copy to clipboard operation
vscode copied to clipboard

JavaScript Intellisense not working for commonJS after upgrading to 0.10.10

Open sghung opened this issue 10 years ago • 24 comments

I updated to 0.10.10 today, hoping to try out the new JavaScript support with Salsa. Unfortunately, my Intellisense has stopped working. I am using type definition files from definitely typed (e.g. the express.d.ts).

For example, using 0.10.8:

var exp = require("express"); exp.Router

I will see the content assist for the "Router" function and I can visit the definition file by right clicking on "Router" > Go to Definition

Now when I do the same thing in 0.10.10, I don't see "Router" in the Intellisense list. In addition, the list seems to have variables I had defined earlier in my code (which doesn't apply to express at all).

sghung avatar Mar 07 '16 23:03 sghung

I have the same issue, intellisense seems to be completely missing as of 0.10.10 in javascript files. I tried introducing a skeleton jsconfig.json file:

{ "compilerOptions": { "target": "ES6", "module": "commonjs" } }

This doesn't help. I'm also using typings from tsd.

For reference, I tried the exact same setup but changed my file to .ts and tsconfig.json and intellisense worked properly as before the update.

Daynil avatar Mar 08 '16 06:03 Daynil

My issue seems to be related to this as well. https://github.com/Microsoft/vscode/issues/3813

slowmove avatar Mar 08 '16 08:03 slowmove

I have same problem. Javascript intellisense stopped working after update in HTML files. In javascript files it's working fine

konrad147 avatar Mar 08 '16 08:03 konrad147

@konrad147 Yours is expected behavior. From the patch notes: There is no longer support for IntelliSense in script sections inside HTML documents.

Daynil avatar Mar 08 '16 08:03 Daynil

@konrad147

I have same problem. Javascript intellisense stopped working after update in HTML files. In javascript files it's working fine

Sorry, but this is a know limitation that is documented in release notes. We will work with the TypeScript team to bring this back.

egamma avatar Mar 08 '16 09:03 egamma

@sghung this works for me, pls see below. Do you have a jsconfig.json defined? Can you compare the setup in the screenshot with your setup

image

egamma avatar Mar 08 '16 09:03 egamma

@Daynil do you have a setup that allows me to reproduce the problem.

egamma avatar Mar 08 '16 09:03 egamma

I have a similar problem with Javascript after updating to 0.10.10. After update it completely stopped working, forcing Intellisense to show up with ctrl+space shows "Loading..." tooltip which hangs forever. Once I got a tooltip that "[Javascript service?] crashed 5 times in 5 minutes" (are those crash reports logged somewhere so I could share them?)

Some details that maybe could be useful for establishing pattern:

Update 2: OK, I am pretty sure that I correlated the issue with VS Code trying to parse and cache existing JS folders. My folder structure looks like this:

/
- jsconfig.json
- [other config files etc.]
/ client
  / app - folder with our code
  / jspm_packages - jspm packages
/ node_modules - dev. npm packages (gulp etc.)
/ jspm_packages - old folder, which is not used right now

Opening this folder does crash Intellisense for JS files. It can be fixed with one of few ways:

  • remove jsconfig.json - VS Code does give some intellisense then, but it does not scan jspm/npm folders.
  • remove both node_modules and old jspm_packages - VS Code will start helper child process, in my case it will load about 400MB of cached data and Intellisense will work as expected.
  • exclude explicitly node_modules in jsconfig.json - This will prevent VS Code from scanning node_modules, and work similarly to previous point

To see what happens when Intellisense is broken we can observe child processes it spawns. One of child processes will try to cache files from folders I mentioned above, crash silently, new one will be spawned and so on. After few crashes VS Code will show message I mentioned before.

One thing I can't figure out to create a repro is why for some projects VS Code will cache node_modules and for some won't (without even excluding them from jsconfig.json)

Update 1: Changing jsconfig.json (by removing exclude or by changing module to different values doesn't help, same for setting it empty with { }, but removing jsonconfig.json file altogether does help.

Old post: The problem is not machine wide, for simpler projects I have it does work well (I can have 2 instances of VS Code running side by side, one is having Intellisense, one is stuck. I do have jsconfig.json, for me it looks like that:

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

Making it identical to what @egamma suggested did not solve the problem.

I tried to open only small part of the project and it still hangs (by opening a folder -> pointing it to some subdirectory with 2-3 *.js files; maybe VS Code is smart enough to look up in directory tree to "base directory"?)

The project I have problem with is of rather small (around 50 js files, many of them very short) we are using AngularJS 1.5 with jspm (systemjs) and pure ES6, no TS (no tsd/typings folders are present). Our setup is maybe somewhat unusual as we are using ES6 modules to do heavy lifting when defining Angular components, something like this:

import template from './match.html!text';
import controller from './match.controller';
import link from './match.link.js';

let matchComponent = function(){
    return {
        template,
        controller,
        [...],
                link : link
    };
};

I will try to duplicate my project layout and see if I can get a minimal repro.

Ravadre avatar Mar 08 '16 13:03 Ravadre

I also am having problems with the intellisense now, getting that ~10s lag. It seems to happen intermittently, but it consistently happens when typing "try" or "trycatch" to get the snippet. The lag ranges from ~3-10s. I tried this in a new file in a new folder, and the lag doesn't occur. Only in my actual project.

ghost avatar Mar 08 '16 13:03 ghost

@egamma I added the jsconfig.json as you had suggested. That did not fix the issue. However, if I restart VS Code, then intellisense works again. Are the jsconfig.json properties being cached somehow? (that would be fixed on a restart?)

sghung avatar Mar 08 '16 15:03 sghung

@sghung

I added the jsconfig.json as you had suggested.

OK, can you confirm that you didn't have a jsconfig.json when Intellisense didn't work?

Are the jsconfig.json properties being cached somehow? (that would be fixed on a restart?)

yes, but you do not have to restart you can execute Reload JavaScript Project.

egamma avatar Mar 08 '16 16:03 egamma

@Ravadre please notice that the jsconfig.json I included in this issue was just for this particular project setup. In general you exclude the folders with generated or library JS code, pls see https://code.visualstudio.com/Updates#_languages-javascript the section 'Migration'

Something like

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "ES6"
    },
    "exclude": [
        "node_modules",
        "jspm_packages",
        "client/jspm_packages
    ]
}

egamma avatar Mar 08 '16 16:03 egamma

@egamma Yes, I can confirm that I did not have a jsconfig.json file in my workspace (in VS Code 0.10.8, I didn't need a jsconfig.json for intellisense to work).

Thanks for the tip regarding Reload JavaScript Project, that worked. Now to workaround this issue I do:

  1. Test Intellisense not working in project
  2. Add jsconfig.json
  3. Test intellisense not working in project
  4. Run "Reload JavaScript Project" command
  5. Test Intellisense now works in project

sghung avatar Mar 08 '16 16:03 sghung

@egamma Migration section, which for some reason I missed when I read changelog yesterday explains a lot. It also perfectly explains why removing jsconfig helped. I guess most time I spent on testing was futile :disappointed: .

Possibly, one thing I think could be useful to add would be some sort of a message to inform user that TS engine crashes because of (possibly?) running out of memory. Right now forgetting to exclude 1-2 jspm/node directories can mean that Code will constantly parse those file in the background (which means high IO, allocating lots of memory) over and over again.

Thanks for help!

Ravadre avatar Mar 08 '16 16:03 Ravadre

Here's how my setup looks when I'm getting the issue, with the jsconfig.json set up as directed by @egamma :

intellisense

Daynil avatar Mar 08 '16 18:03 Daynil

@Ravadre agreed that we should provide more guidance for how to exclude folders and also in the case of a crash. This is tracked in #3901

egamma avatar Mar 09 '16 10:03 egamma

@bill-mybiz your behaviour can be explained by not excluding folders in the jsconfig.json pls see this comment https://github.com/Microsoft/vscode/issues/3791#issuecomment-193848434.

egamma avatar Mar 09 '16 10:03 egamma

@Daynil

I cannot reproduce what you show in the comment above (with or without jsconfig.json) image

Can you start with the minimal example from the screenshot, does this work for you? Next, can you and more of your setup until Intellisense breaks?

Also when adding/modifying the jsconfig.json can you make sure that run the 'Reload JavaScript' command.

egamma avatar Mar 09 '16 11:03 egamma

@egamma This is a TypeScript project and there are no source js files in my ts files glob. But just for the fun of it, I added a jsconfig.json as follows in the root directory (alongside my tsconfig):

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "ES6"
    },
    "exclude": [
        "bin",
        "bin-webpack",
        "client/node_modules",
        "client/platforms",
        "client/plugins",
        "client/resources",
        "node_modules"
    ]
}

I tried both restart javascript project command and restarting vs code itself and there is no difference. There are still several seconds of lag with the trycatch snippet option (as well as with other ctrl+shift+spacebar intellisense). When I hit ctrl+space on "trycatch" to get the snippet intellisense option, it will consistently lag about 10sec. Ctrl+space thereafter will be immediate as long as I don't edit anything. But if I hit spacebar just after trycatch (to move the cursor off of the symbol), then left arrow (to return to the end of "trycatch"), and then ctrl+space, there will be the 10 second lag again.

I also tried to explicitly exclude folders in tsconfig, but it is not allowed when using the files glob.

My project is available on GitHub here.

ghost avatar Mar 09 '16 13:03 ghost

@bill-mybiz since this is a TypeScript project then your issue is unrelated to what is discussed here and you are in the wrong issue :smile:

I also tried to explicitly exclude folders in tsconfig, but it is not allowed when using the files glob.

I see that you are using filesGlob this attribute is not supported in TS version that is used by VS Code (fileGlob is an Atom TypeScript specific extension). I would recommend to not use files glob but have a tsconfig.json that has no files section but that uses exclude.

egamma avatar Mar 10 '16 10:03 egamma