preservim / tagbar

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

Add alternate tagging source by importing from tree-sitter data #751

Open rpaaron opened 3 years ago

rpaaron commented 3 years ago

is it possible, does it make sense to be able to dynamically generate the tags from tree-sitter?
ie https://github.com/nvim-treesitter/nvim-treesitter

alerque commented 3 years ago

I'm not 100% up to speed on how treesitter works or what it can be used for, but from what I do know it might make sense if you were running it already for some reason. However this means adding an entirely new backend tags provider. This plugin is already setup to handle different backends, but all the current ones involve shell commands. You would need to write one that somehow used the in-memory structures provided by treesitter that outputs ctags format data.

I'm be happy to help get such a project upstreamed here if you (or somebody else) contributes such a thing, but I don't have the bandwidth to work on such a project.

raven42 commented 3 years ago

After taking a look at treesitter, that is more of a syntax parser, not a tag parser/generator. It seems to only understand the syntax of a language, not the tag information. For a simple variable or function name that would be ok to identify the type of a variable name or function name. But it doesn't have any hierarchy definition. So for example class member functions wouldn't be given proper ownership definitions so tagbar wouldn't be able to tell what class that function was a member of. So then tagbar wouldn't be able to build a tree correctly. Closing this out as it is not in the scope of what tagbar does. Basic syntax parsing and language interpretation is not enough for what tagbar needs or does with ctags as the backend.

hacker-DOM commented 1 year ago

I don't think that's right @raven42 , Treesitter does provide a hierarchy for symbols. The data structure of it's output is, well, a tree.

raven42 commented 1 year ago

@hacker-DOM I’m certainly open to correction. If it can integrate well and provide a better user experience, I’d be all for it. As @alerque said, we can help merge something in if someone wants to put in the work. That is not something I am free to do right now though.