14 ms·
Tern – Intelligent JavaScript editing
- dotmanish 14y agoI typed "[[[[" and the script became unresponsive (hung). Repeated by reloading the page. Same result. FireFox / MacOS.
- marijn 14y agoThat's bad. I'll look into it right away.
- adlpz 14y agoWorking fine on Chrome 24 on Linux/x64.
- mimog 14y agoThe browser tab hangs on Chromium 24.0.1312.56 on Kubuntu 12.10 (when typing [[[[).
- adlpz 14y agoWeird, 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 14y agoThe problem is fixed now, so the fact that it works shouldn't come as a surprise.
- jokeofweek 14y agoThe 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 14y agoThat 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.
- deleted 14y ago[deleted]
- marijn 14y agoShould be better now. It was a change I made half an hour ago. Ad-hoc changes to sites that are receiving traffic always do that. [You'll need to hard-refresh to get the fixed code.]
- adlpz 14y agoWell, 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.
- 3ds 14y agoupvote for vim bindings, that would totally rock!
- thadk 14y agoThe cloud9 ide's open source javascript-based editor, [Ace](http://ace.ajax.org/build/kitchen-sink.html 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.
- jakozaur 14y agoAmazing, but it could be even more awesome if you could provide API that could be integrated with other editors.
- NuZZ 14y ago> But that is a proprietary system tied to a single IDE. If the crowd-funding succeeds, Tern will be an open system that can (and will) be plugged into a variety of editors and IDEs. Hopefully, that will happen. Sounds very cool though, as my IDE, sublime text, is rather underpowered in the intelligence department I'm afraid. I could imagine it applying .tmLanguage scopes to words in the document, where you could colorize different variables according to type (I would opt for different background shades, myself). Then, mixed type colors (prompting you to click it and see what Tern says) when you can't know. Damn, that would be helpful.
- marijn 14y agoAs 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).
- V1 14y agoBacked. 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-javascript-content-assist-in.html http://contraptionsforprogramming.blogspot.nl/2012/02/better...
- marijn 14y ago(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 14y agoIs it able to track all dependencies in a web page for autocomplete? I mean, keywords defined in dependent files - do they automagically work?
- marijn 14y agoNot 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.
- gngeal 14y ago"whereas Tern tries to do whole-program analysis." I suppose you're not doing live type feedback? Given a test suite for the code being edited, that would seem like a natural thing to do.
- cromwellian 14y agoI 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 14y agoIf 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.
- visarga 14y agoAnother way to go about it would be to mark the keywords that seem mistyped or auto-correct them. That would be less intrusive for people who don't want to select from drop downs.
- larve 14y agoI 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.
- deleted 14y ago[deleted]
- kayoone 14y agoIt 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 14y agoI 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/DEV308 http://channel9.msdn.com/Events/TechEd/NorthAmerica/2012/DEV...
- gruseom 14y agoCare to mention what you found clever in their approach?
- marijn 14y agoThey 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 14y agoDoes 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 14y agoI 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.)
- vukmir 14y agoI 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
- meryn 14y agoLooks 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-better-coffeescript-compiler http://www.kickstarter.com/projects/michaelficarra/make-a-be... brought in over 20% of the total amount pledged.
- marijn 14y agoInteresting. 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.
- antirez 14y ago"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.
- marijn 14y agoWhat do you mean?
- antirez 14y agoI mean that from my point of view "gimme money if you want that open sourced" is very bad approach. Either build your closed source business, or try to earn from an open source product to pay the bills. 1) What is the current state of the source code? It could be a mess. 2) The value of open source is mostly in continued developments, support, community, not just in releasing the code itself. 3) If you have this mindset, who guarantees me that tomorrow you'll write plugins that are closed and ask again for money to release?
- marijn 14y agoAs for trust, the JavaScript community knows me as the maintainer of CodeMirror, and apparently likes the way I'm handling that project. This seems to lead people to believe that I won't deliver a horrible mess, and that I won't try to rip them off after the fact. Starting up a project with a crowd funding does not make it impossible to later fund continued maintenance by selling support and such. It is a way in which I'm safeguarding my initial investment. In short, I still fail to see the problem.
- EzGraphs 14y agoIntelliJ'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 14y agoJust contributed, as I'm intrigued. Have you seen Chris Granger's LightTable? (http://www.lighttable.com/ http://www.lighttable.com/) I think there's some overlap, although his vision is much broader.
- serkanyersen 14y agoBacked, 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 14y agoOn 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.
- gruseom 14y agoMarijn Haverbeke has a stellar track record of work in this area, so this should be taken more seriously than usual.
- ibdknox 14y agoJust 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.
- shaunxcode 14y agoTo 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 14y agoNote 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 14y agoStill, 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.
- mishoo 14y agoThat "added cleverness" is a big story in itself. Linking it with an editor is trivial. If you never tried to do static analysis on a dynamic language like JS you can't really appreciate just how smart Tern is (or wants to be).
- slajax 14y agoThis is really great work. I'd love to see it for VIM.
- MrUnderhill 14y agoLooks 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.
- bsimpson 14y agoCurious 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.