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?
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.
Related
Is it possible to get access for built-in completion sources like keywords in the current buffer or omnicompletion? I am trying to make my own completion manager based on completefunc. I know there is \k character class and I can simply search through the whole buffer but it is such an overhead to deal with on each key presses.
If not, do you know the way to copy all keywords into the list? Keep in mind, I need cursor ordinary atom \%# so the family of match functions is unacceptable.
No, currently there's no such function available in Vim. My CompleteHelper plugin has generic functions to extract arbitrary patterns from buffers; I use it to implement several custom completions. Additionally, I've written emulations of the local keyword and tag completions in this (unpublished) library. Feel free to reuse or derive your own code from it!
Is there a way to get a summary of the instantiated templates (with what types and how many times - like a histogram) within a translation unit or for the whole project (shared object/executable)?
If I have a large codebase and I want to take advantage of the C++11 extern keyword I would like to know which templates are most used within my project (or from the internals of stl - like std::less<MyString> for example).
Also is it possible to have a weight assigned to each template instantiation (time spent by the compiler)?
Even if only one (c++11 enabled) compiler gives me such statistics I would be happy.
How difficult would it be to implement such a thing with Clang's LibTooling?
And is this even reasonable? Many people told me that I can reason which template instantiations I should extern without the use of a tool...
There are several ways to attack this problem.
If you are working with an open-source compiler, it's not hard to make a simple change to the source code that will trace all template substantiations.
If that sounds like too much hassle, you can also try to force the compiler to produce a warning on each template instantiation for a given symbol. Steven Watanabe has written a set of tools that can help you with that.
Finally, possibly the best options is to use the debugging symbols (or map files), generated by the compiler, to track down how many times each function appears in the final image and more importantly how much does it add to the weight in bytes. The best example for such a tool is Andrian Stone's SymbolSort, which is based on the Microsoft's toolset. Another similar tool is the Map File Browser.
I have two questions regarding coding Haskell in Emacs/VIM in Linux :
If one wanted to organise a haskell code base into multiple projects (where files of a given project are stored in a particular folder) then can emacs and vim handle this? The reason is that I have used IDE's before where all the projects are loaded at once into the session, but am not sure how this would work for Emacs/VIM.
Another nice thing about IDEs is that I can go the definition of a function from a given project, even if that function definition is in a separate project (i.e. stored in a separate folder). Can Emacs/VIM handle this?
There was some discussion here : Haskell IDE for Windows?
VIM/Emacs don't care how you organize your files. They're primarily editors, so you can use them to edit files no matter how you lay out your directory structure. Other than that, it's good to follow some standard conventions, or adapt the structure for tools you are going to use. You can have a look at Structure of a Haskell project. It is also convenient to use Cabal to build your project and to manage its dependencies.
VIM/Emacs can use Ctags index files for navigating in your project. See Tags for available options how to create these index files. The indexing tools don't expect any specific project structure, so if you need to navigate in multiple projects, you can just index a directory with multiple projects into one index file.
There's an Emacs mode called Projectile that allows some "project-like" functionality, which might be what you're looking for. I haven't really used it myself (I tend to stick to the old *nix way of just editing files), so I can't give you details, but it can't hurt to check it out.
Not sure if I understood the gist of question correctly. The following is my suggestion concerning the question of management of multiple projects in Vim, without regard to the language employed.
You could take advantage of vim sessions. With a few custom functions/keymappings in your .vimrc you'll be able to keep a separate session file for each project, either in the project directory or the one you'd dedicate for session files.
This is the general how-to: http://vim.runpaint.org/editing/managing-sessions/
And there you'll find a number of scripts that specifically address the issue of handling multiple project-specific sessions: How to auto save vim session on quit and auto reload on start including split window state?
In LabVIEW, is it possible to tell from within a VI whether an output terminal is wired in the calling VI? Obviously, this would depend on the calling VI, but perhaps there is some way to find the answer for the current invocation of a VI.
In C terms, this would be like defining a function that takes arguments which are pointers to where to store output parameters, but will accept NULL if the caller is not interested in that parameter.
As it was said you can't do this in the natural way, but there's a workaround using data value references (requires LV 2009). It is the same idea of giving a NULLÂ pointer to an output argument. The result is given in input as a data value reference (which is the pointer), and checked for Not a Reference by the SubVI. If it is null, do nothing.
Here is the SubVI (case true does nothing of course):
And here is the calling VI:
Images are VI snippets so you can drag and drop on a diagram to get the code.
I'd suggest you're going about this the wrong way. If the compiler is not smart enough to avoid the calculation on its own, make two versions of this VI. One that does the expensive calculation, one that does not. Then make a polymorphic VI that will allow you to switch between them. You already know at design time which version you want (because you're either wiring the output terminal or not), so just use the correct version of the polymorphic VI.
Alternatively, pass in a variable that switches on or off a Case statement for the expensive section of your calculation.
Like Underflow said, the basic answer is no.
You can have a look here to get the what is probably the most official and detailed answer which will ever be provided by NI.
Extending your analogy, you can do this in LV, except LV doesn't have the concept of null that C does. You can see an example of this here.
Note that the code in the link Underflow provided will not work in an executable, because the diagrams are stripped by default when building an EXE and because the RTE does not support some of properties and methods used there.
Sorry, I see I misunderstood the question. I thought you were asking about an input, so the idea I suggested does not apply. The restrictions I pointed do apply, though.
Why do you want to do this? There might be another solution.
Generally, no.
It is possible to do a static analysis on the code using the "scripting" features. This would require pulling the calling hierarchy, and tracking the wire references.
Pulling together a trial of this, there are some difficulties. Multiple identical sub-vi's on the same diagram are difficult to distinguish. Also, terminal references appear to be accessible mostly by name, which can lead to some collisions with identically named terminals of other vi's.
NI has done a bit of work on a variation of this problem; check out this.
In general, the LV compiler optimizes the machine code in such a way that unused code is not even built into the executable.
This does not apply to subVIs (because there's no way of knowing that you won't try to use the value of the indicators somehow, although LV could do it if it removes the FP when building an executable, and possibly does), but there is one way you can get it to apply to a subVI - inline the subVI, which should allow the compiler to see the outputs aren't used. You can also set its priority to subroutine, which will possibly also do this, but I wouldn't recommend that.
Officially, in-lining is only available in LV 2010, but there are ways of accessing the private VI property in older versions. I wouldn't recommend it, though, and it's likely that 2010 has some optimizations in this area that older versions did not.
P.S. In general, the details of the compiling process are not exposed and vary between LV versions as NI tweaks the compiler. The whole process is supposed to have been given a major upgrade in LV 2010 and there should be a webcast on NI's site with some of the details.
I have been getting very frustrated recently in dealing with a massive bulk of legacy code which I am trying to get familiar with.
Say I try to search for a particular function call, I get loads of results that turn out to be completely irrelevant; some of them are easy to spot, eg a comment saying
// Fixed functionality in foo() so don't need to handle this here any more
But others are much harder to spot manually, because they turn out to be calls from other functions in modules that are only compiled in certain cases, or are part of a much larger block of code that is #if 0'd out in its entirety.
What I'd like would be a search tool that would allow me to search for a term and give me the choice to include or exclude commented out or #if 0'd out code. Then the search results would be displayed alongside a list of #defines that are required in order for that snippet of code to be relevant.
I'm working in C / C++, but other than the specific comment syntax I guess the techniques should be more generally applicable.
Does such a tool exist?
Not entirely what you're after, but I find this quite handy.
GrepWin - A free visual "grep" tool for searching files.
I find it quite helpful because:
Its a separate app (doesn't lock up my editor)
Handles Regular expressions
Its fast
Can specify what folder to search, and what filetypes (handles regex's here too)
Can limit by file size
Can include subdirs (or exclude by regex)
etc.
Almost any decent source browser will let you go to where a function is defined, and/or list all the calls of that function and take you directly to a call site. This will normally be based on a fairly complete parse of the source code so it will ignore comments, code that's excluded by the preprocessor, and so on (in fact, in at least one case, the parser used by the source browser is almost certainly better than the one used in the compiler itself).