xolox / vim-easytags

Automated tag file generation and syntax highlighting of tags in Vim
http://peterodding.com/code/vim/easytags/
1.01k stars 109 forks source link

easytags isn't creating tags for c++ class #91

Closed ramon-oliveira closed 9 years ago

ramon-oliveira commented 10 years ago

Here is my .vimtags file: tags

And it's possible to see that it's not highlighting my class in my file test.cpp :

code

Anyone knows how to solve this?

ghost commented 10 years ago

I got this problem also. The tags file marks all these files as C instead of C++ and classes are no longer highlighted anymore. I am not sure, but if I remember correctly, this has happened since b6f8757d004d5f4ef7280fd111a21821e6bee79a or even earlier.

ghost commented 10 years ago

I just did a bisect and found the problem starts at b6f8757 exactly.

ghost commented 10 years ago

A quick test. If you set g:easytags_syntax_keyword to anything other than "auto" or "always", you will get your class highlighting back. But here comes another problem: if you have a function or member that has a class name within (like "class PDB{}; void toPDBFormat()"), then the highlight will mis-highlighting the class name in between (like "PDB" in "toPDBFormat" will be marked as a class, while other parts remain black).

ghost commented 10 years ago

The changes ( b6f8757 ) in xolox#easytags#define_tagkind about a:object.pattern_prefix and a:object.pattern_suffix causes the mis-highlighting problem. I guess this is used in syntax_keyword approach.

ghost commented 10 years ago

Please ignore those part. Those are fixed in the HEAD.

Disable the syntax keyword method by setting g:easytags_syntax_keyword to anything except "auto" or "always" fixes the problem.

ghost commented 10 years ago

For ctags generating C tags for C++ files, I just changed autoload/xolox/easytags.vim: s:prep_cmdline (line 238) to call xolox#easytags#filetypes#to_ctags instead of xolox#easytags#filetypes#canonicalize, and it works. Probably it is better to change line 267 to let filetype = xolox#easytags#filetypes#to_ctags(&filetype), but I am not sure.

ramon-oliveira commented 10 years ago

I made the changes that you indicated in the last post, and it works. Thanks a lot.

harnold commented 10 years ago

Because 'cpp' is added to the 'c' group in autoload/xolox/easytags/filetypes.vim, the function xolox#easytags#filetypes#canonicalize() returns 'c' when called with filetype 'cpp'. This causes ctags to be called with the option --language-force=c, while it should be called with --language-force=c++.

ramon-oliveira commented 10 years ago

Another question, why easytags is creating tags to the variables in the structure? There is a way to disable this?

sorry if this is a silly question, i am new in vim and their plugins.

ghost commented 10 years ago

Sorry for the late reply. You might want to check g:easytags_languages options, which is described in the readme file. To remove members, you might want to check --extra=-q option to ctags.

xolox commented 10 years ago

Sorry for all of the confusion (and buggy behavior) I seem to have caused with this. Let me first point out the original reason for this behavior of vim-easytags (the canonicalization misfeature) because I've seen no mention of this so far while it is quite relevant:

The result of the three points above was that I missed the tags defined in my C *.h files so I implemented file type canonicalization. The current implementation is clearly suboptimal :-) but I'm not yet sure how to improve it. Given that C++ is a (proper?) super set of C maybe the canonicalization of C should result in C++ instead of the other way around? But then what to do with Objective C and others?


Here's an example of Exuberant Ctags' behavior I'm referring to above (just tested it to verify):

$ ctags -f - --fields=+l /usr/include/errno.h
_ERRNO_H    /usr/include/errno.h    28;"    d   language:C++
__error_t_defined   /usr/include/errno.h    70;"    d   language:C++
__need_Emath    /usr/include/errno.h    37;"    d   language:C++
__need_error_t  /usr/include/errno.h    72;"    d   language:C++
error_t /usr/include/errno.h    /^typedef int error_t;$/;"  t   language:C++
xolox commented 10 years ago

I just realized that Vim interprets *.h files as C++ (filetype=cpp) as well. So Vim and Exuberant Ctags are consistent with each other. Maybe that means file type canonicalization is a bogus feature which can be removed?

