Search code examples
c++parsingctagsuniversal-ctags

Difficulty with Universal Ctags: Obtaining Fully Qualified C++ Scopes


I'm currently working on a C++ project and using Universal Ctags for code navigation. I'm facing difficulties obtaining fully qualified C++ scopes, including namespaces, classes, and functions.

Here's what I've tried so far:

Used the standard Universal Ctags command:

ctags --languages=c++ --fields=+n -R .

However, this command doesn't seem to capture the fully qualified scopes as expected.

The function I'm particularly interested in is declared and defined in the client.cpp file within a namespace and possibly a class.

Am I missing any specific flags or options in the Universal Ctags command? Could there be an issue with my code structure affecting the tagging process?

If anyone has experience with Universal Ctags and successfully obtained fully qualified C++ scopes, I would greatly appreciate your guidance and any tips to improve the tagging process.

Thank you!


Solution

  • Add --extras=+q or --extras=+{qualified} option to your command line like:

    $ cat /tmp/foo.cpp 
    class C {
        void method(void) {}
    };
    $ ctags --languages=c++ --fields=+n -R --extras=+q -o - /tmp/foo.cpp 
    C   /tmp/foo.cpp    /^class C {$/;" c   line:1  file:
    C::method   /tmp/foo.cpp    /^  void method(void) {}$/;"    f   line:2  class:C typeref:typename:void   file:
    method  /tmp/foo.cpp    /^  void method(void) {}$/;"    f   line:2  class:C typeref:typename:void   file: