Visual Studio Code Intellisense不适用于Javascript [英] Visual Studio Code Intellisense not working for Javascript
问题描述
我在Windows和Mac上使用Visual Studio Code(VSC)0.10.11。出于这个问题的目的,我有一个小的JavaScript代码段:
'use strict';
const os = require('os');
console.log(os.homedir());
我在Visual Studio Code上关注了John Papa(
但不是 os
和 homedir()
:
< a href =https://i.stack.imgur.com/Rw0hi.png>
但是所有4种类型都可以在 typings / main / ambient / node / index.d.ts中找到
。我知道在 os
的情况下差别是 require
,但在John Papa的视频课程中,VSC还提供了IntelliSense用于所需的模块。不同的是,John Papa使用 tsd
,而我使用 typings
。
所以我的问题是
- 如何为所有已知类型启用Intellisense?
- 我需要做什么,VSC为我提供快速修复(模数下缺少打字的绿线)?
以上链接已过时。在较早版本的 VS Code 中,您需要引用您的输入,例如 ///< reference path> for somelibrary.d.ts
。
对于新版本,您需要通过创建 jsconfig.json <来初始化项目/ code>在项目的根目录中添加以下内容:
{
compilerOptions :{
target:es5,
module:commonjs
},
exclude:[
node_modules
]
}
接下来安装你需要的输入。您可以使用tsd或typings。在您的情况下,您需要安装 tsd安装节点
或 typings安装节点--ambient
。确保已安装 typings / tsd
。重启项目。
请参考docs:
- 安装JS项目 - < a href =https://code.visualstudio.com/docs/languages/javascript\"rel =noreferrer> https://code.visualstudio.com/docs/languages/javascript
- Node.js - https://code.visualstudio.com/docs/runtimes / nodejs
- 调试 - https:// code.visualstudio.com/docs/editor/debugging
更新:
从版本1.7开始,无需手动安装打字,应自动下载。 更好的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):
but not os
and 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)?
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:
- Setup JS project - https://code.visualstudio.com/docs/languages/javascript
- Node.js - https://code.visualstudio.com/docs/runtimes/nodejs
- 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
这篇关于Visual Studio Code Intellisense不适用于Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!