Question

When I generate my ctags file, it seems to be parsing content inside comments too. For instance, using Vim's plugin Tagbar, I can see in the list of functions non-existent functions such as:

  • is
  • in
  • just

What is happening here is that ctags is going into comments and finding things like:

"This function is...", thinking that "is" is a function, it is then adding an entry for it in the tags file.

I am wondering if there is an easy way to tell ctags not to parse contents inside comments.

I have found that apparently there was a fix for this to be released after 5.8.0 but I am not sure whether this has already been released or not, my ctags version is 5.8.0.

This is related to a PHP project but I guess it would be nice if the answer can cover a solution that would work for any programming language (if such a thing is possible).

Example:

The following comment to a function generates the tag "is" and lists it as a function:

/**
 * This function is run to set certain preferences
 */
Was it helpful?

Solution

There's a bug in ctags 5.8. Fortunately, one day after it was released, jafl committed revision 729 to fix the problem. Unfortunately, there has not been a release since then.

Fortunately, the project has been forked as "Universal Ctags." Here's how to install that from source.

# Get rid of 5.8.
sudo apt-get remove exuberant-ctags

# autoconf is needed to assemble the configure files
sudo apt-get install autoconf autoconf-doc

git clone https://github.com/universal-ctags/ctags.git universal-ctags

cd universal-ctags

./autogen.sh
./configure
make

sudo make install

OTHER TIPS

Exuberant Ctags has a large variety of languages already built into it. Each of these has a custom parser tailored to that language. Of course, it doesn't make sense to include comments / commented-out sections of code in the tags file. If that happens, it is a bug in the language's parser and must be fixed in the ctags code.

Note that Exuberant Ctags also supports extension to new languages via regular expressions. With these, it can be very difficult / slow / impossible to exclude comments (as there may be a large preceding context to consider, and the language syntax may not be fully representable as regexp), and you would have to live with this, or apply workarounds like preprocessing the comments out of the sources before processing them.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top