preservim / tagbar

Vim plugin that displays tags in a window, ordered by scope
https://preservim.github.io/tagbar
Other
6.11k stars 486 forks source link

JS support? #30

Open ehynds opened 13 years ago

ehynds commented 13 years ago

I haven't been able to get this plugin to play nice with JavaScript files. Here's what the output looks like: http://gyazo.com/36426dcb57e835537f5561ffd45df2eb.png

I have tried setting g:tagbar_ctags_bin to both my exuberant ctags install and jsctags, but the output remains the same. I would expect to see some kind of hierarchy & organization of functions? Is there something I'm missing here?

majutsushi commented 13 years ago

This seems to be a bug in jsctags. In my old checkout from April jsctags correctly reports the scopes that tags are in, but the current version doesn't do that. I'll file a bug with them, unfortunately there's nothing else I can do about that from within Tagbar.

rolnxyz commented 13 years ago

I have the exact same issue. I tried to check out this https://github.com/int3/doctorjs which is from March, and I am still unable to see scopes when using the plugin.

To which version of jsctags should I revert back? Can you share the one you have?

huyz commented 13 years ago

I would also like some pointers on how to get jsctags working properly

huyz commented 13 years ago

@majutsuhi I'm a bit confused in general about how to get jsctags working from within Tagbar. Tagbar says it's compatible, but if I set g:tagbar_ctags_bin I get an error. How does tagbar know to run jsctags instead of ctags?

majutsushi commented 13 years ago

@rolnxyz: The official repo is at https://github.com/mozilla/doctorjs. This version worked for me: https://github.com/mozilla/doctorjs/commit/1062dd31625cc002261f15e68af77eedd63a56f6

@huyz: g:tagbar_ctags_bin is only for exuberant-ctags. If your jsctags binary is in your $PATH then it should 'just work', otherwise you will have to provide a tagbar type configuration with the ctagsbin key in it. See :help tagbar-extend for information on how to do that.

huyz commented 13 years ago

@majutsushi Great thanks

huyz commented 13 years ago

I can confirm that that commit works for me. Just:

git checkout 1062dd31625cc002261f15e68af77eedd63a56f6
sudo make install

and Tagbar works beautifully

rolnxyz commented 13 years ago

I installed the old version of jsctags and now, instead of getting a bunch functions with no namespace information, I just get the highest level namespaces and no function information at all.

This is the code I am trying to see in Tagbar


$(function(){
  window.Todo = Backbone.Model.extend({
    defaults: function() {
      return {
        done:  false,
        order: Todos.nextOrder()
      };
    },

    // Toggle the `done` state of this todo item.
    toggle: function() {
      this.save({done: !this.get("done")});
    }

  });
});

And this is what I see in vim GitHub Logo

This is happening because I am using Backboje.js framework. I know this is a jsctags issue and not a tagbar issue once again. I guess javascript is too complicated to accurately retrieve tags in a generic way.

Any help is appreciated.

majutsushi commented 13 years ago

Yes, that's unfortunate, but again I can't do anything about that on Tagbar's side. If you run jsctags manually on your file you will see that it reports only this single tag. Once jsctags supports this style it should work without any changes in Tagbar, though.

huyz commented 13 years ago

@rolnxyz You know, I got tired of all the tools that couldn't recognize functions inside of an anonymous wrapper function. Here are some that have trouble:

Interestingly, NetBeans seems to handle the situation fine..

So basically I just removed the anonymous wrapper and now I rely on Closure Compiler's --output_wrapper flag to wrap everything when I ship (in a similar way that coffee-script wraps by default, but more customizable). While developing, I don't really need this wrapper anyway.

vheon commented 12 years ago

since in four months on jsctags side there is no answer on the scope problem I tried to use the older version as you suggested, but it gives me this output:

[07:25 pm] vheon@starkBox ~$ echo $NODE_PATH 
/usr/local/lib/jsctags/:
[07:25 pm] vheon@starkBox ~$ ls /usr/local/lib/jsctags/
ctags         log.js        paperboy.js   underscore.js
getopt.js     narcissus     traits.js
[07:25 pm] vheon@starkBox ~$ jsctags

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
Error: require.paths is removed. Use node_modules folders, or the NODE_PATH environment variable instead.
    at Function.<anonymous> (module.js:378:11)
    at Object.<anonymous> (/usr/local/bin/jsctags:41:8)
    at Module._compile (module.js:441:26)
    at Object..js (module.js:459:10)
    at Module.load (module.js:348:31)
    at Function._load (module.js:308:12)
    at Array.0 (module.js:479:10)
    at EventEmitter._tickCallback (node.js:192:40)

someone can tell me why?

majutsushi commented 12 years ago

Hm, no one seems to have any clever ideas, and I don't really use JavaScript myself so I probably can't be of much help. Maybe it's possible to modify the old jsctags version to make it work with newer node.js versions (which is the cause of the above error), but I don't know how much work that would be. Otherwise I guess we will have to wait for the main developer to have some time to re-add this functionality.

yunong commented 12 years ago

The require.paths problems is due to node 0.6.x

Rolling back node on your system to 0.4.x will fix that issue. I suggest using https://github.com/creationix/nvm to manage various node versions on your box.

faceleg commented 11 years ago

I've cobbled together a working version from issue comments & a fork: https://github.com/faceleg/doctorjs. This version works with node 0.10.x.

stefandtw commented 10 years ago

Nowadays there is a new jsctags.

jelera commented 10 years ago

have you tried it? because I did tried it a couple of months ago, and that version of jsctags couldn't generate a proper tags files compatible with Exuberant Ctags (the format Tagbar recognizes).

If you get it to work, please update the Wiki, the community will thank you.

majutsushi commented 10 years ago

There were some changes recently that apparently make it work: https://github.com/ramitos/jsctags/issues/2 I haven't tested it myself, though, and there seems to be another issue where not all tags are recognized: https://github.com/ramitos/jsctags/issues/3

stefandtw commented 10 years ago

I have tried it a little bit, but not too much. For simple JavaScript files I see an outline with my prototype object and its methods, but it doesn't show any of the properties assigned in the constructor.

On the other hand, opening some library files like JQuery I just get lots of errors. That may be because of the issue majutsushi mentioned, I don't know.

alerque commented 4 years ago

Can any of you Javascript aficionados comment on the status of this? Does jsctagas work now? Do we need to use the fork? Is there something that still needs fixing? Does uctags now cover Javasacript better? I'd be happy to facilitate a fix to this long standing issue but I don't have much to work with here. What's the current low down?