Code Monkey home page Code Monkey logo

Comments (13)

bsmith89 avatar bsmith89 commented on May 22, 2024

Okay, I'm learning more about the plugin and I see that it's not just running ctags at the project root. My trace output:

gutentags: Running: !/Users/bjsmith/Projects/dotfiles/home/.vim/bundle/vim-gutentags/plat/unix
/update_tags.sh -e "ctags" -t "/Users/bjsmith/.vim/bundle/vim-gutentags/tags" -p "/Users/bjsmi
th/.vim/bundle/vim-gutentags" > "/Users/bjsmith/.vim/bundle/vim-gutentags/tags.log" 2>&1 &
gutentags: In:      /Users/bjsmith/.vim/bundle/vim-gutentags
:!/Users/bjsmith/Projects/dotfiles/home/.vim/bundle/vim-gutentags/plat/unix/update_tags.sh -e
"ctags" -t "/Users/bjsmith/.vim/bundle/vim-gutentags/tags" -p "/Users/bjsmith/.vim/bundle/vim-
gutentags" > "/Users/bjsmith/.vim/bundle/vim-gutentags/tags.log" 2>&1 &
gutentags:

from vim-gutentags.

ludovicchabant avatar ludovicchabant commented on May 22, 2024

Hey, sorry I'm catching up with the issues here that I've neglected these past few weeks.

Gutentags is not running ctags in the project root because it's possible to have Gutentags "hide" the tags files away in a temp folder. This means the tags file is in a folder unrelated to the project root, but contains relative paths to the project's code files, so when you want to navigate to a tag, there's a good chance (depending on Vim's current working directory) that the file won't open. And using the --tag-relative gives ugly ../../../foo/bar paths... maybe there's a magical combination of parameters that works, but I haven't found it so far.

So instead, Gutentags just runs ctags wherever and passes absolute paths to both the project directory and the tags file.

However, I just added with cff4176 the ability for Gutentags to look for a .ctags file in the project root, and if it exists, pass it to ctags through the --options parameter. This seems to work as expected... re-open the issue if it causes problems. Thanks!

from vim-gutentags.

madssj avatar madssj commented on May 22, 2024

For some reason the .ctags file doesn't work as expected on OS X. Observe the following:

# no .ctags file exists
$ ctags -R --options=.ctags README.md
ctags: cannot open option file ".ctags" : No such file or directory
# now make the file, and observe the same error
$ touch .ctags
$ ctags -R --options=.ctags README.md
ctags: cannot open option file ".ctags" : No such file or directory
# moving the file into another name, will fix the problem
$ mv .ctags .gutentagsoptions
$ ctags -R --options=.gutentagoptions  README.md
$ ctags --version
Exuberant Ctags 5.8, Copyright (C) 1996-2009 Darren Hiebert
  Compiled: Mar 16 2015, 23:48:18
  Addresses: <[email protected]>, http://ctags.sourceforge.net
  Optional compiled features: +wildcards, +regex

Reading the man page for ctags it has a section about FILES which lists .ctags as a special file. So in order to get this to work properly, I think you need to rename your version to .gutentagsoptions or something which ctags doesn't use itself.

On a Linux box, I get a Permission denied error.

Does this work for anyone, with the .ctags options file?

from vim-gutentags.

ludovicchabant avatar ludovicchabant commented on May 22, 2024

Interesting, I didn't know that... but it does work for me on OS X if ctags is not run from the same directory as the project. So:

cd myproject
ctags -R --options=.ctags .

...will indeed give me the errors you mentioned. But if I do:

cd ..
ctags -R -f myproject/tags --options=myproject/.ctags myproject

...then it works as expected.

Since Gutentags doesn't run ctags from the project root, I guess that's what makes it work... although hopefully that behaviour is the same across all platforms.

from vim-gutentags.

madssj avatar madssj commented on May 22, 2024

