Open timblaktu opened 6 years ago
Hi! I'm not super familiar with the cscope side of things (half of the code was contributed by other people for that module).
Does the GTAGS
file exist prior to opening Vim? If not, could it be that Gtags-cscope
tries to add it, but it doesn't exist, and it only gets created by Gutentags a second later?
@ludovicchabant yes, the entire tree of files in ~/.cache/tags as I posted above exists before I open a file in that project in vim. Note that this is not just a GTAGS issue - the ctags file also exists beforehand, yet gutentags still creates it.
Is there some test I could do to help shed more light on this? Thanks.
Ok, so you could try to first restrict Gutentags' work to ctags
(with let g:gutentags_modules = ['ctags']
) so we can see if that works as expected for that.
Note that it's expected for Gutentags to rebuild the files/DBs/etc. on open by default (see g:gutentags_generate_on_new
). You could try changing that setting as a test to see if it's indeed some kind of problem between Vim trying to read the GTAGS
file at the same time it's being written to.... (comparatively, the ctags
module doesn't write directly to the tags file, it writes to a .temp
file and then switches the 2... maybe the cscope
module should do the same if that's the problem).
When I let g:gutentags_modules = ['ctags']:
When I let g:gutentags_generate_on_new=0, as you said the ctags no longer generate when vim opens. I see now that the behavior I want requires me to let gutentags_generate_on_missing=1.
So now the only mystery is 1. above, why the GTAGS not found Gtags-cscope error is happening...
I can see that the gtags-cscope.vim plugin is emitting this text within this function which is called when the plugin starts up:
function! s:GtagsCscope_GtagsRoot()
let cmd = s:global_command . " -pq"
let cmd_output = system(cmd)
if v:shell_error != 0
if v:shell_error == 3
call s:Error('GTAGS not found.')
else
call s:Error('global command failed. command line: ' . cmd)
endif
return ''
endif
return strpart(cmd_output, 0, strlen(cmd_output) - 1)
endfunction
where
let s:global_command = $GTAGSGLOBAL
if s:global_command == ''
let s:global_command = "global"
endif
When this code fails, it basically exits the main GtagsCscope() plugin function, so the plugin functionality isn't working.
Testing this manually in a shell:
[tblack-stretch]/home/tblack/src > which global
/usr/local/bin/global
[tblack-stretch]/home/tblack/src > echo $GTAGSGLOBAL
[tblack-stretch]/home/tblack/src > global -pq
[tblack-stretch]/home/tblack/src > echo $?
3
indicates the error is caused by gnu global -pq (which is supposed to simply print out the location of the GTAGS tags database) is returning an error 3 bc it cannot find it.
If I cd into the directory that contains the GTAGS db file, and rerun the command, it succeeds:
[tblack-stretch]/home/tblack/src > cd ~/.cache/tags/home-tblack-src-lt-
[tblack-stretch]tblack/.cache/tags/home-tblack-src-lt- > ls
GPATH GRTAGS GTAGS
[tblack-stretch]tblack/.cache/tags/home-tblack-src-lt- > global -pq
/home/tblack/.cache/tags/home-tblack-src-lt-
[tblack-stretch]tblack/.cache/tags/home-tblack-src-lt- > echo $?
0
So, it appears the problem I am having here is that gnu global needs to be configured to know my g:gutentags_cache_dir so that at startup it can find the GTAGS database.
Can anyone using gutentags with gnu global chime in on how I need to properly configure so that gnu global is able to dynamically find the GTAGS databases that gutentags is generating?
In my vimrc I am sourcing this file:
source ~/dotfiles/vim/.vim/gtags-cscope.vim
which is a copy of the gtags-cscope.vim plugin from the gnu global std distribution.
I see now that gutentags also ships with some gtags-cscope vimscript, in vim-gutentags/autoload/gutentags/gtags_cscope.vim, which does a lot of fancy things, including what looks like setting up the path to the gtags database files (by calling gutentags#get_cachefile
)...
.. so, this sort of answers my question - I can see now that there is gutentags code in place that is supposed to be setting up the path to gtags database, dynamically, per-buffer.
I guess this means that I should turn off autoloading in MY gtags_cscope plugin:
let g:GtagsCscope_Auto_Load = 0
so that it will just let gutentags' gtags-cscope support do this instead?
Of course, when I do this, the error I was seeing goes away, but I'm not yet convinced that gutentags/gtags-cscope support is working, bc I always get "no matches found" when I invoke the standard cscope queries like :cs find g name
, even though I see that the GTAGS for the corresponding project are there in my cache dir.
Yeah the gtags_cscope
is enabled if you go back to having g:gutentags_modules
contain it. Maybe the problems you had were both that and GtagsCscope
conflicting each other?
Other than that, like I said, the gtags_cscope
support in Gutentags is mostly provided by other contributors, I'm not using it myself... so if it doesn't work you might have to troubleshoot it yourself, or see if someone else replies to this thread.
mark
I have not been able to find any issues matching this basic problem. Tags are getting generated by gutentags where I have configured them to be generated, and vim is finding them and allowing me to use them for code navigation, however I am getting a "GTAGS not found" error every time I start vim, and both the ctags and gtags are getting re-generated everytime I start vim. My expectation is for gutentags to discover the existing tags and (a) not post the "GTAGS not found" error (which I realize may be a Gtags-cscope error), and (b) not invoke update_tags.sh on startup.
With this config, defined towards the end of my .vimrc:
and with a projectroot set by the .cproject file at my project root:
and ctags and gtags already created successfully by gutentags (and working within vim) :
I get this when I open the root makefile in the project with vim (or any other file in the project):
Upon opening the makefile, my status line and the below trace output indicate that gutentags is regenerating both ctags and gtags files even though these already exist as shown above:
I'm on debian 9, vim 8 (nogui), universal-ctags version 0.0.0(6418097e), gnu-global version 6.6.2, gutentags master: