Skip to content

Using require in method breaks JavaScript IntelliSense #13033

@mjbvz

Description

@mjbvz

From @abc1236762 on December 15, 2016 19:4

  • VSCode Version: 1.8.0
  • OS Version: Windows 10.0.14393

Steps to Reproduce:

  1. Create a project folder and create func.js, main.js, and jsconfig.json in it.

jsconfig.json:

{
    "compilerOptions": {
        "target": "ES6"
    },
    "file": [
        "func.js"
    ]
}

func.js:

function Test() {
    // ...
}
// ...
Test.a = function() {
    // ...
    var k = require('n');
    // ...
    return 0;
};
// ...
Test.prototype.b = function() {
    // ...
    var k = require('n');
    // ...
    return 1;
};

main.js:

Test.a();
var test = new Test();
test.b();
  1. Open main.js, and move mouse on Test or a() at line 1, the ToolTip shows any, move mouse on any words, the ToolTip shows the sentence that have any. Also autocomplete do not show a when I type Test. and b when I type test..

  2. Edit func.js, make lines which has require as comment, like :

function Test() {
    // ...
}
// ...
Test.a = function() {
    // ...
    //var k = require('n');
    // ...
    return 0;
};
// ...
Test.prototype.b = function() {
    // ...
    //var k = require('n');
    // ...
    return 1;
};
  1. Open main.js, and move mouse on Test at line 1 and line 2, the ToolTip shows function Test(): void, but move mouse on a() at line 1, the ToolTip still shows any, move mouse on any words at line 2 and line 3, the ToolTip shows the sentence that haven't any. For example, test shows
var test: {
    b: () => number;
}
  1. Output Test.a() can get 0, test.b() can get 1. At Step 4, Visual Studio Code found the definition of test.b() as Test.prototype.b (move mouse on b() at line 3 and the ToolTip shows (property) Test.b: () => number), but not found the definition of Test.a() because move mouse on a() at line 1 and the ToolTip shows any. Also autocomplete show b when I type test., but not show a when I type Test..

Conclusion:
If the definition of the method or prototype of function in JavaScript have method require() in it, Intellisense in Visual Studio Code cannot find the definition of "that function, the prototype of that function, and the method of that function" at another JS file.
If the definition of the method or prototype of function in JavaScript do not have method require() in it, Intellisense in Visual Studio Code can find the definition of "that function, and the prototype of that function" at another JS file, but still cannot find the definition of method of that function at another JS file.

Copied from original issue: microsoft/vscode#17339

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixedA PR has been merged for this issueVS Code TrackedThere is a VS Code equivalent to this issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions