Visual Studio Code Intellisense 不适用于 Javascript [英] Visual Studio Code Intellisense not working for Javascript

查看:33
本文介绍了Visual Studio Code Intellisense 不适用于 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(

但不是 oshomedir():

但是所有 4 种类型都可以在 typings/main/ambient/node/index.d.ts 中使用.我知道区别在于 os 中的 require,但在 John Papa 的视频课程中,VSC 还为所需模块提供了 IntelliSense.不同之处在于,John Papa 使用了 tsd,而我使用的是 typings.

所以我的问题是

  • 如何为所有已知类型启用智能感知?
  • 如果 VSC 为我提供快速修复(缺少类型的模块下的绿线),我该怎么做?

解决方案

以上链接已过时.在旧版本的 VS Code 中,您需要引用您的类型,例如 ///<reference path>对于 somelibrary.d.ts.

对于新版本,您需要通过在项目的根目录创建 jsconfig.json 并在其中添加以下内容来初始化您的项目:

<代码>{编译器选项":{目标":es5",模块":commonjs"},排除": [节点模块"]}

下一步安装键入您需要的内容.您可以使用 tsd 或typings.在您的情况下,您需要安装 tsd install nodetypings install node --ambient.确保您已安装 typings/tsd.重启项目.

请参考文档:

  1. 设置 JS 项目 - https://code.visualstudio.com/docs/languages/javascript
  2. Node.js - https://code.visualstudio.com/docs/runtimes/nodejs
  3. 调试 - https://code.visualstudio.com/docs/editor/debugging

更新:

从 1.7 版本开始,不需要手动安装类型,它们应该自动下载.更好的 JavaScript IntelliSense

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:

  1. Setup JS project - https://code.visualstudio.com/docs/languages/javascript
  2. Node.js - https://code.visualstudio.com/docs/runtimes/nodejs
  3. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