[plugin] TernJS for Light Table (autocomplete, inline docs, and jump-to-definition for JS)

1,100 views
Skip to first unread message

Eric Pritchett

unread,
Feb 22, 2014, 6:17:20 PM2/22/14
to light-table...@googlegroups.com
Release: 0.0.1

I've been working on getting Light Table's support for JavaScript up to a similar level as Clojure/ClojureScript. Chris Granger and I plan to merge this plugin with the current JavaScript one, but I'd like to workout the kinks first. Including this subset of functionality as a plugin means I can get feedback from the community and iterate quickly to get fixes pushed out. 

I don't have an OSX box to test on, so feedback about how well it works on that OS would be appreciated.

Notes:
* Startup time for the server can be negligible or it can take a noticeable amount of time before results start coming back. After the initial startup, you shouldn't notice anymore lag.
* I've included a command to reset the TernJS server in case things get in a weird state.

You can find the repo here, let me know what you think :)

Josh Cole

unread,
Feb 24, 2014, 5:07:37 PM2/24/14
to light-table...@googlegroups.com
Looks exciting, can't wait to see how it works!

Josh Cole

unread,
Feb 24, 2014, 6:53:44 PM2/24/14
to light-table...@googlegroups.com
Unfortunately, I'm getting death by recursion on trying to interact with tern at all in JS:

  • "Invalid behavior: :lt.plugins.tern/start-server"
  • RangeError: Maximum call stack size exceeded
        at cljs.core.LazySeq.sval (file:///Users/jcole/repos/external/LightTable/deploy/core/node_modules/lighttable/bootstrap.js:5560:44)
        at cljs.core.LazySeq.cljs$core$ISeqable$_seq$arity$1 (file:///Users/jcole/repos/external/LightTable/deploy/core/node_modules/lighttable/bootstrap.js:5571:8)
        at cljs.core._seq (file:///Users/jcole/repos/external/LightTable/deploy/core/node_modules/lighttable/bootstrap.js:2311:14)
        at cljs.core.seq (file:///Users/jcole/repos/external/LightTable/deploy/core/node_modules/lighttable/bootstrap.js:2824:27)
        at eval (file:///Users/jcole/repos/external/LightTable/deploy/core/node_modules/lighttable/bootstrap.js:5966:29)
        at cljs.core.LazySeq.sval (file:///Users/jcole/repos/external/LightTable/deploy/core/node_modules/lighttable/bootstrap.js:5561:40)
        at cljs.core.LazySeq.cljs$core$ISeqable$_seq$arity$1 (file:///Users/jcole/repos/external/LightTable/deploy/core/node_modules/lighttable/bootstrap.js:5571:8)
        at cljs.core._seq (file:///Users/jcole/repos/external/LightTable/deploy/core/node_modules/lighttable/bootstrap.js:2311:14)
        at cljs.core.seq (file:///Users/jcole/repos/external/LightTable/deploy/core/node_modules/lighttable/bootstrap.js:2824:27)
        at eval (file:///Users/jcole/repos/external/LightTable/deploy/core/node_modules/lighttable/bootstrap.js:5966:29)

Happy to provide any other debugging information you'd find useful in figuring out why it can't connect to tern.

Josh Cole

unread,
Feb 24, 2014, 7:19:17 PM2/24/14
to light-table...@googlegroups.com
Okay, I really wanted to use the plugin, so I did some debugging and got to the root of the issue --

::start-server calls (all-js-files ws) which breaks on certain complex workspaces. My best guess right now is that it's breaking due to symlinks from depth 2 to depth 0 (./<project>/node_modules/<company_library> to ./<company_library>). Notably, this isn't a cyclic link and I'm not sure why it would cause us to bust the call stack, but I'm a bit tired of changing a variable, waiting 45 seconds for my editor to unfreeze, and then inspecting the result to continue pecking at it right now.

I'd definitely experiment with the FS vagaries people might get into to try and make all-js-files more robust.

Cheers,
Josh

Josh Cole

unread,
Feb 24, 2014, 7:37:25 PM2/24/14
to light-table...@googlegroups.com
Another addendum: I can actually reproduce the busted call stack with a much smaller workspace that contains no symlinks. Of course, smaller in this case is a still rather large:


Any large node project tends to have a lot of dependencies, which in turn have many dependencies, and so on until the number of files is preposterous. I don't know of a good way to filter those out of the workspace, and even if I did I would then be losing a lot of meaningful context (80% of the time I would prefer documentation on the modules I'm using rather than my team's code). It might be worthwhile to try and implement lazy file addition -- just add the immediate node_modules for the project and only add their dependencies if you open an editor into one of their files.

More generally, it would be excellent if you could lazily load files into tern based on a dependency graph from opened files -- you'll never want or need documentation or source locations for things which aren't referenced in the files that are immediately open. I'd also recommend offloading the process of adding files into a separate task to improve the latency issue (and spare me the 45 second wait for file addition to crash :P ). 

All in all, excellent work for a beta, really looking forward to seeing this mature. Tern and Light Table together is a wonderful thing.

Cheers,
Josh

Eric Pritchett

unread,
Feb 24, 2014, 9:50:11 PM2/24/14
to light-table...@googlegroups.com
Thanks so much for checking out the plugin! I really appreciate you taking the time to debug issue, this is the kind of feedback I was hoping to see.

I often forget that node brings in a massive amount of JavaScript files for some projects and locking up the editor for 45 seconds to handle that is unacceptable. I've got a few ideas on how to approach the issue, so I'll be working on it this week. I'll make a github issue with some of my ideas in case anyone with enough free time wants to jump on it before I get around to it.

Once again, thank you for the feedback! We'll get this issue cleared up right away.

Eric Pritchett

unread,
Feb 24, 2014, 10:15:35 PM2/24/14
to light-table...@googlegroups.com
Can you provide a sample project that recreates the problem or a least the node dependencies you are using? A work around for now maybe to add only the folders and files you care about to the workspace, and make sure to exclude the node_modules directory. Tern's nodejs plugin seems to be smart enough to understand how to load dependencies lazily without help from Light Table.

On Monday, February 24, 2014 6:37:25 PM UTC-6, Josh Cole wrote:

Eric Pritchett

unread,
Feb 24, 2014, 10:35:11 PM2/24/14
to light-table...@googlegroups.com
Forgot to add, I've made an issue for this on github here. Please post any future comments or pertinent information there.

Josh Cole

unread,
Feb 24, 2014, 10:57:41 PM2/24/14
to light-table...@googlegroups.com
I'll move the debugging conversation there then,

cheers,
Josh

Eric Pritchett

unread,
Mar 8, 2014, 1:24:58 AM3/8/14
to light-table...@googlegroups.com
Release: 0.1.2

Changes:
  • FIX: Workspace files are now loaded asynchronously
  • FIX: Changes to large files send partial file requests
  • ADDED: Libs can now be loaded via behaviors
  • ADDED: Plugins can now be loaded via behaviors
Light table should no longer lag when the Tern server is starting up. You can also perform basic configuration of the server! Whoohoo! Apparently loading all plugins and libs really messes things up for the browser environment.

The change log only shows up to version 0.1.0 but it is still current as far as actual features and changes. That's because I am still figuring out this whole versioning thing and had to make 2 more releases while trying to remember to update all the required files. Naturally I still failed to update all the files, even when I had a checklist xD.

Please let me know if you run into any issues.

Eric Pritchett

unread,
May 2, 2014, 11:01:53 PM5/2/14
to light-table...@googlegroups.com
Anouncing the next significant release of the TernJS plugin! I want to thank all those that have been using the plugin and have provided feedback; knowing that even one person is made more productive by this plugin drives me to continue development.

Overall this particular release should bring a lot of stability to the plugin.  Lazy loading of AMD dependencies is now fully supported (there was a sneaky bug I had to track down), so your RequireJS projects should be pleasant to work in now. You can check the README for details on setting up your workspace behaviors for RequireJS.

Once again, thank you to everyone for the awesome feedback! Keep it coming.

Changes:

0.1.6

  • FIX: Formatting of JSDocs
  • ADD: Support for lazy loading of AMD js files
  • ADD: Minimal support for lazy loading of files in general
  • FIX: Node process going to 100% CPU when loading many JS files
  • FIX: TernJS plugin not working with transient JS editor
  • FIX: Node process lives on past shutdown of Light Table

0.1.5

  • FIX: Upstream issue regarding optional comments
  • ADD: Refresh configuration after disconnection from server

0.1.4

  • FIX: Incorrect plugin dependency name (azmr)

0.1.3

  • FIX: Unterminated comments fill console with errors
  • ADDED: User notified if critical executable script cannot be found


TP

unread,
May 3, 2014, 12:43:28 AM5/3/14
to light-table...@googlegroups.com
On Fri, May 2, 2014 at 8:01 PM, Eric Pritchett <eric.a.pri...@gmail.com> wrote:
Anouncing the next significant release of the TernJS plugin! I want to thank all those that have been using the plugin and have provided feedback; knowing that even one person is made more productive by this plugin drives me to continue development.


You need to get the Tern people to put a link to https://github.com/mortalapeman/LT-TernJS in their "Editor plugins" section at http://ternjs.net/ :)

Eric Pritchett

unread,
May 3, 2014, 12:58:41 AM5/3/14
to light-table...@googlegroups.com
Good point, I'll make a topic on their dev mailing list.

Eric Pritchett

unread,
Jun 7, 2014, 6:40:07 PM6/7/14
to light-table...@googlegroups.com
Announcing TernJS 0.1.8! The update to Tern 0.6.2 is the real meat of this version. It also includes a few minor bug fixes and spelling changes, but other than that not too much has changed. As always, let me know if you run into any issues and we'll get them sorted out as soon as possible!


0.1.8

  • FIX: Correctly initialize Tern when workspace is empty
  • MOD: Update to Tern 0.6.2

0.1.7

  • FIX: Correctly handle nil doc string
  • FIX: Allow other plugins to extend auto-complete in concert with TernJS

Eric Pritchett

unread,
Jun 8, 2014, 4:19:20 AM6/8/14
to light-table...@googlegroups.com
So it appears that dependency loading for the Tern nodejs plugin is currently broken in 0.6.2. If you want to use the Light Table plugin and need node support, hold off on upgrading until I can get a work around added. I had done some simple node dependency testing, but it apparently wasn't enough.

Eric Pritchett

unread,
Jun 8, 2014, 11:20:08 PM6/8/14
to light-table...@googlegroups.com
Release 0.1.9 has reverted the upgrade to tern 0.6.2 for now. I'll need more time than I have available to track down the cause of the bug on tern's side.
Reply all
Reply to author
Forward
0 new messages