1

Visual Studio 代码似乎对 javascript 自动完成有很好的支持,但我有一个项目使用 duktape 从我的应用程序中导出一个庞大且不断增长的对象库。

随着更多功能的导出,该库正在快速增长,我想知道是否有可能以某种方式导入或使 VS 代码的智能感知器了解一组“内置”对象。这些对象本身没有来源。它们通过 duktape 的 API 调用导出。我可以遍历全局对象空间并转储所有已知对象的名称并以任意方式打印它们。

我正在寻找一种方法来使全局对象转储(同样,它可以以任何格式工作)对智能感知或任何其他自动完成引擎有用。

4

1 回答 1

2

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>. 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:

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

The typings file also works for plain JS code, if you give vscode some hints via type annotations. 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.

于 2017-12-01T09:21:57.793 回答