YouCompleteMe and C++ diagnostics inappropriate errors

3.7k views Asked by At

I'm trying to get YCM working in Vim for C++ development. I'm using the JUCE framework. Ctags and autocompletion are working great. However, I'm getting lots of wrong errors come up in the 'gutter' as red arrows.

E.g.

no matching member function for call to 'addAndMakeVisible'

when addAndMakeVisible is a function of an inherited class Component and even comes up in the autocomplete.

Also getting lots of errors like the following:

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

My .ycm_extra_conf.py: https://gist.github.com/adamski/a793a24b026f68a1074e I am adding the JUCE libraries with absolute path as well as the local project version, and copied suggestion from @ladislas example.

Output of :YCMDebugInfo https://gist.github.com/adamski/2e7dd79b45d0fb6f5010#file-ycmdebuginfo

Current output of :YCMDiags https://gist.github.com/adamski/8fad8e0724a03854912b

example repository that recreates the problem: https://github.com/adamski/juce-chapter02-07

My .vimrc looks like:

"" 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>
3

There are 3 answers

7
ladislas On BEST ANSWER

As @FDinoff pointed out, every .ycm_extra_conf.py needs to be tailored for its own project.

To give you an example that might help you, here is mine : .ycm_extra_conf.py

Because I put all my libs inside a ./lib directory at the root of my projects, I've made a little script to automatically scan the directories and add the libraries as flags.

You can read it 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 is defined line 4

And here is the original project: Moti

EDIT - 12/02/2014 -

I don't see the .ycm_extra_conf.py in your tree output. This file should be at the root of your project.

Also you can try using absolute path for your flags.

The output of :YcmDebugInfo should look like that : http://pastebin.com/WARSUiML

You can check my .vimrc where I configure YCM : Link to YCM Conf. Try using mine without yours to see what happens.

1
Samuel Gaehwiler On

For me YouCompleteMe works great in conjunction with JUCE without the false errors you're describing.

I have copied the .ycm_extra_conf.py from my current project to the opensource predecessor for you where YCM also works as expected.

Get it from https://github.com/klangfreund/LUFSMeter . Either YCM works as expected (Somthing is wrong with your project) or it doesn't (Something is wrong with you installation of YCM).

0
Adamski On

I installed the XCode update to 6.11, and it now seems to be working as expected. Thanks to @ladislas and @Samuel Gaehwiler for the help and pointers.