如何通过Company获得C / C ++上下文相关的完成功能?


11

Semantic 似乎能够做到这一点,但是我无法按预期实现它。例如,如果我#include "Type.h"和声明Type t,使用semantic-complete-analyze-inlinewhen point was after t.始终给我错误

找不到“类型t”的类型

而不是向我提供的所有公共(或其他适当方式)成员t

如何获得我在这里寻找的结果?理想情况下,我如何使用语义可能提供的任何东西作为公司的后端?


您确定Type.h存在,正在被发现并声明Type类型吗?如果我将Type.h和Type.cpp与Type.h放在同一个目录中,则声明一个Type带有字段int foo和的类char bar,则语义和公司即开即用。
J大卫·史密斯

您是否已验证company-backends变量company-semantic列表中是否包含变量?如果不是这样,您将希望在列表的第一行添加前缀,以便首先搜索到它
俗气的2014年

有趣的是,它与我描述的最小示例兼容。(不幸的是,我确实无法给出实际的用例,但这无关紧要。)我有什么方法可以强迫Semantic重新解析所有内容?
肖恩·艾瑞德

@JDavidSmith如何确保找到它?我实际使用的项目的构建结构非常复杂。
肖恩·艾瑞德

@cheezy company-semantic在里面company-backends;谢谢:)
肖恩·阿雷德

Answers:



0

您可能想要按照此处的教程进行设置,company-clang以获得更好的候选人。


0

首先,您需要初始化CEDET和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")

那么您可以使用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/"))
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.