how to make vim ctags works for modern javascript
Asked Answered
I

4

35

I am using vim and ctags to get taglist. but for javascript, it does not works for this convention

MyClass.extend({
  xxx: function(){
  },
   ...
})

MyClass.prototype = {
    method : function(){ }

}

MyClass.prototype.method  = function () {
}
Inertia answered 18/12, 2010 at 8:34 Comment(1)
Odds are no-one's written the parser for you yet so your going to have to do it yourself.Ober
N
18

Like the others had said: DoctorJS (formerly jsctags) is the best option.

However, integrating it with Vim by writing custom wrappers or using Vim-taglist-plus plugin, which isn't currently working, aren't good solutions.

The easiest way I've found is to install the TagBar Vim plugin (NOTE: It's TagBar, not the old infamous TagList!).

See my other answer for more info.

Edit:

There's a new project called tern.js which should replace the dead doctor.js. See the link above for more info.

Naturalistic answered 5/5, 2011 at 6:47 Comment(5)
Wow, you switched the answer. Guess you really enjoyed the solution. :)Naturalistic
Too bad the DoctorJS project is no longer maintained (at least here). It fails to run on itself, and not only...Buchalter
Yes, but the wiki in TagBar GitHub repo has a temporary fix for this - you can revert to an earlier commit.Naturalistic
Both DoctorJS and Tern for vim are abandonware. There is currently no good way that is documented online (which doesn't mean it doesn't exist).Whinchat
Tern is, Tern for Vim is notWhinchat
N
12

As @Benoit answered, you can always setup a new languages for ctags; however in the case of JavaScript, you may want to try DoctorJS (formerly jsctags). From the author it is a limited JS environment that records all the functions and objects your script made and turns them into vim-compatible tags file. Here is the original post http://pcwalton.blogspot.com/2010/05/introducing-jsctags.html and its website: http://doctorjs.org/.

To use it with ctags I have to rename the ctags file to smt like ex-ctags and write a wrapper script named ctags which will switch the tool depending on --language.

Nuncle answered 3/2, 2011 at 5:45 Comment(1)
Installing it seems to require a bit of work. And it looks like the package isn't being actively maintained: npmjs.org/package/jsctags, github.com/mozilla/doctorjs But good stuff!Emir
R
5

You can setup new languages for ctags. See this and that

Rustic answered 2/2, 2011 at 9:37 Comment(1)
+1, but this answer would be better if the "this" content were included here for reference (with a source citation).Remove
H
1

provided you install doctorjs, you can use the vim-taglist-plus plugin, which is a fork of the vim-taglist plugin with jsctags (doctorjs) support : https://github.com/int3/vim-taglist-plus

Heloise answered 17/4, 2011 at 12:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.