ghost commented 10 years ago

From the viewpoint of vim's syntax highlighter and ctags, I think it is fair to treat C as a subset of C++. But I am not familiar with Obj-C and Obj-C++. Thank you for your help.

harnold commented 10 years ago

I think the approach of Easytags canonizing the file type is wrong. File type detection is Vim's business, and Vim can already detect file types based on more than the file name ending. If that doesn't work, it's easy to fix. For example, for *.h files, I decide between C and C++ based on a search for some C++ specific keywords, which works great. Therefore, in my opinion, Easytags should simply map each supported Vim file type to the corresponding ctags file type.

xolox commented 9 years ago

Hi all! I just published vim-easytags 3.8 with the intention of fixing this issue... Please try it out and let me know whether it resolves the issue reported here.

harnold commented 9 years ago

Version 3.8 only partially works for me: It generates C++ tags for C and C++ files now, but the tags are no longer highlighted.

xolox commented 9 years ago

@harnold: You're right, it's only a partial fix, thanks for pointing that out. I have a proper test case now so will update this issue when I've pushed a fix.

xolox commented 9 years ago

I just released vim-easytags 3.8.2. Does this work better?

harnold commented 9 years ago

@xolox: Unfortunately not, tags are not colored (neither C nor C++). Does it work for you?

xolox commented 9 years ago

@harnold:

Yes this time I properly tested it :-). I get highlighted C as well as C++ tags, with and without syntax keyword highlighting and with and without Python accelerated highlighting. Maybe another bug is preventing highlighting from working for you? Below is a one line Vim command to print your vim-easytags configuration:

echo join(sort(map(items(filter(copy(g:), 'v:key =~ "^easytags"')), 'string(v:val)')), "\n")

If you're running gVim you may prefer this variant:

call confirm(join(sort(map(items(filter(copy(g:), 'v:key =~ "^easytags"')), 'string(v:val)')), "\n"))

Here is the output with my configuration:

['easytags_always_enabled', 1]
['easytags_async', 1]
['easytags_by_filetype', '/home/peter/.local/vim/tags/filetypes']
['easytags_cmd', '/usr/bin/ctags-exuberant']
['easytags_ctags_version', '5.9']
['easytags_events', ['BufWritePost', 'CursorHold', 'CursorHoldI', 'BufReadPost', 'FocusGained', 'ShellCmdPost', 'ShellFilterPost']]
['easytags_file', '~/.vimtags']
['easytags_ignored_filetypes', '^tex$']
['easytags_on_cursorhold', 1]
['easytags_python_enabled', 1]
['easytags_python_script', '/home/peter/Dropbox/Projects/Vim/easytags/plugin/../misc/easytags/highlight.py']
['easytags_resolve_links', 1]
['easytags_syntax_keyword', 'auto']
ghost commented 9 years ago

Mine works okay. Thanks a lot.

xolox commented 9 years ago

@nocte107: Thanks for the follow up! I'm glad to hear that this issue seems to be resolved for at least some users.

If anyone else feels like chiming in, I'd love to hear whether the issue is resolved for others. If/when it's not (as suggested by @harnold) then we can start to narrow down what the difference is between the users who say the issue is resolved vs. those who say the issue is not resolved; e.g. we might be conflating unrelated issues!

Also @harnold if you could reply to my previous message here that would be great.

harnold commented 9 years ago

@xolox: Sorry, I missed your last comment. Tag coloring now works on my system; must have been some caching issue. I guess you can consider this bug solved.

xolox commented 9 years ago

@harnold: Thanks for the follow up, great to hear it works now!

Thanks for everyone's input on this issue & happy Vimming!

davidkennedydev commented 8 years ago

Ok, at principle i believe that's my problem, but searching vim with :tag NamespaceX::ClassNameX::methodName this points correctly, but if i just puts the cursos above a methodName call and use <c-]> this points incorrectly. This a problem on vim-easytags plugins or a problem with the own <c-]> map to go to tag on VIM?