12

Semantic seems to be able to do this, but I cannot get it to work as I would expect it to. For example, if I #include "Type.h" and declare Type t, using semantic-complete-analyze-inline when point is after t. consistently gives me the error

Cannot find types for `Type t'

instead of giving me all of the public (or otherwise appropriate) members of t.

How can I get the result I'm looking for here? Ideally, how can I use whatever Semantic might provide as a backend for Company?

Drew
  • 75,699
  • 9
  • 109
  • 225
Sean Allred
  • 6,861
  • 16
  • 85
  • Are you sure Type.h exists, is being found, and declares the type Type? If I make Type.h and Type.cpp in the same directory with Type.h declaring a class `Type` with fields `int foo` and `char bar`, semantic and company work out of the box. – J David Smith Nov 10 '14 at 19:35
  • Have you verified if `company-backends` variable has `company-semantic` in its list? If not, you'll want to add prepend it to the first of the list so that it's searched first – cheezy Nov 10 '14 at 20:26
  • Interestingly, it works with the minimal example I describe. (Unfortunately I really can't give the actual use case, but it shouldn't matter.) Is there any way I can force Semantic to reparse everything? – Sean Allred Nov 10 '14 at 20:56
  • @JDavidSmith How can I ensure it is being found? The project I'm actually working with is very complex in its build structure. – Sean Allred Nov 10 '14 at 21:01
  • @cheezy `company-semantic` is in `company-backends`; thanks :) – Sean Allred Nov 10 '14 at 21:02
  • Another option is using Company with Clang, [using this setup](http://tuhdo.github.io/c-ide.html#sec-5). – Tu Do Nov 11 '14 at 15:40
  • http://emacs.stackexchange.com/questions/474/using-emacs-as-a-full-featured-c-c-ide might help (http://emacs.stackexchange.com/questions/474/using-emacs-as-a-full-featured-c-c-ide#comment5549_644 is my preferred solution) – unhammer Nov 20 '14 at 11:34
  • See also the related post: http://emacs.stackexchange.com/questions/801/how-to-get-intelligent-auto-completion-in-c – Guillaume Papin Dec 06 '14 at 12:36
  • @GuillaumePapin I always overlooked `irony-mode` – not too sure why. If I can get it to work, I'll be tempted to close this as a duplicate. It doesn't give a solution to work with Semantic, but it gives a solution that achieves the same goal (or at least appears to). Thanks :) – Sean Allred Dec 06 '14 at 17:42

3 Answers3

1

You probably want to follow the tutorial here and setup company-clang to get better candidates.

expez
  • 381
  • 2
  • 8
1

I suggest using irony-mode with company-irony for completion instead of semantic as semantic is generally too slow and simplistic - ie. it often doesn't offer completions when you would think it should.

alexmurray
  • 281
  • 1
  • 5
0

First you need to initialize CEDET and ede

(global-ede-mode 1)
(add-to-list 'semantic-default-submodes 'global-semanticdb-minor-mode 1)
(add-to-list 'semantic-default-submodes 'global-semantic-idle-scheduler-mode 1)
(add-to-list 'semantic-default-submodes 'global-semantic-stickyfunc-mode 1)
(add-to-list 'semantic-default-submodes 'global-semantic-highlight-func-mode 1)
(add-to-list 'semantic-default-submodes 'global-semantic-idle-summary-mode t)
(add-to-list 'semantic-default-submodes 'global-semantic-idle-completions-mode t)
(add-to-list 'semantic-default-submodes 'global-srecode-minor-mode t)
(add-to-list 'semantic-default-submodes 'global-semantic-decoration-mode t)
(semantic-mode) ;; Active le mode semantic
(require 'stickyfunc-enhance) ;; multilines concatene dans la header line
(require 'cedet-cscope)

(require 'ecb)
(ede-cpp-root-project "projName"
                  :name "projName Project"
                  :file "~/workspaces/projName/proj.txt" ;; an arbitrary file
                  :include-path '("/src/main/src"
                                  "/src/main/include"
                                  "/src/test/src"
                                  "/src/test/include"
                                  ... )
                  :system-include-path '("/usr/include/ ~/workspaces/install/proj3/lib/ /usr/include/boost/")
                  :spp-table '(("isUnix" . "") ("BOOST_TEST_DYN_LINK" . "")))
;; cedet semantic
(semanticdb-enable-gnu-global-databases 'c-mode t)
(semanticdb-enable-gnu-global-databases 'c++-mode t)
;; You can add this to improve the parse of macro-heavy code:
(require 'semantic/bovine/c)
(add-to-list 'semantic-lex-c-preprocessor-symbol-file "/usr/lib/gcc/x86_64-redhat-linux/4.4.7/include/stddef.h")

then you can use company-c-headers (https://github.com/randomphrase/company-c-headers)

(require 'company-c-headers)
     (add-to-list 'company-backends 'company-c-headers)
     (add-to-list 'company-c-headers-path-system "/usr/include/c++/4.4.7/ /home/me/DEPEDENCIES/LIBXX/lib/ /home/me/DEPEDENCIES/LIBYY/lib /usr/include/boost/"))
djangoliv
  • 3,169
  • 16
  • 31