[英]Get Visual Studio Code to give intellisense for custom Javascript imports
I am writing automated testing scripts using TestComplete. 我正在使用TestComplete编写自动化测试脚本。 TestComplete mostly supports Ecmascript 2015, but it has a few quirks that are causing intellisense to not work as I would expect. TestComplete主要支持Ecmascript 2015,但是它有一些古怪之处,导致智能感知无法正常工作。
Here is two examples of code files: 这是代码文件的两个示例:
File: UsefulStuffFileName.js 文件: 有用的StuffFileName.js
class UsefulStuff {
constructor(initValue) {
this.initValue = initValue;
}
get someValue(){
return this.initValue + " someValue";
}
doStuff(input) {
return input + " stuff done";
}
}
module.exports.UsefullStuff = UsefullStuff;
File: WorkingHere.js 文件: WorkingHere.js
var useful = require('UsefulStuffFileName');
class WorkingHere {
constructor() {
this.usefullStuff = new useful.UsefulStuff("Hello");
}
doCoolStuff() {
// I want intellisense options when I type the period after this.usefulStuff
// The options would be someValue, doStuff() and initValue.
// |
// |
// V
let myVariable = this.usefullStuff.someValue;
}
}
The quirks, as I see them are: 我认为这些怪癖是:
module.exports.UsefullStuff = UsefullStuff;
导出是通过以下样式完成的: module.exports.UsefullStuff = UsefullStuff;
. 。 (This makes it work with TestComplete.) (这使其可以与TestComplete一起使用。) var useful = require('UsefulStuffFileName');
) “导入”分配给变量( var useful = require('UsefulStuffFileName');
) new useful.UsefulStuff("Hello");
). 对象的“新建”使用变量访问类( new useful.UsefulStuff("Hello");
)。 Is there anyway to configure Visual Studio Code to understand how these files are related and give me intellisense? 无论如何,有没有配置Visual Studio Code来了解这些文件之间的关系并给我带来智能?
Note: If I try the more standard import {UsefulStuff} from './UsefulStuffFileName';
注意:如果我尝试import {UsefulStuff} from './UsefulStuffFileName';
更标准的import {UsefulStuff} from './UsefulStuffFileName';
I get an error saying "Unexpected token import" from TestComplete. 我从TestComplete收到一条错误消息,提示“意外的令牌导入”。
This can be done via these steps. 可以通过以下步骤完成。
Change the import to look like this: 将导入更改为如下所示:
var { UsefulStuff } = require('UsefulStuff');
Change the instantiation of the class to look like this: 将类的实例更改为如下所示:
this.usefulStuff = new UsefulStuff("Hello");
Add a file called jsconfig.json
and put this in it: 添加一个名为jsconfig.json
的文件,并将其放入其中:
. 。
{
"compilerOptions": {
"baseUrl": "."
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.