emacscedet

emacs cedet "semantic-analyze-proto-impl-toggle" can't jump to suitable implement


after read a great article called "A Gentle Introduction to CEDET" that written by Alex Ott . I do some experiment for c++ projects in my emacs 24.3 and latest cedet in "https://git.code.sf.net/p/cedet/git" (also in emacs 23.1 and stable cedet1.1). I am quite satisfied with it except for one small "jump to function implement" issue in "semantic-analyze-proto-impl-toggle". my project is very simple(only 2 files):

1) head file "y.hpp" in dir "~/emacs/test/zz1/"

  class y{
     public:
       int y1(int);//error here! semantic can't found implement in y.cpp
};

2) implement file "y.cpp" in dir "~/emacs/test/zz2/"

   #include "y.hpp"
   int y::y1(int b) // semantic can found definition in y.hpp
    {
     return 0;
    }

my cedet config is based on alex oot 's "minimial-cedet-config.el"(https://gist.github.com/alexott/3930120) and only add following two lines:

(semantic-add-system-include "~/emacs/test/zz1/" 'c++-mode)

(semantic-add-system-include "~/emacs/test/zz2/" 'c++-mode)

i checked my semantic db cache and found all db file is create correctly, this is part info in cache db for y.hpp in zz1:

  ("y1" function
                       (:prototype-flag t
                        :arguments 
                          ( ("" variable (:type "int") (reparse-symbol arg-sub-list) [27 31]))                          
                        :type "int")
                        (reparse-symbol classsubparts) [20 32])

this is part info in cache db for y.cpp in zz2:

("y1" function
               (:parent "y"
                :arguments 
                  ( ("b" variable (:type "int") (reparse-symbol arg-sub-list) [28 34]))                  
                :type "int")
                nil [18 50])

Solution

  • after i got the suggestion from Eric Ludlam . I believe the problem is that Semantic doesn't know these two files belong to the same project. System header trick might help in one direction but not bi-directionally.

    The way to teach it that it belongs in the same project is to enable EDE, then make sure there is an EDE project there, such as using the 'ede-cpp-root' project type, like this:

    ;; make sure fname exists**

    (ede-cpp-root-project "TEST" :file "~/emacs/test/fname" :include-path '("/zz1" "/zz2" ) )

    Since you already have

    (ede-enable-generic-projects)

    you could also just put stick everything in git or CVS and it will discover it as a project. Then customize-project and add include paths to make sure it can find everything.

    Once you start using EDE projects to specify project roots, semantic will have much better support for its navigation and completion systems.

    and we don't need following two lines anymore :

    (semantic-add-system-include "~/emacs/test/zz1/" 'c++-mode)

    (semantic-add-system-include "~/emacs/test/zz2/" 'c++-mode)