(编辑:更新了我尝试的事情的更多信息以及我遇到过的问题。)
我正在努力让Intellisense识别并利用我项目中常见文件夹中的JS文件。我目前的结构如下:
.vscode
launch.json
common
jsconfig.json
MyLib.js
tests
jsconfig.json
index.html
runtests.js
demo
jsconfig.json
index.html
demo.js
MyLib.js
只是:
function MyLib(){}
MyLib.prototype = { constructor: MyLib };
我的demo/jsconfig.json
文件如下所示:
{
"compilerOptions": {
"target": "ES5"
},
"include": [
"../common/MyLib.js"
]
}
现在,当我正在编辑demo.js
时,我开始输入:var x = new MyL
......没有任何反应。
我在配置中遗漏了什么?它需要某种文件吗?
更新
我将demo/jsconfig.json
更新为这样(添加files
,如Matt Bierner建议的那样):
{
"compilerOptions": {
"target": "ES5"
},
"files": [
"demo.js",
],
"include": [
"../common/MyLib.js"
]
}
...我能够在建议中看到MyLib
,但我在demo.js
创建的对象...
var x = new MyLib();
... x
无法看到MyLib
的任何属性,这是(IMO)Intellisense的重点。
答案 0 :(得分:1)
尝试配置项目,使其包含两个文件,使用files
选项明确列出项目中的所有文件:
{
"compilerOptions": {
"target": "ES5"
},
"files": [
"demo.js",
"../common/MyLib.js"
]
}
或使用include
选项:
{
"compilerOptions": {
"target": "ES5"
},
"files": [
"demo.js",
},
"include": {
"./**/*.js"
]
}
使用此配置,我会在demo.js
中看到MyLib
的建议。 Here's more information about the jsconfig options