c++ - YouCompleteMe 和 C++ 诊断不当错误

标签 c++ c++11 vim exuberant-ctags juce

我正试图让 YCM 在 Vim 中工作以进行 C++ 开发。我正在使用 JUCE 框架。 Ctags 和自动完成功能运行良好。但是,我在“装订线”中出现了很多错误的错误,如红色箭头所示。

例如

no matching member function for call to 'addAndMakeVisible'

addAndMakeVisible 是继承类 Component 的函数时甚至出现在自动完成中。

还会出现如下错误:

cannot initialize object parameter of type 'juce::Component' with an expression of type 'MyComponent'

我的.ycm_extra_conf.py:https://gist.github.com/adamski/a793a24b026f68a1074e 我正在添加具有绝对路径的 JUCE 库以及本地项目版本,并从@ladislas 示例中复制了建议。

:YCMDebugInfo 的输出 https://gist.github.com/adamski/2e7dd79b45d0fb6f5010#file-ycmdebuginfo

:YCMDiags 的当前输出 https://gist.github.com/adamski/8fad8e0724a03854912b

重现问题的示例存储库:https://github.com/adamski/juce-chapter02-07

我的 .vimrc 看起来像:

"" YouCompleteMe options
"
let g:ycm_register_as_syntastic_checker = 0 "default 1
"let g:Show_diagnostics_ui = 1 "default 1
"
""will put icons in Vim's gutter on lines that have a diagnostic set.
"Turning this off will also turn off the YcmErrorLine and YcmWarningLine
""highlighting
set tags=./tags,tags;
set autochdir
let g:ycm_enable_diagnostic_signs = 1
let g:ycm_enable_diagnostic_highlighting = 1
let g:ycm_always_populate_location_list = 1 "default 0
let g:ycm_open_loclist_on_ycm_diags = 1 "default 1
let g:ycm_seed_identifiers_with_syntax = 1

let g:ycm_complete_in_strings = 1 "default 1
let g:ycm_collect_identifiers_from_tags_files = 1 "default 0
let g:ycm_path_to_python_interpreter = '' "default ''


let g:ycm_server_use_vim_stdout = 0 "default 0 (logging to console)
let g:ycm_server_log_level = 'info' "default info


let g:ycm_global_ycm_extra_conf = '~/.ycm_extra_conf.py'  "where to search for .ycm_extra_conf.py if not found

let g:ycm_confirm_extra_conf = 1

let g:ycm_goto_buffer_command = 'same-buffer' "[ 'same-buffer', 'horizontal-split', 'vertical-split', 'new-tab' ]
let g:ycm_filetype_whitelist = { '*': 1 }
let g:ycm_key_invoke_completion = '<C-Space>'

nnoremap <F11> :YcmForceCompileAndDiagnostics <CR>

最佳答案

正如@FDinoff 指出的那样,每个 .ycm_extra_conf.py 都需要针对自己的项目进行定制。

为了给你一个可能对你有帮助的例子,这是我的例子:.ycm_extra_conf.py

因为我将所有库放在项目根目录的 ./lib 目录中,所以我编写了一个小脚本来自动扫描目录并将库添加为标志。

你可以读一下line 57 :

  for path, dirs, files in os.walk(libDir):
    for d in dirs:
      flag = '-I' + os.path.join(path, d)
      flags.append(flag)

libDir 已定义 line 4

这是原始项目:Moti

编辑 - 12/02/2014 -

我在你的树输出中没有看到 .ycm_extra_conf.py。此文件应位于项目的根目录中。

您也可以尝试为您的标志使用绝对路径。

:YcmDebugInfo 的输出应如下所示:http://pastebin.com/WARSUiML

你可以查看我配置 YCM 的 .vimrc : Link to YCM Conf .尝试使用我的而不使用你的,看看会发生什么。

关于c++ - YouCompleteMe 和 C++ 诊断不当错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27219433/

相关文章:

c++ - TBB parallel_for:为什么 Body::operator() 参数不是 const?

c++ - 无法调用构造函数(模板-模板参数)

regex - 在 vim 的正则表达式引擎中,为什么有些元字符会被转义而有些则不会?

c++ - bool 与非 bool 运算符的行为

c++ - 构造函数在 C++ 和/或 C++11 中是线程安全的吗?

c++ - 启动线程导致 abort()

c++ - decltype 声明函数返回类型的参数(无自动)

googlecl 使用的 vimrc 自定义

Java (Eclim + Vim) "system.out.print"不工作

c++ - OpenMP:从上到下的文本