Indeed it does. I haven't checked, but I recall reading somewhere else, that gutentags runs ctags from the project dir sometimes?

Not running ctags from the directory makes using relative excludes not work, so do you have any thoughts for handling those?

from vim-gutentags.

ludovicchabant avatar ludovicchabant commented on May 22, 2024

Gutentags will run ctags from the project directory if you didn't specify any g:gutentags_cache_dir (i.e. the tags file will be at the root of your project instead of "hidden away" in a cache folder).

Mmmh but yeah, indeed that's a downside of the current approach. Unless I'm missing something, I can't figure out a combination of options and current directories that will make it work as expected for relative excludes when using "hidden" tags files (but it should work when no g:gutentags_cache_dir is defined)... maybe in that case I need to generate the tags file with absolute paths in the project root, and move it at the end to the cache directory...?

from vim-gutentags.

madssj avatar madssj commented on May 22, 2024

Would the following work?

  • Always run from the project directory, use absolute paths to output files
  • Rename the options file to something else, which is not used by ctags internally

from vim-gutentags.

ludovicchabant avatar ludovicchabant commented on May 22, 2024

Well I tried a few more combinations but I'm now running into the original bug you had but even when specifying the full project path. Even if I don't specify --options, ctags seems to skip my .ctags. This all seems awfully brittle, and tells me that, indeed, using a custom options filename may actually be safer... :(

The other problem is that it seems impossible to have both absolute paths in the tags file and relative exclude rules in the options file. It looks like the exclude rules are run against the same paths as what you'll get, so if you want absolute paths, the rules will run against absolute paths. Argh!

And using relative paths only works if the tags file is at the project root anyway -- this is because Vim will combine any relative paths with the directory of the tags file. And using --tag-relative is not super cool because it makes all your paths start with ../../../../.. or something.

from vim-gutentags.

madssj avatar madssj commented on May 22, 2024

I made a test repository so we have something more concrete to go from.

If you look at the crudely named correcttags file there, you'll see that it doesn't have any of said dot-paths, but that they are indeed just relative from the project root. That was archived by running ctags from the project directory, and that makes using relative excludes (for example) work fine.

We can rule out being able to use, or even have a file called .ctags as just having that file causes ctags to stop working, as we've both verified.

It seems, that the only viable way to fix this, would be to rename the options file. ctags itself is not going to be fixing that, so it'll have to be worked around, and always running ctags from the project root dir.

The reason for having absolute paths, would be to enable having the tags file outside the project root, and because it enables vim to then reference those files, so it wouldn't work having a tags file with relative (to the project dir) paths outside the project root, right?

from vim-gutentags.

ludovicchabant avatar ludovicchabant commented on May 22, 2024

That's right, the tags file must have absolute paths to make it possible to store it outside of the project root. However, ctags sadly ties this together with its "exclude" rules, so we can't have both that and relative exclude rules.

So either you need to disable Gutentags' cache directory and keep your tags files at project roots (that's sad), or we need to get creative... for instance, now that Gutentags will be looking for a custom options file (say, .gutentagsoptions), we can do some processing on it. I don't know how error-prone it would be, but it's definitely possible to look for any line starting with --exclude in it, and if the value contains a slash, make it absolute, store that as a "processed options file" in the cache directory, and tell ctags to use that. Basically transform all relative exclude paths in the custom options file to be absolute. It wouldn't be too much work IMHO.

from vim-gutentags.

madssj avatar madssj commented on May 22, 2024

I feel like most magic should be avoided where possible, but I can't really come up with anything other that processing the file to add absolute paths.

from vim-gutentags.

ludovicchabant avatar ludovicchabant commented on May 22, 2024

Ok I finally had some free time to do this, see 3e2a65a. I'm expecting some side effect bugs with this so make sure to open new bugs for that, thanks !

from vim-gutentags.

madssj avatar madssj commented on May 22, 2024

Excellent!

It'll be a little while before I can tinker with it though.

from vim-gutentags.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.