Thanks to Emmet for releasing the “Sublime Tern” package. It implements TernJS into Sublime Text.
“TernJS is a JavaScript type inference engine written by Marijn Haverbeke. It analyses your JS code on-the-fly and provides autocompletion, function argument hints, jump-to-definition, and various automatic refactoring operations.”
I like stuff that “just works”, but since this package is pretty new it lacks a bit of documentation and Q&A.
I did also try the newly released official “TernJS for Sublime” package but that just became complicated compared to Emmet’s version and seemed to slow the editor way the heck down. So I uninstalled that rather quickly. I’m sure it’ll become much better as time goes on.
If you take a look at the TernJS Demo, you’ll see right away that using Ctrl-Space after the characters “co” will auto-complete to “console” or “confirm”. This is something I expected to “just happen” in the Sublime Tern package. But to my horror, it appeared that it just didn’t work.
After some discussion in GitHub, I finally figured out that you have to add some libraries into the project settings, which is kind of annoying. But I did just see that they released a new update to GitHub just now that will accept defaults for library loading which will be quite nice.
But basically here’s the answer to solve what appeared to be “broken” to me. Add this config object to your sublime-project file (Project > Edit Project):
"ternjs": { "libs": ["browser"] }
But I almost always use jQuery so I also added that:
"ternjs": { "libs": ["browser", "jquery"] }
Now I see the auto-completion options I was looking for.
If you program in JavaScript I highly recommend installed one of the two TernJS packages.
The reason I looked so deeply into this was because Adobe’s Brackets implemented it and it was touted as a great feature to have!