Meteor and Ternjs

1,563 views
Skip to first unread message

Bondi French

unread,
Dec 3, 2013, 8:36:33 PM12/3/13
to meteo...@googlegroups.com
There is a great code-analysis engine called Tern (ternjs.net) created by Marijn Haverbeke, it enables intelligent Javascript editing and currently supports several editors like Emacs, Vim and Sublime.
Its functionalities really help quick coding:
  • Autocompletion on variables and properties
  • Function argument hints
  • Querying the type of an expression
  • Finding the definition of something
  • Automatic refactoring
I have no direct link with this project, and I am not experienced enough to build it on my own but thought it would be great if there was a Meteor plugin as there is already an experimental Angular one.

tern + Meteor would be a great combination to develop in javascript!!

Cheers

Adrian Lanning

unread,
Dec 4, 2013, 4:50:16 PM12/4/13
to meteo...@googlegroups.com
Thanks for the link.  I'm looking forward to trying Tern out with vim.  

What functionality would a tern-meteor plugin enable?

Bondi French

unread,
Dec 9, 2013, 6:05:44 AM12/9/13
to meteo...@googlegroups.com
I was thinking: auto completion, finding definitions, function arguments hinting relative to everything Meteor like for meteor.collection meteor. subscribe meteor.publish etc... could be useful as well as dependency management.
Regards


--
You received this message because you are subscribed to a topic in the Google Groups "meteor-talk" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/meteor-talk/b_yGWIqXl7Y/unsubscribe.
To unsubscribe from this group and all its topics, send an email to meteor-talk...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Slava Kim

unread,
Dec 9, 2013, 5:22:52 PM12/9/13
to meteo...@googlegroups.com
I am interested in this effort (TernJS + Meteor + vim). Last time I played with TernJS - it just kept eating RAM as crazy (probably because static analysis needs a lot of memory for a dynamic language as JS) and it was unusable.

Bondi, Adrian, please share your progress if you get anything to work. Alternatively, there is typescript and existing effort on Meteor definitions for typescript.

Bondi French

unread,
Dec 11, 2013, 8:33:59 PM12/11/13
to meteo...@googlegroups.com
I'm not that proficient in programming, more of a beginner in JS so was more suggesting a feature than proposing to be the lead on this.

Slava Kim

unread,
Dec 12, 2013, 4:26:35 AM12/12/13
to meteo...@googlegroups.com
I looked at Ternjs docs today a little bit, thought I would share something I found:

