Code Completion For JavaScript Libraries


JavaScript code completion only

This page is only about code completion for the JavaScript language. For code completion in other languages, please refer to the Language Tooling Introduction and the guide on Using Existing Language Tools.

Cloud9 uses Tern for code completion. Tern uses a combination of type inference and type signatures as the basis for completions. Using type signatures, the code completer can be extended to support custom libraries.

Tern type signatures

Tern type signatures use a JSON format as explained in the Tern manual. Below is an example:

  "!name": "mylibrary",
  "!define": {
    "point": {
      "x": "number",
      "y": "number"
  "MyConstructor": {
    "!type": "fn(arg: string)",
    "staticFunction": "fn() -> bool",
    "prototype": {
      "property": "[number]",
      "clone": "fn() -> +MyConstructor",
      "getPoint": "fn(i: number) -> point"
  "someOtherGlobal": "string"

To register new type signatures for libraries, use the language.tern plugin as follows:

var signature = require("text!plugins/mylang.language/mylibrary.sig");

tern.registerDef("mylibrary", signature, { enabled: true, hidden: false });

This adds a new signature based on the file mylibrary.sig and enables it by default for the current workspace.