

Tern – Intelligent JavaScript editing - aerique
http://ternjs.net/

======
shaunxcode
To be clear the author of this IS the author of code mirror! That should be in
large bold letters on that first page (it is on the crowd sourcing page). My
first thought was "really? this is just code mirror with added cleverness,
sort of lame to profit from it" - totally different story when it's the author
adding value to something he has already contributed to the community. In that
case this is the "premium" plan for code mirror.

~~~
marijn
Note that Tern's core is editor-independent. I made the demo on top of
CodeMirror, obviously, since I know it very well. But the meat of this project
does not have anything to with the editor that's used to interact with it.

~~~
robbrown451
Still, I wouldn't be shy about the fact that you did CodeMirror. It makes a
huge difference to me....you are a known quantity and convinces me that this
is a solid project.

And I'd think that CodeMirror is the obvious thing to hook this into, for the
rest of us as well.

------
kayoone
It might sound like an abomination, but Visual Studio is apart from obv. being
excellent in C++/C# also a very pleasant IDE for Javascript, Python or even
PHP!

In fact i have been an "texteditor-only" type in the past, but coding C# in
Visual Studio has really been a revelation for me.

~~~
marijn
I know. I was blown away by VS when I was researching what others were doing
in this space. Their approach is also very clever -- there's an interesting
talk about it at
[http://channel9.msdn.com/Events/TechEd/NorthAmerica/2012/DEV...](http://channel9.msdn.com/Events/TechEd/NorthAmerica/2012/DEV308)

~~~
gruseom
Care to mention what you found clever in their approach?

~~~
marijn
They basically _run_ the scripts, instrumenting their Chakra JS engine to
automatically abort overlong loops and overdeep recursion, and preventing all
side effects outside of the DOM/JS runtime. And then use the actual types that
occur in this run to do the completion. Plus, I guess, some added tricks that
the talk doesn't go into, but which are necessary to make sure execution
actually reaches the part of the program where you are trying to complete
something.

~~~
aerique
Does it ever get the types wrong? Just curious, I assume one wouldn't want to
see the kind of code where VS gets the types wrong.

~~~
marijn
I was able to create situations where it failed to find any type for a
variable, and when you have variables that may contain multiple types it
appears to only find one type, but I wasn't able to make it report any
actually _wrong_ types. (But I haven't used it very much.)

------
adlpz
Well, that looks _really_ nice. I am not a IDE type, but I do enjoy nice
coding helpers when I write. This, well integrated into say, Vim, would make
Javascript programming really comfortable.

~~~
thadk
The cloud9 ide's open source javascript-based editor,
[Ace](<http://ace.ajax.org/build/kitchen-sink.html>) can mimic vim mode.

Though ternjs's developer created CodeMirror, the platform would be agnostic
of editor and could easily be ported to that.

------
gruseom
Marijn Haverbeke has a stellar track record of work in this area, so this
should be taken more seriously than usual.

~~~
ibdknox
Just to lend some more credence to this statement, we (LightTable) have
actually contracted him to work on CodeMirror and have been nothing but happy
with the results. He runs a tight ship and the output is great. CodeMirror is
a fantastic editor (I say this as an ex PM on the Visual Studio editor) that
continues to get better every day, it has been invaluable to our work.

------
meryn
Looks cool! How do you gauge the difficulty of adding support for CoffeeScript
to this?

Re the indiegogo campaign: I think you should consider adding an extra
supporter tier between 25 USD and 1000 USD. The 200 USD tier of CoffeeScript
Redux [http://www.kickstarter.com/projects/michaelficarra/make-a-
be...](http://www.kickstarter.com/projects/michaelficarra/make-a-better-
coffeescript-compiler) brought in over 20% of the total amount pledged.

~~~
marijn
Interesting. Their 200 dollar tier is basically my 'all backers' tier (name in
a readme file). But I can probably come up with something slightly more
valuable to offer at ~250€.

As for CoffeeScript support -- the only major piece missing there is an error-
tolerant CoffeeScript parser. Given that, one could simply run the
CoffeeScript compiler over code, and analyze the output. There'd be some
shuffling with source maps needed to translate source locations in the various
representations of the code, but that's a solved problem. Well, and of course
you might see some translation artifacts. The CS output code is semantically
close to the input, but there are differences.

~~~
larve
a signed copy of your book? :}

~~~
aerique
I don't know Marijn's hourly rate, but perhaps one or two hours face-to-face
on Skype?

------
cromwellian
I find most of these attempts to code-completion in JS to be annoying, like
bad speech recognition, if the accuracy is poor, it becomes frustrating. Not
to knock their attempt, but I find that if codeassist isn't like 98% accurate,
it often becomes more work to step through all of the wrong entries and not
find what I want, then to just type it out.

The closest I've seen to something that works well is IntelliJ IDEA 12, when
working with ActionScript, Closure annotated JS (JsDoc'ed libraries), or by
comparison, the Dart editor.

With IntelliJ 12, if you're looking at a library with enough JsDoc on
functions, the type inferencing seems to be a lot more accurate. Find Usages,
Go to Definition, code-assist, all seem to be more pleasurable to use.

I don't like Flash, but ActionScript3 in IntelliJ is as close to the
Java/C#/et al experience you'll get with respect to accuracy of assist.
Probably wouldn't hard to port this over to JSX or Typescript which have
similar syntax.

~~~
marijn
If you're using completion to verify that a thing has the type you thought it
has, then yes, Tern won't help you much. If you're using it to save
keystrokes, it certainly will.

Slightly related, I'm working on a feature where it distinguishes wild guesses
from probably correct information by showing a different icon in the
completion list.

~~~
larve
I love autocompletion (even when it is half working, like intellij when the
inheritance marking annotations don't always follow through, my cleverly
optimized jsdoc markup for backbone and co broke down when switching to
idea12). It saves me so much time looking stuff up and APIs, and if it can
indicate the number and name of arguments required, i usually don't have to
use the docs anymore.

And M-./find usages is very useful too, even when it is not perfect.

I pledged, and hope you will get enough funds together.

------
vukmir
I think that anybody who works with JS should support this project and its
author (Marijn Haverbeke of the Eloquent JavaScript fame.)

P.S. Works fine on Chromium Version 24.0.1312.56 Ubuntu 12.04 x64

------
V1
Backed. Like everybody who touches JavaScript should do. Also. mmmm finally
decent vim bindings for javascript?

I do wonder how it will compare to Eclipse Orion's JavaScript content assist
which is using Esprima as parser.

[http://contraptionsforprogramming.blogspot.nl/2012/02/better...](http://contraptionsforprogramming.blogspot.nl/2012/02/better-
javascript-content-assist-in.html)

~~~
marijn
(I'm the author of Tern -- I'm obviously biased.)

It compares very favorably. The Orion approach, as I understand it (I only did
some quick messing around with scripted, am not an expert) is very local,
whereas Tern tries to do whole-program analysis. This should allow it to pick
up much more information.

~~~
visarga
Is it able to track all dependencies in a web page for autocomplete? I mean,
keywords defined in dependent files - do they automagically work?

~~~
marijn
Not magically. That part is, for now, in the scope of the IDE/editor plug-in.
You can feed Tern a set of files to analyze, but Tern doesn't, for example,
scrape HTML files to determine inclusions.

The one exception is requirejs-style dependencies. Those, if you give Tern
some information on where to look, it will resolve and automatically include.
I'll do something similar for node.js-style require calls in the future.

------
EzGraphs
IntelliJ's WebStorm has pretty JavaScript code completion and related tools.
It also has plugins for popular libraries and frameworks, node.js and a
variety of other HTML5 / latest-web-coolness stuff. Seems like a lot of folks
in the AngularJS community have been using it it as well.

Disclaimer: I liked it enough to buy a personal license :), but am not
affiliated with the folks who make and sell it.

------
ScottSauyet
Just contributed, as I'm intrigued. Have you seen Chris Granger's LightTable?
(<http://www.lighttable.com/>) I think there's some overlap, although his
vision is much broader.

~~~
bsimpson
Chris commented above that Marijn is working on LightTable.

~~~
marijn
Not on LightTable itself, but on the editor component they use
(<http://codemirror.net>)

------
serkanyersen
Backed, I really love to see this working on SublimeText. I tired it with my
own code and it managed to bring correct return types and object properties
from all functions. I hope you release it soon. Thanks for the effort

------
talmand
On my Mac (10.6.8), using Firefox 19.0 I get the right mouse contextual menu
when I use CTRL-SPACE in the first example with the Tern selections displaying
behind it. I don't see this behavior in Chrome or Safari.

------
bsimpson
Curious how this compares to Brackets. I haven't played with their latest
sprint yet, but they also seem to be working on adding auto-complete to JS in
CodeMirror.

------
dotmanish
I typed "[[[[" and the script became unresponsive (hung).

Repeated by reloading the page. Same result.

FireFox / MacOS.

~~~
marijn
That's bad. I'll look into it right away.

~~~
adlpz
Working fine on Chrome 24 on Linux/x64.

~~~
mimog
The browser tab hangs on Chromium 24.0.1312.56 on Kubuntu 12.10 (when typing
[[[[).

~~~
adlpz
Weird, I'm on almost the exact same version (24.0.1312.57) and it does nothing
when typing any number of '['. I have the branded version of Chrome, though,
but still, weird!

~~~
marijn
The problem is fixed now, so the fact that it works shouldn't come as a
surprise.

~~~
jokeofweek
The demo doesn't seem to work on Chrome 25.0.1364.152 m. I'm getting this
error whenever I try any of the shortcuts (or when I select a command from the
drop down):

Uncaught TypeError: Cannot set property 'curOrigin' of undefined
(infer.js:489)

Looks interesting though!

~~~
marijn
That was another quick update that broke things. I fixed it ~20 minutes after
I pushed it, but I guess you exactly hit the window where it was broken.

------
jakozaur
Amazing, but it could be even more awesome if you could provide API that could
be integrated with other editors.

~~~
marijn
As NuZZ noted, this is the plan. It is already written as a library with a
server-like architecture (you send requests and get JSON responses). The
vision is to wrap it in a stand-alone HTTP server shim that understands .tern-
project files that you can drop in your project directory, and then write
editor plug-ins that talk to this server (and automatically start it up if
it's not already running).

------
slajax
This is really great work. I'd love to see it for VIM.

~~~
MrUnderhill
Looks like VIM is one of his first priorities. From the indiegogo page:

> _The funding goal is computed to allow me to work for three months at about
> half the income I make with my usual consulting work. (The other half is
> made up in the satisfaction of building the thing I want to build.) In
> addition, I'll spend some of it to engage a Vim expert to help me build the
> Vim plug-in in a way that fits the culture for that editor._

Definitely chipping in.

------
antirez
"Tern is not currently open source. I'd like it to be, but I have to pay my
bills. So I'm running a crowd-funder where interested parties can pledge
money. If successful, Tern will be released under an MIT license."

Very odd model... take your code.

~~~
kayoone
Your development of Redis is sponsored by VMWare afaik (which is awesome and
so is redis), so whats wrong with crowd-sponsoring this guy ?

Sure it might be a trust issue, and it might be better to release the code
first and then ask for money, but as it looks this guy has a good reputation
in the community so i dont see too much of a problem.

~~~
antirez
I talk from a general point of view of my ideas, not as the Redis developer.
Anyway for 1 year I worked at Redis for free, and it was open source since day
0.

