What is ternjs?
Tern is an indiegogo backed project
that “…is a stand-alone, editor-independent JavaScript analyzer that can be used to improve the
JavaScript integration of existing editors.”1
In a nutshell, it analyses your code and provides auto-completion, hints, documentation and more. Even better is that
it is editor-independent so it can fit in with the way you work.
If you want more details follow the links above. In this post we will look at getting it working with Titanium.
Installation
See the tern documentation for the how to set it up for your favourite editor. There are
links for vim, sublime, emacs and brackets. (For those using vim see this guide
to set it up with YouCompleteMe and this stackoverflow question
if you want it all to play nice with UltiSnips.)
titanium.json
Recently @x-cray wrote a perl script to generate the Tern definition file for Titanium from the Appcelerator API documentation
files. Clone the repo if you want to generate the definition file yourself.
Alternatively, here is one I just generated using the script against master branch (2014-01-02) – titanium.json.
You can either copy the file to your project root or to the defs/
folder in the tern install directory.
After that you need to add a .tern-project
definition file to your project. Here is one example for a classic project:
{ "libs": [ "titanium", "underscore", "ecma5" ], "plugins": { "requirejs": { "baseURL": "./Resources", "paths": {} } } }
After that you are good to go.
Here are some examples of what you see (using vim):
Comments
Fokke Zandbergen
For documentation lookup I use Dash (http://kapeli.com/dash) with the DashDoc Sublime Text plugin (https://github.com/farcaller/DashDoc). Very fast and offline as well.
David, I got the code completion working with Tern but have 2 questions:
1) Is there a way I can enable it for all project instead of always having to add a .tern-project file?
2) It always shows a single `fn` as argument for the methods suggested?
Pascal Achard
Hi,
works great with Titanium!
It seems like it doesn’t works with Alloy. ( ex: Alloy.createCollection() ). Is it possible to get the Alloy auto-completion ?