ludovicchabant / vim-gutentags

A Vim plugin that manages your tag files
https://bolt80.com/gutentags/
MIT License
2.29k stars 175 forks source link

gutentags_cache_dir not working #109

Open ghost opened 7 years ago

ghost commented 7 years ago

Hi!

First of all I want to thank you for the great vim plugin! Recently I have started to use vim-gutentags together with Universal Ctags on rails projects. It works like a charm until I try to move tags file content to the gutentags_cache_dir. I am using latest MacVim with latest vim on macOS Sierra installed via brew. Here is the sequence to reproduce the bug:

  1. Create new rails project
  2. Scaffold some model and controller
  3. Go to contoller and press Ctrl+] on model name
  4. Jump back via Ctrl+t
  5. Try to repeat step 3
  6. No tags file and tag not found: SomeTag

:GutenTagsUpdate! takes no effect

Any tips how can I debug this issue or what should I check in my vim configuration? Thanks in advance.

ludovicchabant commented 7 years ago

Hi!

You can turn on debug tracing with let g:gutentags_trace = 1. You will see a bunch of debug output in Vim that tells you what Gutentags is doing. The tags generation script will also leave a log file behind to tell you what it did.

I can't think of any reason for your problem, except maybe some plugin (Gutentags or otherwise, or even your own vimrc) incorrectly settings the &tags settings in your buffer -- i.e. the tags files are there but someone is telling Vim to look elsewhere. You could check by running :echo tagfiles() between each step.

dweidner commented 7 years ago

I have the same problem. :set tags? returns the correct tag files tags=~/.cache/gutentags/Users-username-Sites-project-tags,./tags,tags. The command :echo tagfiles() returns [] though. I think the reason is, that the cached tagfile does not exist within the directory structure of the current project (~/Sites/project). If I create an empty tag file in the project root echo tagfiles() is picking it up correctly ['tags']. I am using the latest version of MacVim on macOS 10.12.3.

ahmedelgabri commented 7 years ago

I have the same problem & @dweidner solution worked by creating an empty tag file. But it's not practical of course, so any update on this?

ludovicchabant commented 7 years ago

No updates -- I'm not sure how to reproduce this bug, everything I tried so far works as expected on my machine.

Please note however that :echo tagfiles() is supposed to return an empty array if none of the files specified by tags actually exist... so I assume that creating an empty tags file would get you rid of the "No tags file" error, but would still get you the "tag not found: SomeTag" error and prevent you from navigating anywhere.

