简体   繁体   English

使用带有Visual Studio Code / JS的非标准内置插件添加自动完成功能

[英]Add auto-complete with non-standard builtins w/Visual Studio Code/JS

Visual studio code seems to have good support for javascript autocomplete, but I have a project which uses duktape to export a large and growing library of objects from my application. Visual Studio代码似乎对javascript自动完成功能有很好的支持,但是我有一个项目使用duktape从我的应用程序中导出了一个庞大且不断增长的对象库。

The library is growing quite quickly as more functionality gets exported, and I'm wondering if it's possible to somehow import or make VS code's intellisense aware of a set of "built in" objects. 随着更多功能的导出,该库正在快速增长,我想知道是否有可能以某种方式导入或使VS代码的智能感知了解一组“内置”对象。 These objects have no source per-se. 这些对象本身没有源。 They're exported via duktape's API calls. 它们是通过duktape的API调用导出的。 I can traverse over the global object space and dump the names of all known objects and print them formatted any arbitrary way. 我可以遍历全局对象空间并转储所有已知对象的名称,并以任意方式打印它们。

I'm looking for a way to make the global object dump (again, it can worked into any format) useful to intellisense or any other autocomplete engine. 我正在寻找一种使全局对象转储(再次可以以任何格式工作)对智能感知或任何其他自动完成引擎有用的方法。

I have a similar project ongoing and had exactly the same need. 我正在进行一个类似的项目,并且需求完全相同。 The solution is easy: create a typings file for your app and put it into node_modules/@type/<yourid> . 解决方案很简单:为您的应用程序创建一个打字文件,并将其放入node_modules/@type/<yourid> If you don't know about typings files read up on the Definitely Typed page. 如果您不知道打字文件,请在“ 绝对打字”页面上阅读。 On the welcome page there's another way to reference a typings file, if you don't have a node.js structure: 如果您没有node.js结构,则在欢迎页面上还有另一种引用类型文件的方法:

/// <reference path="<path>/yourtypes.d.ts" />

The typings file also works for plain JS code, if you give vscode some hints via type annotations. 如果您通过类型注释为vscode提供一些提示,则类型文件也适用于普通的JS代码。 That looks like: 看起来像:

/** @type {yourmodule.yourtype} */
var value; // Will be considered as being of type `yourtype`.

With that in place vscode will then show members for value in the code completion list. 有了该代码,vscode将在代码完成列表中显示成员的value

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM