Tags stop working (path disappears from `tags` option) when editing Ruby files
Describe the bug
Edit: I've traced this back to vim-ruby resetting tags. See the comment below.
When jumping into and back out of a buffer using <c-]> and <c-o>, the tags option is reset, removing the tags file path that Gutentags adds within g:gutentags_cache_dir.
Steps to reproduce
- Set
g:gutentags_cache_dirin your vim config - Start vim
- Jump to definition using
<c-]> - Jump back to previous file using
<c-o> - Check
:verbose set tags?and the Gutentags path is missing
Share your setup
- macOS Catalina 10.15.6
- NVIM v0.4.4
- Exuberant Ctags 5.8, Compiled: Aug 16 2020, 12:00:05
let g:gutentags_file_list_command = 'rg --files'let g:gutentags_cache_dir = '/Users/tom/config/nvim/gutentags'
Post the logs
:messages:
gutentags: [job stdout]: ['Locking tags file...', 'Running file list command, patching for absolute paths', 'eval rg --files', '']
gutentags: [job stdout]: ['Running ctags on whole project', '']
gutentags: [job stdout]: ['ctags -f "/Users/tom/config/nvim/gutentags/Users-tom-proj-memex-tags.temp" -L "/Users/tom/config/nvim/gutentags/Users-tom-proj-memex-tags.files"', '']
gutentags: [job stdout]: ['Replacing tags file', 'mv -f "/Users/tom/config/nvim/gutentags/Users-tom-proj-memex-tags.temp" "/Users/tom/config/nvim/gutentags/Users-tom-proj-memex-tags"
', '']
gutentags: [job stdout]: ['Unlocking tags file...', '']
gutentags: [job stdout]: ['Done.', '']
gutentags: [job stderr]: ['']
gutentags: [job stdout]: ['']
gutentags: Finished ctags job.
I'm not sure where to find the tags.log file.
Additional context
I have narrowed it down to the early return in gutentags#setup_gutentags(). Deleting the early return here fixes the problem. This function assumes that tags is already set correctly if b:gutentags_files exists, but that assumption doesn't appear to be true for me.
Using :verbose set tags? to check when the problem occurs, it's ok when vim starts, it's also ok when jumping to a file, then it bugs after <c-o>. It doesn't seem to be overwritten by any other plugin according to the following output.
Starting with $ vim lib/reference/template.rb:
tags=~/config/nvim/gutentags/Users-tom-proj-memex-tags,./tags;,tags
Last set from ~/config/nvim/plugged/vim-gutentags/autoload/gutentags/ctags.vim line 62
After jumping to lib/reference/metadata.rb using <c-]>. Note: vim says the path to this file is ~/proj/memex/lib/reference/metadata.rb, which is longer than I expected.
tags=~/config/nvim/gutentags/Users-tom-proj-memex-tags,./tags;,tags
Last set from ~/config/nvim/plugged/vim-gutentags/autoload/gutentags/ctags.vim line 62
After jumping back to lib/reference/template.rb with <c-o>. Note: "Last set from" is not present in the output.
tags=./tags;,tags
I think I've found the culprit. b:undo_ftplugin within vim-ruby is responsible for resetting the tags option. I don't know why or how it is being executed, but if I remove "tags=" from there it fixes the problem. I'll open an issue with vim-ruby to see if it can be fixed there (edit: opened vim-ruby issue).
You might want to also consider adding the ability for Gutentags to rerun setlocal tags^=... in situations like this. Feel free to close this issue if you want to.
After reading Tim Pope's comment, it seems that resetting the local tags option from a filetype plugin could be a common practice, in which case it makes sense to handle this in Gutentags.
I'm now working around this issue with a function that puts missing paths back into tags whenever the filetype changes. You can get it here: https://github.com/tomdalling/config/blob/a8712d2d4fdbd8484140f4010142b7a09806bb48/nvim/after/plugin/gutentags.vim
Ah thanks for the link to that comment. That makes sense. I've added Tim's recommended fix to my todo list but obviously if someone wants to take a crack at it I'd be grateful!
is gutentags still maintained? finding this to still be an issue