tweekmonster / deoplete-clang2

MIT License
90 stars 17 forks source link

Exception during clang2.on_event for event 'Init': expected string or bytes-like object. #21

Open KristupasSavickas opened 6 years ago

KristupasSavickas commented 6 years ago

Hello, I've just installed deoplete_clang2 and I'm getting this error when trying to edit a .c file:

[deoplete] Traceback (most recent call last):                                                                                                                          
[deoplete]   File "/home/savickaskr/.vim/bundle/deoplete.nvim/rplugin/python3/deoplete/deoplete.py", line 473, in on_event                                             
[deoplete]     source.on_event(context)                                                                                                                                
[deoplete]   File "/home/savickaskr/.vim/bundle/deoplete-clang2/rplugin/python3/deoplete/sources/deoplete_clang2.py", line 151, in on_event                            
[deoplete]     cmd, flags = self.build_flags(context)                                                                                                                  
[deoplete]   File "/home/savickaskr/.vim/bundle/deoplete-clang2/rplugin/python3/deoplete/sources/deoplete_clang2.py", line 506, in build_flags                         
[deoplete]     db_flags = self.find_db_flags(context)                                                                                                                  
[deoplete]   File "/home/savickaskr/.vim/bundle/deoplete-clang2/rplugin/python3/deoplete/sources/deoplete_clang2.py", line 354, in find_db_flags                       
[deoplete]     ')\s*(\S+)', entry.get('command')):                                                                                                                     
[deoplete]   File "/usr/lib/python3.6/re.py", line 229, in finditer                                                                                                    
[deoplete]     return _compile(pattern, flags).finditer(string)                                                                                                        
[deoplete] TypeError: expected string or bytes-like object                                                                                                             
[deoplete] Exception during clang2.on_event for event 'Init': expected string or bytes-like object.  Use :messages for error details.  

My ~/.config/nvim/init.vim:

set number
set mouse=a
set background=dark

" NeoBundle settings
" Skip initialization for vim-tiny or vim-small.
if 0 | endif

if &compatible
  set nocompatible               " Be iMproved
endif

set runtimepath+=~/.config/nvim/bundle/neobundle/
call neobundle#begin(expand('~/.vim/bundle/'))
NeoBundleFetch 'Shougo/neobundle.vim'

" My Bundles here:
" Refer to |:NeoBundle-examples|.
NeoBundle 'airblade/vim-gitgutter'
NeoBundle 'scrooloose/nerdtree'
NeoBundle 'vim-airline/vim-airline'
NeoBundle 'vim-airline/vim-airline-themes'
NeoBundle 'tpope/vim-commentary'
NeoBundle 'google/vim-searchindex'
NeoBundle 'icymind/NeoSolarized'
NeoBundle 'Shougo/deoplete.nvim'
NeoBundle 'tweekmonster/deoplete-clang2'

call neobundle#end()

filetype plugin indent on

NeoBundleCheck

let g:gitgutter_enabled = 1
let g:gitgutter_realtime = 1
let g:gitgutter_eager = 1

" NERDTree settings
" Open NERDTreee when opening vim with no files were specified
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif

" Close vim if the only tab open is NERDTree
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif

" Files to be ignored by NERDTree
let NERDTreeIgnore = ['\.o$', 'core']

" Toggle NERDTree
map <F2> :NERDTreeToggle<CR>

" Airline settings
let g:airline_theme='solarized'
let g:airline_solarized_bg='dark'

" Easier navigation in splits
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>

" Set colorscheme
colorscheme NeoSolarized

" Deaoplete setup
let g:deoplete#enable_at_startup = 1

My compile_commands.json:

[
    {
        "arguments": [
            "cc",
            "-c",
            "-Wall",
            "-Wextra",
            "-pedantic",
            "-Iinclude",
            "-pthread",
            "-std=gnu99",
            "-o",
            "main.o",
            "main.c"
        ],
        "directory": "/home/savickaskr/projects/stmd/testapp",
        "file": "main.c"
    }
]
lesavonfou commented 6 years ago

I confirm this problem

phush0 commented 6 years ago

compile_command.json have two formats one is with arguments, other is with command. This plugin require second option, as generated by clang

bb010g commented 6 years ago

A quick way to fix this is jq 'map(try (.command = (.arguments | join(" ")) | del(.arguments)))' compile_commands.json > compile_commands.json.tmp && mv compile_commands.json{.tmp,}.