tagbar icon indicating copy to clipboard operation
tagbar copied to clipboard

Tagbar to use available tags file; option to set path to tag file

Open robcsi opened this issue 10 years ago • 10 comments

Hi,

I understand that tagbar uses ctags executable to generate tags for each file, when the file is switched to. This is kind of slow for me on Windows: I have to wait for the ctags command to finish which runs in a separate cmd window in the background. I would like Tagbar to not generate tags each time a file is opened, but take the existing tags from an already generated tag file.

Would it be possible to add support for this?

Cheers, robcsi

robcsi avatar Mar 05 '14 15:03 robcsi

I am interested in this as well. I tend to use tags in my projects so I have already generated them when I am using vim. It would really help with load times if I could reuse that file.

3cooper avatar Mar 21 '14 12:03 3cooper

Are you sure the ctags execution is actually taking a noticeable amount of time? It should actually be pretty much instantaneous. The only part of an update that can take a few seconds with long and complex files is the parsing of the tags into a tree structure, and that has to be done regardless of how the tags were generated. It only has to be done if the file actually changed (or is a newly edited file) though, so just switching between files shouldn't call ctags.

Using a pre-generated tags file is unfortunately not as simple and beneficial as it may seem. For one thing, there would be two ways of getting the tag information into Tagbar: by using Vim's own tag handling commands, or by parsing the tags file from Tagbar. But Vim's tag commands are not flexible enough for Tagbar's needs, and filtering a (potentially very big) tags file manually for the tags of the current buffer would most likely be quite slow, especially in addition to the tree parsing time mentioned above. Additionally it would be pretty much impossible to keep the tag information in sync with buffer changes as Tagbar currently does. Ctags doesn't support updating the information of only one source file in a tags file, you either have to update the whole tags file (making it slower again) or append the new information, leading to duplicate tags. So I don't think there would be any advantage in using an already existing file.

majutsushi avatar Mar 22 '14 07:03 majutsushi

Hi,

Yes, I'm sure: a cmd window shows up in the background and on the taskbar, which runs the ctags command. If I'm fast enough, I can click on it and I can see the whole command. It does not run for long, but it is run more than 1 time, because I usually open vim with many files (using CtrlSpace plugin).

The cmd window also appears when I don't have this plugin installed, and I do a buffer change using the :b command.

You can see my vim configs here: https://github.com/robcsi/.vim

robcsi avatar Mar 24 '14 09:03 robcsi

Hey,

sorry for my slow replies. I've done some investigation, but it seems to me that Tagbar probably isn't the culprit. If I run Vim in a Windows VM and load new files with Tagbar open, the ctags run is so quick that I really have to pay attention to even see it flash by in the taskbar. It's certainly not visible long enough for me to click on it. And if I just switch between buffers then ctags doesn't get run by Tagbar, it only gets run if the file actually changed. I found a corner case where it does process the file needlessly when switching buffers but that would have only affected you if you didn't have hidden set. Tagbar also shouldn't do any processing on Vim startup unless you use the statusline functionality (which you don't seem to do), it will only start processing files once you actually open the Tagbar window.

However, I did notice that you also seem to be using the easytags plugin. This seems like a much more likely candidate for the issues you're describing, as easytags is run on all files in your project and even if it is just run on one file (possibly when switching buffers) then it does some more processing. Could you try disabling the easytags plugin to see if that makes the issue go away?

majutsushi avatar Apr 03 '14 06:04 majutsushi

Hi,

Thanks for your investigation.

I removed easytags (moved the directory out of my bundle directory) and the cmd windows still appear when restarting GVim. If I move the tagbar directory, too, then no cmd windows appear.

Here are two screenshots of the commands I could catch, maybe you'll recognize them: https://drive.google.com/file/d/0BzKH_q50TDwzSHA1SnpETFBpbXM/edit?usp=sharing https://drive.google.com/file/d/0BzKH_q50TDwzbzJ6RWVxdmlhNmc/edit?usp=sharing They were made after moving the easytags plugin out.

Thanks, robcsi

robcsi avatar Apr 03 '14 07:04 robcsi

Hmm, those commands do indeed seem to be from Tagbar. Strange. Could you maybe generate a debug log as described in :h tagbar-issues (after updating to the latest revision), but instead of just opening a file and then quitting switch between buffers a bit? That way I can hopefully see why ctags gets run again in that scenario. Also, what ctags version are you using, the one from ctags.sf.net or the one included with cygwin?

majutsushi avatar Apr 05 '14 06:04 majutsushi

Hi,

I'm using Exuberant Ctags 5.8, Copyright (C) 1996-2009 Darren Hiebert Compiled: Jul 9 2009, 17:05:35 Addresses: [email protected], http://ctags.sourceforge.net Optional compiled features: +win32, +regex, +internal-sort This is what I get after running ctags --help.

Here are the logs, too, in tagbarlogs.zip. https://drive.google.com/folderview?id=0BzKH_q50TDwzajlwQUJvU0Z6OWM&usp=sharing

Cheers, robcsi

robcsi avatar Apr 07 '14 06:04 robcsi

Sorry for the very late reply again, I've been very busy recently. I had a quick look at the logs, but as far as I can see from them ctags execution seems to be pretty quick, only about 200 milliseconds. And switching between already open files doesn't seem to execute it again either. Is this different from what you're experiencing? I'll have a closer look in about a week when I should have a bit more time.

majutsushi avatar May 09 '14 01:05 majutsushi

Love this plugin, but also love Gutentags for tag file generation. We have things like SASS files that we have custom ctags defs for and Gutentags does a great job of working with Universal Ctags to generate the necessary ctags/files.

To keep our projects clean and because we love XDG Base Directory layouts we have Gutentags files being saved to ~/.cache/gutentags/.

Would be awesome if there were some way to integrate Gutentags and Tagbar. It might take more than just saying "here's a custom tag file path" but that'd be a great start.

ActionScripted avatar Sep 28 '18 14:09 ActionScripted

@ActionScripted I would be happy to review a PR that added this as a feature. I work with projects that have tags generated for other reasons as well so it would be nice to integrate the two. I probably won't have time to work on it, but would be happy to help get it added to the plugin.

To @robcsi and @3cooper, did you ever get your performance issues worked out? If not, please let us know (but maybe in a separate issue because this is really about adding a feature, and I don't think the performance problem and feature request are really linked in this case). Also note comments about easytags in #107, that plugin has been known to cause performance problems (I had to stop using it in the past as well, unrelated to tagbar).

alerque avatar Oct 22 '19 12:10 alerque