Skip to content

JavaScript Code Intelligence Investigation

eztierney edited this page Apr 8, 2013 · 14 revisions

Tern.JS Integration

The JavaScript Code Intelligence extension is implemented as a Brackets code hinting extension. For hinting, it relies on the TernJS Library.

The extension manages an instance of the Tern server, which runs in a web-worker, and makes requests to it whenever it needs information to calculate hints. The information requested includes function types, types of the base of a member expression, and potential property or identifier names. The extension caches most of the information it requests so that it does not need to continuously requery tern during the same code hinting session.

When the extension starts up, it reads in some .json files that provide type information for the environment. Currently it reads in ecma5.json, which contains type info for the javascript builtins, and browser.json, which provides type information for the methods that the browser exposes. These files are only parsed once, as they should never change. When the tern server is initialized, the environment built from those files is passed to tern to initialize its environment. To support different modes of development (e.g. editing a node.js file vs. a browser based file) we could supply tern with different environments to get the most appropriate hints.

The hints are calculated based on the files in the current directory, and on the calls to requirejs seen in the file. Requirejs is not supported yet, but will be added shortly as understanding requirejs modules provides rich type information that can be used for hinting.

API Proposals and Guesses

Go-To-Definition (of current identifier)

Clone this wiki locally