简体   繁体   中英

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.

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. These objects have no source per-se. They're exported via duktape's API calls. 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> . 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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