vim lookup struct elements/members

730 Views Asked by At

Does anyone know of a vim plugin that allows to look up struct members/elements of structures in C or classes in case of C++?

I'm thinking something similar to jumping to a definition of a struct using cscope/ctags, but ideally I would want something similar to moving a cursor over the desired variable and a keystroke will pull up a table akin to when you use omni-complete?

I've been trying to find something but to no avail.

The requirement is: should be exclusively for vim. 99% of my development is sshing to a remote linux machine.

Normally my workflow is, git clone the project, setup ctags and cscope, open up the desired file and load up my cscope db and that's where I stay for the majority of the day, moving around the directory I have the nerd-tree plugin.

So far I use a combination of ctags/cscope, and calltree plugins to look up function callees.

I'm missing a plugin that allows me to simply look up struct elements. I don't really use omnicompletion because it is notoriously slow and I've given up to make it faster.

Any ideas?

1

There are 1 best solutions below

0
Luc Hermitte On

With universal-ctags, given you've used the right options, you can always obtain the members of a class/struct type.

If you read in between the lines, this means there is no efficient way to do it on a C++ variable if you stick to vimscript. I've tried do it, but I've given up on this path eventually ; path that has no way to support auto.

Now, I've started using (/implementing) another approach to analyse C++ code and exploit the information from vim: I rely on libclang. The catch is that it needs to operate on the current translation unit (TU), and if the TU is long (e.g if it includes many long files), it's takes time to parse it for the first time since the last time it has changed (I expect the solution to change with C++20 modules) -- the analysing is done on demand, and not in the background. Note: my plugin is currently under development and I haven't yet provided an high level Vim function that returns the type of a variable and its associated information (type, members, possible enum values...)

If your ultimate objective is completion of members, clang based tools provide a dedicated API for this purpose that'll be more efficient than completely analysing the current TU. The plugins you don't wish to use exploit this API. LSP servers even try to cache as much information as possible (for navigation and completion purpose only).

Note that there exist a few plugins, like tagbar, that tries to organize information extracted with ctags and present it in a hierarchic view. Note that it won't help with disambiguation nor with auto.