preservim / tagbar

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

Add global support for TODO FIXME XXX... #811

Closed ChausseBenjamin closed 2 years ago

ChausseBenjamin commented 2 years ago

So tagbar is great for navigating projects. But I feel like implementing a way to navigate TODO's (and all the others) would improve it greatly. I was looking around for a solution and stumbled upon this ctags flag which seemed promising but the given example is exclusive to javascript.

So what I think could be great is to take a page from their book but make it universal. Therefore this:

--regex-javascript=/\/\/[ \t]*\(FIXME\)[ \t]*:?.*/\1/T,Todo,Todo messages/b

which takes JS specific comments into account could probably be turned into something like this:

--regex-all=\(FIXME\)[ \t]*:?.*/\1/T,Todo,Todo messages/b

which is language agnostic since comments simply aren't handled (I think closing comments would be kept i.e. */ but it's better than nothing).

Please note that I haven't tested any of these commands. I assumed all could be used as a valid language since the ctags manual mentions that --alias-all=... can be used for the --alias-<LANG>=... command. I simply thought this could be a great starting point if such a feature were to be implemented into vim-tagbar. I don't know if this should be added as a default. Perhaps it should be implemented as an option like:

let g:tagbar_todo_enable=1

Anyway, have a great day.

raven42 commented 2 years ago

I've pushed up a change that will allow this to be defined on a per-language basis.

Unfortunately there is no way to provide a global 'TODO' type support as the regex expression also defines the tag kind that needs to be used, and each language has it's own definition. So what works in this case with the T option in the javascript language, would not work for other languages that use a T identifier as the tag kind (for example, Markdown, ReStructuredText, Rust, etc). So if we had a global definition that used T, it would break support for those languages.

Providing a generic regex definition for any language does mean anyone looking to add this will have to manually add the language definition, but it does provide a flexible solution, and even allows for other new tag kinds to be supported as well. For example, this method also allows a fix for #799 by adding a new regex syntax for the async <function> () syntax and giving it a tag kind of f.

raven42 commented 2 years ago

The doc/tagbar.txt in the PR shows an example of how this can be defined for the c language. @ChausseBenjamin, give this a shot with your language and let me know if this works for you. I can merge it in once we have a little confirmation from another language support.

ChausseBenjamin commented 2 years ago

I just commented on the PR, there seems to be a typo in the doc/tagbar.txt. Copying the example from the doc give an error...