- you launch the ternjs server and use POST requests to communicate with it
- you can give ternjs server a path to the code base and it will try to analyze the code
- if you want to help the server (in case the code base too large or you want to teach it about some external environment not presented in the code base), you can give it type hints in special format (http://ternjs.net/doc/manual.html#typedef)
- to teach server how files relate to each other (as there are different environments with different rules) you load one of the plugins (https://github.com/marijnh/tern/tree/master/plugin) explaining the rules

Challenges I see:

1. teach Ternjs server about Meteor's functions

It can be done by taking existing efforts for Typescript definitions (https://github.com/borisyankov/DefinitelyTyped/tree/master/meteor) and converting them to the format Ternjs requires (http://ternjs.net/doc/manual.html#typedef).

It would suck if we had to maintain both type definitions, it may make sense to maintain only Typescript one and then run reusable script to convert it for Ternjs.

2. teach Ternjs server about Meteor's load order and packages

The require.js one is only 200 LOC (https://github.com/marijnh/tern/blob/master/plugin/requirejs.js), maybe it is not that hard, given you can port this logic directly from Meteor code (https://github.com/meteor/meteor/blob/devel/tools/files.js#L41). The problem is - load order may change over time, it might become more flexible or configurable by user's config or whatever, this API is not crystallized yet. Also, writing a plugin that takes into account all the stuff linker does (packages, exports, implications) is as hard as writing linker.

So yeah, this integration doesn't look straight forward - it is a project and it is work. Maybe someone JetBrains will build the Meteor support earlier :)

Slava Kim

unread,
Dec 12, 2013, 2:25:58 PM12/12/13
to meteo...@googlegroups.com

Another idea for 2 is to use Meteor's linked and compiled files from .build folders.

Slava Kim

unread,
Dec 23, 2013, 3:22:24 AM12/23/13
to meteo...@googlegroups.com
A short update:

TernJS has a tool for simple TypeScript to TernJS JSON conversion (/bin/from_ts). They didn't update typescript module dependency in a while but once you do that and adjust meteor.ts.d from https://github.com/borisyankov/DefinitelyTyped/tree/master/meteor you can easily get something. Still needs some work but the initial json can be found in this gist: https://gist.github.com/Slava/8093354. I am sure it can be improved in future as some features of TypeScript are not clearly represented in TernJS JSON definitions.

The code inference and completion remains the hard part. Looking at node.js plugin for Tern, it just registers a method on `require` - node's import statement. And then in that method plugin loads files to index on demand, so the load is top-down.

This approach wouldn't work with Meteor as we don't have explicit imports and everything is loaded in a specific order (which noone remembers) and linker does some closure wrappings and package exports pulling.
To unsubscribe from this group and all its topics, send an email to meteor-talk+unsubscribe@googlegroups.com.

Slava Kim

unread,
Jan 18, 2014, 4:15:08 AM1/18/14
to meteo...@googlegroups.com
Update:


supported features:

- each file is wrapped in a scope
- global variable are global project-wise
- interface definitions converted from meteor.ts.d

todo features or nice to have:

- correctly calculate package scope and their exports
- some auto-completion based on Templates names would be nice


How to install:

For general case: use meteor.js file as tern.js plugin

For Sublime Text 2/3 plugin called "sublime-tern":

- install Package Control (https://sublime.wbond.net/installation)
- install sublime-tern plugin (cmd+shift+p -> install package -> sublime-tern -> restart sublime)
- `cd` to Sublime Text packages directory (`~/Library/Application Support/Sublime Text 3/Packages` on Mac OS X) 
- `cd sublime-tern/ternjs/plugin`
- copy over meteor.js file here
- create a new sublime project, save it, add files
- edit project configuration (menu->project->edit project)
- edit the json file in this manner:

{
"folders":
[
           ... don't touch this part, leave it as it was ...
],
        // add this! ternjs object
"ternjs": {
"libs": ["browser", "underscore", "jquery"],
"plugins": {
"meteor": {}
}
}
}


Tell me how it goes, contributions are welcome.

Adrian Lanning

unread,
Jan 18, 2014, 2:24:57 PM1/18/14
to meteo...@googlegroups.com
Awesome!!

Wait, so video says Sublime only...   What's the word on vim support?

Slava Kim

unread,
Jan 18, 2014, 2:39:01 PM1/18/14
to meteo...@googlegroups.com

I didn't try vim yet, right now my vim setup has neoautocomple and I am thinking on how to pair it with vim.

James Wilson

unread,
Jan 18, 2014, 7:23:28 PM1/18/14
to meteo...@googlegroups.com
Since we're bringing up pet IDEs I vote for IntelliJ and LightTable support. :)


James Wilson


--
You received this message because you are subscribed to the Google Groups "meteor-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to meteor-talk...@googlegroups.com.

Slava Kim

unread,
Jan 18, 2014, 7:39:07 PM1/18/14
to meteo...@googlegroups.com

James, what do you mean by "pet ides"? We are not voting for ides in this thread, but rather pairing ternjs with editors.

Slava Kim

unread,
Jan 18, 2014, 9:47:06 PM1/18/14
to meteo...@googlegroups.com
Made it to the workable state in Vim, will post instructions later today.


James Wilson


To unsubscribe from this group and all its topics, send an email to meteor-talk+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "meteor-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to meteor-talk+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to a topic in the Google Groups "meteor-talk" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/meteor-talk/b_yGWIqXl7Y/unsubscribe.
To unsubscribe from this group and all its topics, send an email to meteor-talk+unsubscribe@googlegroups.com.

Slava Kim

unread,
Jan 18, 2014, 10:50:20 PM1/18/14
to meteo...@googlegroups.com
Vim and Tern and Meteor, youtube link: https://www.youtube.com/watch?v=TIE9ZOqlvFo

Shortly: it works perfectly if you follow tern_for_vim instructions. For project configuration: tell ternjs not to include .meteor files. Didn't test multi-files apps yet, my suspicion is: you would need to open all working files in vim buffers to tell tern what files you would like to be considered. 

Later, some hacking would be needed for tern_for_vim to open all js files from the current Meteor project.
Another interesting note is: we can actually display docs in vim, we might want some new process to parse Meteor docs instead of converting definitions from meteor.ts.d.

Jeroen Tiebout

unread,
Jan 19, 2014, 3:03:51 PM1/19/14
to meteo...@googlegroups.com
Hey Slava,

Thank you for the great work!
Autocompletion works fine in emacs as well.

> Didn't test multi-files apps yet, my suspicion is: you would need to open all working files in vim buffers to tell tern what files you would like to be considered. 

I found that adding all .js files to loadEagerly in the .tern-project works just fine.
Only strange thing is that the regular glob pattern one would use ("**/*.js") does not seem to work

{
"libs": ["browser", "underscore", "jquery"],
"dontLoad": [".meteor"],
"loadEagerly": ["*.js","*/*.js","*/*/*.js","*/*/*/*.js"],
"plugins": {
"meteor": {}
}
}

I've opened an issue here: https://github.com/marijnh/tern/issues/281.

Slava Kim

unread,
Jan 19, 2014, 3:13:09 PM1/19/14
to meteo...@googlegroups.com
Hi Jeroen,

nice to hear it worked for you. I tried adding `'loadEagerly': **/*.js` before and failed as you described. It didn't occur to me to open an issue, thank you for doing this!
My current issue is to parse docs and fix the definitions. One of the downsides of converting the meteor.ts.d (which made it possible btw): now if I type "Deps.autorun" it returns a `IMeteorComputationObject` but it would be much better if it returned a `Deps.Computation` for example.

I am exploring the ways we could generate definitions from Meteor codebase rather than fixing these little bugs by handes. 

Serkan Durusoy

unread,
Jan 19, 2014, 6:42:42 PM1/19/14
to meteo...@googlegroups.com
Hi Guys,

I read through this thread with great enthusiasm and appreciation. Smart autocompletion, code hinting and suggestions go a long way while learning and getting used to a new framework. I'm coming from a javaee world where my preferred ide was/is netbeans. In fact, I'm so used to it, I'm using it for meteor development.

Yet I find it bloated and *very* memory intensive.

Sublime and the likes look too boy-toy-ish.

Spending most of the day on a linux machine with multiple terminals open, I find its simplicity and power very attractive. Also, having seen a couple eventedmind.com videos, tmux+vim combo look like bliss!


Yet, I've done the vim-dive for programming more than a handful times and bounced back. The vim 0-60mph seems to be forever. And I believe I'm not alone in this. 

Would you guys be interested in compiling a quick how-to post, or better yet a video tutorial - couldn't resist the temptation to push my luck here :) - for setting up and getting off the ground on vim (+tmux/screen for a wider audience perhaps) Meteor development with autocompletion, hinting, linting, highlighting, matching braces/brackets etc?

Cheers,
Serkan


Serkan Durusoy [DNA | encoding the future]

unread,
Jan 20, 2014, 4:32:04 AM1/20/14
to meteo...@googlegroups.com
for anyone reading this thread coming from a webstorm keyword search, abigail watson's meteor cookbook has some great resources on setting up webstrom for meteor development.

Sent from my iPhone



On Jan 20, 2014, at 2:28, Slava Kim <sl...@meteor.com> wrote:


Hey Serkan,

switching to Vim/Emacs and setting up your environment which is comfortable and getting used to it is a lifetime process and I haven't seen anyone being 100% satisfied with his/her set up.

But you know, my teachers tended to say "Calisman kazanir, calismayan hic kalir", so it will happen only when you commit yourself to this process and your final result would probably differ from anything other people show you.

Until then, consider using WebStorm - it's a 1st class IDE written in Java (w/o Meteor support unfortunately but there is a ticket: http://youtrack.jetbrains.com/issue/WEB-6264). WebStorm supports autocompetion, some smartness and debugger.

Gadi Cohen

unread,
Jan 20, 2014, 9:00:28 AM1/20/14
to meteo...@googlegroups.com
Slava, this is super awesome!  Especially loved the videos, great way to demo all the features and close the sale :>

I've updated the following Meteorpedia pages to reflect your progress:


The videos were embedded in the latter two pages, along with installation instructions and a download link to the raw meteor.js contents from master branch.

Many thanks!

Gadi

Slava Kim

unread,
Jan 31, 2014, 5:11:46 AM1/31/14
to meteo...@googlegroups.com
Today I had a chance to present this work on Meteor Devshop in a form of lightning talk. There is a big chance you will not understand a lot of the words I am saying in the video, but there is a good chance you can read my slides w/o any problems: http://slid.es/slavakim/meteor

I also updated the readme file to link to the talk, slides and cool gifs :)

On today's devshop Bo Zhao Yu of EventedMind showed me that "Jump to definition" actually works well and later I discovered, a "Jump to Reference" works too :). He also had an idea in mind of bringing IronRouter definitions to the projects which would be sweet. Hopefully, once the packages support will be figured out, it would be easy to generate definitions for your packages.

Cheers :)

p.s.
Gadi, thanks for those updates on Meteorpedia!

Arunoda Susiripala

unread,
Jan 31, 2014, 5:27:20 AM1/31/14
to meteo...@googlegroups.com
Just watched it. Very nice.

Not much depends on auto completion, but this is something must to have :)


--
You received this message because you are subscribed to the Google Groups "meteor-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to meteor-talk...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

Bondi French

unread,
Feb 3, 2014, 12:33:59 AM2/3/14
to meteo...@googlegroups.com
Slava, this is awesome! You did an impressive job!
I never expected that my little comment on the Meteor GoogleGroup would trigger this!

Well done!! 
I wish my level of programming was higher so I could contribute further.

Cheers

Pieter Soudan

unread,
Feb 3, 2014, 2:44:44 PM2/3/14
to meteo...@googlegroups.com
Thanks a lot! This is great!

Gagi Vosk

unread,
May 9, 2014, 7:08:56 AM5/9/14
to meteo...@googlegroups.com
Can't make your ternjs meteor extention work in vim spf13 please help me with that...

Angelo zerr

unread,
May 9, 2014, 8:34:40 AM5/9/14
to meteo...@googlegroups.com
Hi,

If you are Eclipse user, I have integrated the meteor tern plugin of Slava in Tern IDE (which uses tern inside Eclipse IDE). You can see wiki at https://github.com/angelozerr/tern.java/wiki/Tern-&-Meteor-support

Many thank's Slava for your work!

Regards Angelo

Slava Kim

unread,
May 9, 2014, 2:42:41 PM5/9/14
to meteo...@googlegroups.com
Hi Gagi,

I don't know what is vim spf13, but you do need to have a vim build with +python support. You can check it running `:version` in your vim and looking for either `-python` or `+python`. '+' means good, '-' means bad.

Slava Kim

unread,
May 9, 2014, 2:43:25 PM5/9/14
to meteo...@googlegroups.com
Thanks Angelo for porting it to Eclipse. Although the defs are not up to date, they still get 90% of API correct.

Gagi Vosk

unread,
May 10, 2014, 3:48:27 AM5/10/14
to meteo...@googlegroups.com
Thanks, for the fast reply and huge thanks to Angelo for porting it to eclipse, I had used eclipse all the time until now, I will give it a go if vim won't work for me,
I like Vim way more then eclipse only because it's blazingly fast and has really cool short-cuts to do a lot of useful stuff.

Back to Slava, here is link to vim spf13 project for to know what am I talking about:
https://github.com/spf13/spf13-vim
It's suppose to be the best tweaked vim for web development,with lots of handy bundles(some of which are yours :) ).

I think that the problem is that some bundle is overlaping tern_for_vim bundle and and that's why it won't work,
I am really new to vim (and Meteor) and that's why I may be way off... and I don't know how to check it out without breaking it.
Otherwise I'll get back to eclipse thanks to Angelo.

so please Slava if you have time and the mood to help me out find out what is the reason for it I will really appreciate it.

best of luck, cheers.

Angelo zerr

unread,
May 10, 2014, 9:29:34 AM5/10/14
to meteo...@googlegroups.com
2014-05-09 20:43 GMT+02:00 Slava Kim <sl...@meteor.com>:
Thanks Angelo for porting it to Eclipse.

You are welcome, thank's for your work!
 
Although the defs are not up to date, they still get 90% of API correct.

IMHO, I think your issue https://github.com/Slava/tern-meteor/issues/1 should be fixed, because I find it's really shame that there is no documentation.
 

--
You received this message because you are subscribed to a topic in the Google Groups "meteor-talk" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/meteor-talk/b_yGWIqXl7Y/unsubscribe.
To unsubscribe from this group and all its topics, send an email to meteor-talk...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Angelo zerr

unread,
May 10, 2014, 9:32:44 AM5/10/14
to meteo...@googlegroups.com
2014-05-10 9:48 GMT+02:00 Gagi Vosk <gagi...@gmail.com>:
Thanks, for the fast reply and huge thanks to Angelo for porting it to eclipse,

Since tern.java exists, it was very easy to integrate tern meteor. To install tern ide, please read https://github.com/angelozerr/tern.java/wiki/Installation-Update-Site and install the snaphot version.

I don't know meteor, but it seems that there is HTML templates too, and I think Eclipse plugin should exists to provide syntax coloration, completion inside EL like I have done for angularjs eclipse https://github.com/angelozerr/angularjs-eclipse which is based on tern.js too. If some people are interested to do the same thing for meteor, don't hesitate to contact me.

Regards Angelo
 

--
Message has been deleted

Gagi Vosk

unread,
May 17, 2014, 11:42:11 AM5/17/14
to meteo...@googlegroups.com
So , Slava will you consider to help with vim spf13 ? I have yet been able to fix the problem.

Slava Kim

unread,
May 17, 2014, 3:52:56 PM5/17/14
to meteo...@googlegroups.com
Gagi,

look at my answer above: either you don't have python support in your vim, or you didn't follow all the instructions for installation (for example, don't have node.js or forgot to run `npm install` inside plugin's directory) or as you said, something conflicts in vim spf13, here you would need to figure it out w/o me.


On Sat, May 17, 2014 at 8:42 AM, Gagi Vosk <gagi...@gmail.com> wrote:
So , Slava will you consider to help with vim spf13 ? I have yet been able to fix the problem.

--

Slava Kim

unread,
Nov 2, 2014, 7:14:25 AM11/2/14
to meteo...@googlegroups.com
Good news, everyone!

Today I updated the plugin to Meteor 1.0 API. Now it is generated from JSDoc definitions that Meteor started using around version 0.9.3 (great work by Sashko Stubailo, MDG Core Dev).
I tested the new plugin on my Vim, it would be great to get more feedback from other people using this plugin (if there are any?).


Cheers,
Slava
To unsubscribe from this group and all its topics, send an email to meteor-talk+unsubscribe@googlegroups.com.

Serkan Durusoy [DNA]

unread,
Nov 2, 2014, 12:12:27 PM11/2/14
to meteo...@googlegroups.com
Is this somehow applicable to the Atom editor? I see that there already are a few attempts at Atom/Tern integration @ https://atom.io/packages/search?q=tern so could we just extend that to support Meteor?
To unsubscribe from this group and all its topics, send an email to meteor-talk...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages