Wednesday, January 30, 2013

Re: ctags processing jumps to wrong tag?

/* this function prototype spreads multiple lines, so there is no terminating
* ; character on the first line, so the tag definition is the same as the
* function definition
*/
int func1(
void);

/* this function prototype is all on a single line, so there is an obvious
* difference (the terminating ; character) in the tags file
*/
int func2(void);

int func1(
void)
{
return 1;
}

int func2(void)
{
return 2;
}
On Tuesday, January 29, 2013 10:48:00 AM UTC-6, Ben Fritz wrote:
> I generate CTags for C code with the following:
>
> " -R : recursive
> " --extra=+f : include file name as a tag
> " --fields=+S : include signature (e.g. parameter list)
> " K : include kind of tag as full name
> " -k : not kind of tag as single letter
> " --totals : print on standard output total number of tags, etc.
> " --c-kinds=+p : include function prototype in C code
> let ctags_command=Tlist_Ctags_Cmd.' -R --extra=+f --fields=+SK-k --totals --c-kinds=+p .'
>
> I have 'cscopetag' set, so that pressing CTRL-] on a tag name with multiple matches will prompt me before jumping.
>
> When I CTRL-] on a function name, I usually get 2 hits, one for the prototype, the other for the function. If both are in the same file, choosing either hit will jump to the prototype always.
>
> Does anyone else see this issue? Am I doing something wrong?

After some investigation, the root cause is that ctags by default uses
a search pattern for the tag location. Thus when a function prototype
and definition are spread over multiple lines, and the first line is
the same for each, the tag location in the generated tags file uses an
identical pattern.

This is somewhat documented (but not explicitly):

http://ctags.sourceforge.net/ctags.html#CAVEATS

I see three ways to fix this:

1. Modify the file to force a difference between the prototype and
function definition. Not really an option, files I edit are under
strict change control and this would be a fairly pointless edit.
2. Move the prototypes into a header file. Not an option for the same
reason as (1), and because the problem occurs mostly for "private"
helper functions scoped to the file itself using the static keyword.
3. Generate tags using line numbers as locations, by adding
--excmd=number to my ctags options. I don't like this method because
then jumping to tags with an older tags file will miss frequently if
the file has changed.

Is there some unknown fourth option without the drawbacks of (3) that
does not involve modifying the file itself? Just generating tags for
prototypes using line numbers but using patterns for the rest of the
tags would be a decent compromise, but I'm not sure how I'd accomplish
that (if it's even possible).

See attached test C file and generated tags file demonstrating this problem.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: