Visual Studio Code使用typings拓展自动补全功能
2016-06-13 15:51
791 查看
今天正巧在看vscode官方文档的时候,看到了介绍其使用typings拓展自动补全功能的介绍,同时查了一点其他资料,感觉用起来非常方便。由于脑子总是会清空一些不常用的东西,因此记在这里方便以后参考。
参考来源:
官方介绍:
https://code.visualstudio.com/Docs/runtimes/nodejs#_intellisense-and-typings
gyzhao写的”Visual Studio Code 使用 Typings 实现智能提示功能”:
http://www.cnblogs.com/IPrograming/p/VsCodeTypings.html
但是如果使用node.js或者其require进去的相关函数就比较可怜了。
除了process模块,path、fs、__dirname等也同样没有自动补全。似乎在低版本下使用__dirname还会提示语法错误。
官方描述以及使用说明
https://www.npmjs.com/package/typings
vscode可以识别typings,因此可以通过typings来作为插件拓展vscode的功能。具体使用方法如下:
点击进去,顶部会提示
“Create a jsconfig.json to enable richer IntelliSense and code navigation across the entire workspace.”
选择create,vscode就会创造一个jsconfig.json的文件,内容大致如下:
所有需要的参数都会帮我们设置好。此时我使用的是vscode v1.2.0生成的jsconfig,低版本自动生成的配置可能会比里面的少一点,但不影响。
其中”dt~”为使用DefinitelyTyped类型定义的意思,vscode可以识别这种定义。
之后可以看到在项目目录下出来了新的文件夹“typings”
现在输入process,自动地补全出来了~window下可能需要重启下vscode才能看到自动补全的效果。
以上。个人很喜欢使用vscode,通过typings拓展自动补全功能大大地提升了代码开发效率。
最后,亲测前端用的js也可以通过这种方法实现自动补全。
参考来源:
官方介绍:
https://code.visualstudio.com/Docs/runtimes/nodejs#_intellisense-and-typings
gyzhao写的”Visual Studio Code 使用 Typings 实现智能提示功能”:
http://www.cnblogs.com/IPrograming/p/VsCodeTypings.html
vscode的自动补全
vscode原本是只有es原生api有带自动补全的功能, 如图所示但是如果使用node.js或者其require进去的相关函数就比较可怜了。
除了process模块,path、fs、__dirname等也同样没有自动补全。似乎在低版本下使用__dirname还会提示语法错误。
使用Typings添加自动补全
typings官方描述是一个TypeScript的定义管理器,集成管理了常用函数的语法规则。不知道跟微软有没有关系,不过这点倒是真的挺方便的。官方描述以及使用说明
https://www.npmjs.com/package/typings
vscode可以识别typings,因此可以通过typings来作为插件拓展vscode的功能。具体使用方法如下:
-配置jsconfig.json
在使用typings之前,需要在vscode里面配置一下名为jsconfig.json的文件。配置方法很简单,随便选中一个js文件,vscode右下角会弹出一个绿色的小灯泡,如图所示:点击进去,顶部会提示
“Create a jsconfig.json to enable richer IntelliSense and code navigation across the entire workspace.”
选择create,vscode就会创造一个jsconfig.json的文件,内容大致如下:
{ // See https://go.microsoft.com/fwlink/?LinkId=759670 // for the documentation about the jsconfig.json format "compilerOptions": { "target": "es6", "module": "commonjs", "allowSyntheticDefaultImports": true }, "exclude": [ "node_modules", "bower_components", "jspm_packages", "tmp", "temp" ] }
所有需要的参数都会帮我们设置好。此时我使用的是vscode v1.2.0生成的jsconfig,低版本自动生成的配置可能会比里面的少一点,但不影响。
-安装typings
使用npm全局安装typingsnpm install -g typings
-安装语法插件
以安装node.js自动补全为例,在项目根目录下使用bash或者cmd,输入typings install dt~node --global
其中”dt~”为使用DefinitelyTyped类型定义的意思,vscode可以识别这种定义。
之后可以看到在项目目录下出来了新的文件夹“typings”
现在输入process,自动地补全出来了~window下可能需要重启下vscode才能看到自动补全的效果。
-express、lodash等的自动补全
类似地,可以使用以上的方法,实现其他模块的自动补全。typings install dt~express --global typings install dt~lodash --global
//vscode官方文档上express的typings使用的是 typings install dt~express dt~serve-static dt~express-serve-static-core --global
关于typings的其他相关.
-基本用法
语法复制自typings的Quick Start,个人对注释本地化了一下。# 安装Typings的命令行代码. npm install typings --global # 搜索对应模块的typings定义. typings search tape # 根据名称寻找一个可获得的typings定义. typings search --name react # 如果你用一个独立包的模块: # 或者并不是安装全局模块 # 比如并不是在命令行通过输入npm install -g typings这种方式安装的. typings install debug --save # 如果是通过script标记 # 或者是子环境的一部分 # 或者全局typings命令不可用的时候: typings install dt~mocha --global --save # 从其他版本处安装typings定义(比如env或者npm). typings install env~atom --global --save typings install npm~bluebird --save # 使用该文件`typings/index.d.ts` (在`tsconfig.json`文件使用或者用 `///` 定义). cat typings/index.d.ts
以上。个人很喜欢使用vscode,通过typings拓展自动补全功能大大地提升了代码开发效率。
最后,亲测前端用的js也可以通过这种方法实现自动补全。
相关文章推荐
- setlocale
- Object.keys()
- microstation level2 liner pattern
- 【GLSL教程】(一)图形流水线 【转】
- ES6 localStorage 类库
- bootstrap走动的进度条
- make -e install ,,,make命令的-e选项!
- 网页调用Activex实现,ocx封装成cab文件
- sys.argv的使用方法
- Application Fundamentals(应用程序基础)
- 浅谈SpannableString制造文字特效
- NavigationView更改菜单icon和title颜色变化效果
- (转)纹理映射过滤
- storm sum aggregate 原语 聚合 本地测试
- Unity3d--第三人称摄像机常用控制
- maven中jar包加载不了的原因
- 利用超融合打造新一代呼叫中心坐席桌面
- Bootstrap tutorial: A responsive design tutorial with Twitter Bootstrap 3
- word转换成pdf转换器在线转换的方法
- 判断两个矩形是否重叠