Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a way of specifying type nesting/hierarchy #34

Closed
lukaszkorecki opened this issue Aug 17, 2011 · 8 comments
Closed

Add a way of specifying type nesting/hierarchy #34

lukaszkorecki opened this issue Aug 17, 2011 · 8 comments

Comments

@lukaszkorecki
Copy link

Hi

I'm trying to make tagbar work with CoffeeScript. So far I got it working ok with classes which are contained in a single file

example

Configuration used:

(in .vimrc):

let g:tagbar_type_coffee = {
  \ 'ctagstype' : 'coffee',
  \ 'kinds' : [
  \   'n:namespace',
  \   'c:class',
  \   'o:object',
  \   'm:methods',
  \   'f:functions',
  \   'i:instance variables',
  \   'v:var:1',
  \ ],
  \ 'sro' : ".",
  \ 'scope2kind' : {
  \   'o' : 'object',
  \   'f' : 'function',
  \   'm' : 'method',
  \   'v' : 'var',
  \   'i' : 'ivar'
  \ },
  \ 'kind2scope' : {
  \  'function' : 'f',
  \  'method' : 'm',
  \  'var' : 'v',
  \  'ivar' : 'i',
  \ 'object' : 'o'
  \},
  \ 'deffile' : expand('<sfile>:p:h') . '/.vim/coffee.ctags'
\ }

and coffee.ctags

--langdef=coffee
--langmap=coffee:.coffee
--regex-coffee=/class ([A-Za-z.]+)/\1/c,class/
--regex-coffee=/^([A-Z][a-z].*)[ \t]*=/\1/n,namespace/
--regex-coffee=/^[ \t]*((A-Z][a-zA-Z]*/\1/c,class/
--regex-coffee=/^[ \t]*([A-Za-z]+)[ \t]*=.*->.*$/\1/f,function/
--regex-coffee=/^[ \t]*([A-Za-z]+)[ \t]*:.*->.*$/\1/m,method/
--regex-coffee=/^[ \t]*([ \t][a-z]+)[ \t]*=.*$/\1/v,var/
--regex-coffee=/^[ \t]*(@[A-Za-z]+)[ \t]*=.*$/\1/i,ivar/

This doesn't work in a file which has multiple classes or object literals with methods.

Is there a way of saying that kind method (m) belongs to object (o)? Or am I asking for too much and such functionality would have to be added to ctags/jsctags (or whatever it is called nowadays)?

@majutsushi
Copy link
Collaborator

Yes, unfortunately generating scope information is not possible with the regular expression approach in ctags -- the regular expressions only take the current line into account, and scope information requires knowledge of the file before that to determine the correct scope. It is possible to extend ctags in a way that generates scope information, but that requires writing a proper parser module in C (see here: http://ctags.sourceforge.net/EXTENDING.html). So I'm afraid I can't do anything about that in Tagbar. But once such a module exists it would of course be easy to add an appropriate Tagbar configuration like what you already have.

@lukaszkorecki
Copy link
Author

I was afraid that this is going to be the case.

Anyway - thank you for creating TagBar, shame about ctags not being easily extensible.

@sorin-ionescu
Copy link

@lukaszkorecki There is a problem with multiline comments.

###
This is some text.
More text here.
###

This and More will be listed as classes.

@lukaszkorecki
Copy link
Author

Can you add an issue to coffeetags? :-) Thanks

@sorin-ionescu
Copy link

I did not know coffeetags existed. Does your coffeetags, considering you are the author, have this problem? You would probably have noticed it by now.

@lukaszkorecki
Copy link
Author

w.r.t to the block comment - I think that coffeetags has the same bug (I didn't have the time to check to be honest, and I never had to use block comments in my own CoffeeScript code)

Anyway, lets not pollute this thread any more - I've created an appropriate issue

@joeytwiddle
Copy link

I came for the lovely nesting, so I'm sad to hear it's language-specific.

It occurs to me that in many file formats there is a way to guess the nesting without understanding the language, and that is by the indentation of the lines in the buffer. (This will work better on some files than others.)

I knocked up a proof-of-concept by modifying taglist.vim.

Source: http://hwi.ath.cx/code/home/.vim/plugin/taglist.vim

It's only a prototype, it doesn't squeeze down 4-space indents.

But it's something to consider to introduce the possibility of nesting for lesser-known languages.

@majutsushi
Copy link
Collaborator

That sounds pretty fragile, but I guess it could be useful for some languages. I'll have a look if something like it could be integrated into Tagbar. One question though: it seems like you're calculating the indent yourself, is there a reason why you're not using the indent() function that's provided by Vim?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants