如何将 Intellisense 文件导入 vsCode (Visual Studio Code) [英] How to Import Intellisense files into vsCode (Visual Studio Code)

查看:52
本文介绍了如何将 Intellisense 文件导入 vsCode (Visual Studio Code)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定我是否理解智能感知如何在 Microsoft 的新 vsCode 文本编辑器中工作.在 文件 (d.ts)(没有编辑建议)) 还是我必须从 github 源中复制它们并将它们放在typings 目录中?

2 - 我可以为任何具有打字稿定义的库获取智能感知吗?我尝试了下面的方法,但是当我输入 express.when. 时,我没有得到任何智能感知.但是,我确实得到了节点智能感知.

///<参考路径="../typings/node/node.d.ts"/>///<reference path="../typings/express/express.d.ts"/>var when = require('when'), express = require('express'), gulp = require('gulp')

解决方案

更新:2016 年 8 月:TSD 现在已折旧.而是使用https://www.npmjs.com/package/typings

npm install typings --global

如果使用 2016 年 7 月 29 日发布的 VS2015 NodeJS v1.2,则在首次使用时会自动为您安装 Typings-core@1.3.1:

执行命令'npm install "C:PROGRAM FILES (X86)MICROSOFT VISUAL STUDIO 14.0COMMON7IDEEXTENSIONSMICROSOFTNODE.JS TOOLS FOR VISUAL STUDIO1.2TypingsAcquisitionTool"ntvs-typings-acquisition-tool@1.0.0 ..........
ode_modules
tvs-typings-acquisition-tool├── minimist@1.2.0└──typings-core@1.3.1 (array-uniq@1.0.3, thenify@3.2.0, zip-object@0.1.0, popsicle-status@2.0.0, popsicle-retry@3.2.1, listify@1.0.0,promise-finally@2.2.1,xtend@4.0.1,graceful-fs@4.1.5,throat@3.0.0,lockfile@1.0.1,strip-bom@2.0.0,sort-keys@1.1.2, string-template@1.0.0, make-error-cause@1.2.1, any-promise@1.3.0, has@1.0.1, rc@1.1.6, object.pick@1.1.2, debug@2.2.0, mkdirp@0.5.1, invariant@2.2.1, configstore@2.0.0, parse-json@2.2.0, touch@1.0.0, detect-indent@4.0.0, is-absolute@0.2.5, popsicle-proxy-agent@3.0.0, rimraf@2.5.4, popsicle@8.0.4, typescript@1.8.7)

-----原答案-----

Typescript 定义文件有一个包管理器.这是一个社区驱动的存储库,其中包含许多流行库的 Typescript 定义.

您可以按照此处的说明安装 tsd.

在全局安装 tsd 后,您可以在命令行中从项目根目录安装包,如下所示:

$ tsd install express --save

这将创建一个 Typings 目录(如果一个目录不存在)并添加一个带有 express.d.ts 文件的 express 目录.

它还创建了一个 tsd.d.ts 文件,其中包含对所有 tsd 文件的引用.如果我再安装几个 tsd,这就是它的样子.

现在要访问我的 tsd 文件,我需要做的就是在我的代码顶部使用 ///<reference path="typings/tsd.d.ts" 引用它们的路径./>

现在我得到了智能感知.

I'm not sure I understand how the intellisense works for Microsoft's new vsCode text editor. In the docs under the "Great Code Editing Experience" heading, it shows a warning under the node global variable __dir and offers a lightbulb suggestion to add a reference to a d.ts file so you can get intellisense for node:

I have 2 questions:

1 - How do I import DefinitelyTyped files (d.ts) directly (without editor suggesting it) or do I have to copy them from the github source and put them in a typings directory?

2 - Can I get intellisense for any library that has a typescript definition? I tried the below, but when I type in express. or when. , I don't get any intellisense. However, I do get node intellisense.

/// <reference path="../typings/node/node.d.ts"/>
/// <reference path="../typings/express/express.d.ts" />

var when    = require('when')
  , express = require('express')
  , gulp    = require('gulp')

解决方案

UPDATE: August 2016: TSD is now depreciated. instead use https://www.npmjs.com/package/typings

npm install typings --global

OR

If using VS2015 NodeJS v1.2 released 29th July 2016 then typings-core@1.3.1 is installed automatically for you during first use:

Executing command 'npm install "C:PROGRAM FILES (X86)MICROSOFT VISUAL STUDIO 14.0COMMON7IDEEXTENSIONSMICROSOFTNODE.JS TOOLS FOR VISUAL STUDIO1.2TypingsAcquisitionTool"
ntvs-typings-acquisition-tool@1.0.0 ..........
ode_modules
tvs-typings-acquisition-tool
├── minimist@1.2.0
└── typings-core@1.3.1 (array-uniq@1.0.3, thenify@3.2.0, zip-object@0.1.0, popsicle-status@2.0.0, popsicle-retry@3.2.1, listify@1.0.0, promise-finally@2.2.1, xtend@4.0.1, graceful-fs@4.1.5, throat@3.0.0, lockfile@1.0.1, strip-bom@2.0.0, sort-keys@1.1.2, string-template@1.0.0, make-error-cause@1.2.1, any-promise@1.3.0, has@1.0.1, rc@1.1.6, object.pick@1.1.2, debug@2.2.0, mkdirp@0.5.1, invariant@2.2.1, configstore@2.0.0, parse-json@2.2.0, touch@1.0.0, detect-indent@4.0.0, is-absolute@0.2.5, popsicle-proxy-agent@3.0.0, rimraf@2.5.4, popsicle@8.0.4, typescript@1.8.7)

-----Original Answer-----

There is a package manager for Typescript Definition Files. This is a community driven repository containing Typescript definitions for many popular libraries.

You can install tsd by following the instructions here.

Once you install tsd globally, you can install packages from your project root in the command line like this:

$ tsd install express --save

This will create a typings directory if one doesn't exist and adds an express directory with an express.d.ts file inside.

It also creates a tsd.d.ts file that contains the references to all of your tsd files. If I install a few more tsd's, here is what it looks like.

Now to access my tsd files, all I need to do is reference their path in at the top of my code with /// <reference path="typings/tsd.d.ts" />

Now I get intellisense.

这篇关于如何将 Intellisense 文件导入 vsCode (Visual Studio Code)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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