The question really is why isn't Gutentags producing the file it's suppposed to produce (which is ~/.cache/gutentags/Users-username-Sites-project-tags in @dweidner's case for instance). If you were to check, I assume this file wouldn't exist... but Gutentags is supposed to create it. If you follow the instructions I gave earlier about setting g:gutentags_trace = 1, you will be able to read some logs and figure out what's going on there hopefully.

ahmedelgabri commented 7 years ago

So here is what I get when I add g:gutentags_trace = 1 & this is my settings

let g:gitroot = substitute(system('git rev-parse --show-toplevel'), '[\n\r]', '', 'g')
if g:gitroot !=# ''
  let g:gutentags_cache_dir = g:gitroot .'/.git/tags'
else
  let g:gutentags_cache_dir = $HOME .'/.cache/guten_tags'
endif
let g:gutentags_exclude_project_root = ['/usr/local', $HOME]
let g:gutentags_file_list_command = {
      \ 'markers': {
      \ '.git': 'git ls-files',
      \ },
      \ }
let g:gutentags_resolve_symlinks = 1
let g:gutentags_generate_on_missing = 1
let g:gutentags_generate_on_new = 1
let g:gutentags_generate_on_write = 1
let g:gutentags_trace = 1
zsh:1: no such file or directory: /Users/ahmed/Sites/dev/projectname/.git/tags/Users-ahmed-Sites-dev-projectname-tags.log
gutentags:
Press ENTER or type command to continue

If I create the folder myself .git/tags it works fine, otherwise it doesn't.

ludovicchabant commented 7 years ago

Could it be just a matter of the output directory not existing? Can you just create the /Users/ahmed/Sites/dev/projectname/.git/tags directory and try again?

On a related note, the gutentags_cache_dir is supposed to be set globally, not really per-project. If you want to put a project's tags file somewhere else than at the root, I believe you can set the buffer variable b:gutentags_ctags_file to any path and it would work (you can do that in, say, a BufRead command). In your case you can set it relative to the project root, i.e. setting b:gutentags_ctags_file to .git/tags/my-custom-tags for instance.

ahmedelgabri commented 7 years ago

Could it be just a matter of the output directory not existing? Can you just create the /Users/ahmed/Sites/dev/projectname/.git/tags directory and try again?

I already mentioned that doing this will make it work fine yes.

On a related note, the gutentags_cache_dir is supposed to be set globally, not really per-project. If you want to put a project's tags file somewhere else than at the root, I believe you can set the buffer variable b:gutentags_ctags_file to any path and it would work (you can do that in, say, a BufRead command). In your case you can set it relative to the project root, i.e. setting b:gutentags_ctags_file to .git/tags/my-custom-tags for instance.

The only reason I have this

let g:gitroot = substitute(system('git rev-parse --show-toplevel'), '[\n\r]', '', 'g')
if g:gitroot !=# ''
  let g:gutentags_cache_dir = g:gitroot .'/.git/tags'
else
  let g:gutentags_cache_dir = $HOME .'/.cache/guten_tags'
endif

Is that the plugin will generate tags files everywhere even for none VCS folders, I'd prefer to have my tags files inside the .git/ folder & for other scenarios just put them in the .cache.

So I wonder if I do what you are saying will this generate two tags files? one in root & one inside .git/tags for example or how will it work?

ludovicchabant commented 7 years ago

I already mentioned that doing this will make it work fine yes.

Ah yes, sorry, I got confused between the name of the directory and the name of the tags file.

Do you use any plugin loader like Pathogen or Vundle or something? In theory, when Gutentags loads, it checks if the cache directory is set and, if it is, it checks that it exists -- and creates it if it doesn't (see these lines of code).

So I'm suspecting something where the plugin is loaded before your Vimrc runs that code that sets the cache directory... which means you either need to set the cache directory before, or you need to make sure the directory exists yourself.

So I wonder if I do what you are saying will this generate two tags files? one in root & one inside .git/tags for example or how will it work?

Gutentags should first look at the buffer local value, and if not set, it would look at the global/default value. So it wouldn't create 2 tags files, no.

arashm commented 6 years ago

I have the same problem. But for some reason this does not effect Tagbar. Tagbar uses ctags too and it doesn't seem to have any problem loading them. When I enter echo tagfiles() in a Tagbar pane I get ['/home/arashm/.tags_cache/home-arashm-workspace-Web-Ruby-sth-project-tags'] while entering the same command in a regular pane (with a ruby file open) returns []. I wonder what happens in Tagbar pane that doesn't happen in other panes.

d4em0n commented 6 years ago

same issue here, tags generate to cache, but not set tagfiles. but, if i set tags file manually using set tags+=/path/to/cache/tags it's works. Using let g:gutentags_trace=1 output like this

gutentags: ['Locking tags file...', '']
gutentags: ['Running ctags on whole project', 'ctags -f "/home/ramdhan/.cache/vim/tags/home-ramdhan-ctf-tools-gef-tags.temp"  --options=/home/ramdhan/repo_git/vim-gutenta
gs/res/ctags_recursive.options --fields=+l --c-kinds=+p --c++-kinds=+p --sort=no --extras=+q --exclude=.git --exclude=.hg --exclude=.svn --exclude=.stversions --exclude=*
.pyc --exclude=*.spl --exclude=*.o --exclude=*.out --exclude=*~ --exclude=\%* --exclude=*.jpg --exclude=*.jpeg --exclude=*.png --exclude=*.gif --exclude=*.zip --exclude=*
*/tmp/** --exclude=*.DS_Store --exclude=**/node_modules/** --exclude=**/bower_modules/** --exclude=*/.sass-cache/* --exclude=application/vendor/** --exclude=**/vendor/cke
ditor/** --exclude=media/vendor/** --exclude=__pycache__ --exclude=*.egg-info "/home/ramdhan/ctf/tools/gef"', '']
gutentags: ['Replacing tags file', 'mv -f "/home/ramdhan/.cache/vim/tags/home-ramdhan-ctf-tools-gef-tags.temp" "/home/ramdhan/.cache/vim/tags/home-ramdhan-ctf-tools-gef-t
ags"', '']
gutentags: ['Unlocking tags file...', '']
gutentags: ['Done.', '']
gutentags: Finished ctags job.
Switching off verbose output.

when i echo tagfiles() it's return an empty array

ludovicchabant commented 6 years ago

Do you have g:gutentags_ctags_auto_set_tags somehow set to 0 ?

In theory, Gutentags adds the tag file to Vim's tags on this line.

Note how it uses setlocal because you could have different files open that belong to different projects -- or even belong to no project in particular.

ticklemynausea commented 3 years ago

I believe this symptom may be due to the issue discussed in https://github.com/ludovicchabant/vim-gutentags/issues/289