YouCompleteMe set flags for filetype

3

1

let g:syntastic_c_compiler = 'clang'
let g:syntastic_c_compiler_options = ' -ansi -pedantic'
let g:syntastic_cpp_compiler = 'clang++'
let g:syntastic_cpp_compiler_options = ' -std=c++11 -stdlib=libc++ -pedantic

That was easy, wasn't it? How do I do the same thing with Valloric's YouCompleteMe? The "User Guide" suggests to have a seperate configuration file in each project, and manually edit the flags - which is ridiculous. How can I change the flags based on the filetype in my .ycm_extra_conf.py? My attempt:

  1 
  2 def FlagsForFile(filename, **kwargs):
  3     flags = [
  4             '-Wall',
  5             '-Wextra',
  6             '-Werror',
  7             '-pedantic'
  8     ]
  9     data = kwargs['client_data']
 10     filetype = data['&filetype']
 11     if filetype == 'c':
 12         flags += ['-ansi']
 13     elif filetype == 'cpp':
 14         flags += ['-std=c++11']
 15         flags += ['stdlib=libc++']
 16     return {
 17         'flags': flags,
 18         'do_cache': True
 19     }  

Zach

Posted 2014-11-23T06:56:58.827

Reputation: 31

Where and what did you set kwargs to? – FDinoff – 2014-11-24T14:41:33.323

Answers

1

Nothing in the python looks wrong. The only thing you probably forgot was to set

let g:ycm_extra_conf_vim_data = ['&filetype']

in your vimrc. This tells YouCompleteMe to pass the filetype to the function. Otherwise kwargs is just empty and you probably fall through the if statements without adding anything.

FDinoff

Posted 2014-11-23T06:56:58.827

Reputation: 1 623