{"_id":"56a8dd2470a9440d00ef5fe4","user":"54d5c32a7e05890d006f150d","version":{"_id":"54d5635532d98b0d00384afb","project":"54d53c7b23010a0d001aca0c","__v":10,"forked_from":"54d53c7c23010a0d001aca0f","createdAt":"2015-02-07T00:59:01.934Z","releaseDate":"2015-02-07T00:59:01.934Z","categories":["54d5635632d98b0d00384afc","54d5635632d98b0d00384afd","54d5635632d98b0d00384afe","54d5635632d98b0d00384aff","54d5635632d98b0d00384b00","54d5635632d98b0d00384b01","54d5635632d98b0d00384b02","54d652097e05890d006f153e","54dd1315ca1e5219007e9daa","54e21e2b22de1c230094b147","54e68e62a43fe13500db3879","54fa1d3fe7a0ba2f00306309","551c453a23a1ee190034d19a","551df586e52a0b23000c62b6","551f39be6886f8230055f02a","55a6720751457325000e4d97"],"is_deprecated":false,"is_hidden":false,"is_beta":true,"is_stable":true,"codename":"","version_clean":"0.1.0","version":"0.1"},"__v":3,"category":{"_id":"54d5635632d98b0d00384b01","version":"54d5635532d98b0d00384afb","project":"54d53c7b23010a0d001aca0c","pages":["54d5635732d98b0d00384b10","54d5635732d98b0d00384b11","55104b632dd9010d0019e144","55104c802dd9010d0019e146","551bd2c50d209f21006cad92","552e6fcd5d4baa0d00783691","552e73705d4baa0d00783699","567be431ee052b1700dbda49","567ef29af9ffa20d008782ff","56a8dd2470a9440d00ef5fe4"],"__v":9,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-02-07T00:03:52.618Z","from_sync":false,"order":11,"slug":"language-tooling","title":"Language Tooling"},"parentDoc":null,"project":"54d53c7b23010a0d001aca0c","updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-01-27T15:07:16.573Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"settings":"","results":{"codes":[]},"auth":"required","params":[],"url":""},"isReference":false,"order":5,"body":"[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"JavaScript code completion only\",\n  \"body\": \"This page is only about code completion for the JavaScript language. For code completion in other languages, please refer to the [Language Tooling Introduction](doc:language-tooling) and the guide on [Using Existing Language Tools](doc:existing-tools).\"\n}\n[/block]\nCloud9 uses [Tern](http://ternjs.net/) 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.\n\n\n\n# Tern type signatures\n\nTern type signatures use a JSON format as explained in [the Tern manual](http://ternjs.net/doc/manual.html#typedef). Below is an example:\n\n```\n{\n  \"!name\": \"mylibrary\",\n  \"!define\": {\n    \"point\": {\n      \"x\": \"number\",\n      \"y\": \"number\"\n    }\n  },\n  \"MyConstructor\": {\n    \"!type\": \"fn(arg: string)\",\n    \"staticFunction\": \"fn() -> bool\",\n    \"prototype\": {\n      \"property\": \"[number]\",\n      \"clone\": \"fn() -> +MyConstructor\",\n      \"getPoint\": \"fn(i: number) -> point\"\n    }\n  },\n  \"someOtherGlobal\": \"string\"\n}\n```\n\nTo register new type signatures for libraries, use the [`language.tern`](https://github.com/c9/c9.ide.language.javascript.tern/blob/430142144976781548450295180998d74ce47e2f/tern.js#L179) plugin as follows:\n\n```javascript\nvar signature = require(\"text!plugins/mylang.language/mylibrary.sig\");\n\ntern.registerDef(\"mylibrary\", signature, { enabled: true, hidden: false });\n```\n\nThis adds a new signature based on the file `mylibrary.sig` and enables it by default for the current workspace.","excerpt":"","slug":"code-completion-for-javascript","type":"basic","title":"Code Completion For JavaScript Libraries"}

Code Completion For JavaScript Libraries


[block:callout] { "type": "info", "title": "JavaScript code completion only", "body": "This page is only about code completion for the JavaScript language. For code completion in other languages, please refer to the [Language Tooling Introduction](doc:language-tooling) and the guide on [Using Existing Language Tools](doc:existing-tools)." } [/block] Cloud9 uses [Tern](http://ternjs.net/) 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](http://ternjs.net/doc/manual.html#typedef). 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`](https://github.com/c9/c9.ide.language.javascript.tern/blob/430142144976781548450295180998d74ce47e2f/tern.js#L179) plugin as follows: ```javascript 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.