ludovicchabant / vim-gutentags

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

Partial support for g:gutentags_ctags_extra_args #191

Closed CatalinGB closed 6 years ago

CatalinGB commented 6 years ago

Hello,

Autosar uses for C development certain compiler abstraction macros like:

#define FUNC(rettype, memclass)

One way to generate a correct tags file is to call ctags with -D "FUNC(rettype, memclass) memclass rettype"

When I try to use let g:gutentags_ctags_extra_args += '-D FUNC' everything is working as expected.

More complex macro definitions need to be surrounded by quotes like in the case of -D "FUNC(rettype, memclass) memclass rettype".

In ctags.vim:137 when calling shellescape the double quotes are escaped ending with -D ""FUNC(rettype, memclass) memclass rettype"" which cannot be interpreted by ctags.

The name of the parser: universal-ctags

The content of input file:

#include <stdio.h>

#define FUNC(rettype) rettype

FUNC(int) fnct(int a);
FUNC(int) fnct(int a)
{
  return a;
}

int main(void)
{
  int a = 1;
  printf("%d\n", fnct(a));
}

The tags output you are not satisfied with(ctags main.c):

!_TAG_FILE_FORMAT   2   /extended format; --format=1 will not append ;" to lines/
!_TAG_FILE_SORTED   1   /0=unsorted, 1=sorted, 2=foldcase/
!_TAG_OUTPUT_MODE   u-ctags /u-ctags or e-ctags/
!_TAG_PROGRAM_AUTHOR    Universal Ctags Team    //
!_TAG_PROGRAM_NAME  Universal Ctags /Derived from Exuberant Ctags/
!_TAG_PROGRAM_URL   https://ctags.io/   /official site/
!_TAG_PROGRAM_VERSION   0.0.0   /96d39e4/
FUNC    main.c  /^#define FUNC(/;"  d   file:
fnct    main.c  /^FUNC(int) fnct(int a)$/;" f   typeref:typename:int
main    main.c  /^int main(void)$/;"    f   typeref:typename:int

The tags output you expect(ctags -D "FUNC(rettype) rettype" main.c):

!_TAG_FILE_FORMAT   2   /extended format; --format=1 will not append ;" to lines/
!_TAG_FILE_SORTED   1   /0=unsorted, 1=sorted, 2=foldcase/
!_TAG_OUTPUT_MODE   u-ctags /u-ctags or e-ctags/
!_TAG_PROGRAM_AUTHOR    Universal Ctags Team    //
!_TAG_PROGRAM_NAME  Universal Ctags /Derived from Exuberant Ctags/
!_TAG_PROGRAM_URL   https://ctags.io/   /official site/
!_TAG_PROGRAM_VERSION   0.0.0   /96d39e4/
FUNC    main.c  /^#define FUNC(/;"  d   file:
fnct    main.c  /^FUNC(int) fnct(int a)$/;" f
main    main.c  /^int main(void)$/;"    f   typeref:typename:int

The version of ctags:

$ ctags --version
Universal Ctags 0.0.0(96d39e4), Copyright (C) 2015 Universal Ctags Team
Universal Ctags is derived from Exuberant Ctags.
Exuberant Ctags 5.8, Copyright (C) 1996-2009 Darren Hiebert
  Compiled: Jun  7 2018, 22:00:50
  URL: https://ctags.io/
  Optional compiled features: +wildcards, +regex, +iconv, +option-directory

How do you get ctags binary: Building it locally and win32 binary taken from Universal-ctags/ctags-win32 project

ludovicchabant commented 6 years ago

Hi!

If you want to do more complex argument passing, you should either:

This way you won't run into shell escaping problems, which can get quite hairy quite fast.

For more info, read the docs on ctags options files, and on .gutctags files in Gutentags.

CatalinGB commented 6 years ago

Hi!

Thanks for the reply :)

I've tried with .gutctags and after a bit more struggle I get it to work. The catch is to add options separated by new line and with no double quotes like so:

cat .gutctags
-D FUNC(ret) ret
ludovicchabant commented 6 years ago

Cool, good to know, thanks!