How do you debug your plugins for tern?

558 views
Skip to first unread message

Slava Kim

unread,
Feb 1, 2014, 8:34:34 PM2/1/14
to tern...@googlegroups.com
Hey everyone, new to TernJS.

Currently I am experimenting with a plugin for Meteor (meteor.com) for TernJS. It is extremely hard to understand what is called when and none of console.log's I set are visible in the editor I use (vim).

How can one see the output of console.log's with Tern? How do you debug issues with plugins? Any help is appreciated.

Slava

Angelo zerr

unread,
Feb 2, 2014, 9:42:08 AM2/2/14
to Slava Kim, tern-dev
Hi Slava,

In my case I'm integrating Tern with Eclipse IDE. Even if http://ternjs.net/doc/manual.html is very well documented, I think it's hard to know which JSON request/response must be done to comunicate with Tern server.
So to understand how tern works, I have debugged it with Chrome by using the CodeMirror tern addon http://ternjs.net/doc/demo.html

If you can use Eclipse, you can install https://github.com/angelozerr/angularjs-eclipse and use the Eclispe console to show the JSON request/response used to communicate with (Nodejs) tern server https://github.com/angelozerr/tern.java/wiki/Tern-Console. Note that "part" query is not managed in my case (I have not understood today how to use it).

Regards Angelo


2014-02-02 Slava Kim <sl...@meteor.com>:

--
You received this message because you are subscribed to the Google Groups "tern-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tern-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Marijn Haverbeke

unread,
Feb 2, 2014, 4:40:43 PM2/2/14
to Slava Kim, tern-dev
Hi Slava,

The best way is probably to run the server manually (bin/tern
--verbose) from your project directory (kill existing server instances
first if you vim session is already active -- killall node, unless you
have important node processes), and then start a vim session, which
will connect to that server. You'll see console.log output (as well as
requests/responses if you pass --verbose) in the shell where you
started the server.

Best,
Marijn

Slava Kim

unread,
Feb 2, 2014, 5:44:53 PM2/2/14
to Marijn Haverbeke, tern-dev
Thanks Marijn, Angelo! I will try it tonight.

Slava

Slava Kim

unread,
Feb 2, 2014, 6:11:37 PM2/2/14
to tern...@googlegroups.com, Slava Kim
Marijn, can you please give more info on how to run Vim with tern_for_vim plugin connected to the server I am running on a specific port? I tried putting the port into .tern-port file of my js project I open with Vim but had no luck seeing any console.logs from the node process running.

Slava Kim

unread,
Feb 2, 2014, 7:25:27 PM2/2/14
to tern...@googlegroups.com, Slava Kim
Ohh, I got it. So I am starting my tern checkout from tern's bin folder. And it tries to find a project file in its parent. But my actual project is in a completely different path. I guess that was confusing to tern.

mohitleo91

unread,
Oct 16, 2014, 9:13:36 PM10/16/14
to tern...@googlegroups.com, sl...@meteor.com
Hey could you share your solution I had the same problem

Joshua Giles

unread,
Nov 11, 2014, 11:06:55 PM11/11/14
to tern...@googlegroups.com
My approach to this problem, with some optional bits:

1. Have your dev copy of Tern in some directory tern_dev_dir (with deps installed via `npm install`)
2. Put some sample code that you want to test on in some directory test_project_dir (since I work on tern-closure I use a clone of closure-library).
3. Put a .tern-project file in test_project_dir with whatever configuration you're interested in
4. In test_project_dir, start the server in your dev dir manually (something like `node <path_to_tern_dev_dir>/bin/tern --persistent --port 8001 --verbose`)
5. Open your editor in test_project_dir

Really helpful additions:
node-inspector allows you to use the Chrome debugger to set breakpoints, etc in a running server (you have to start it first by running node-inspector in another shell)
nodemon can automatically restart your server after you make changes to Tern or your plugin

Used together, the command from above is more like:
nodemon --debug --ignore . --watch directory_to_watch <path_to_tern_dev_dir>/bin/tern -- --persistent --port 8001 --verbose
Reply all
Reply to author
Forward
0 new messages