2

I'm using vim to do my code job and I installed Nerdtree and YCM.

With this merge, YCM has two functions, which allows us to get the error and warning counts.

Here is my .vimrc:

autocmd VimEnter * NERDTree
autocmd CursorHold,CursorHoldI * update
set statusline+=%#warningmsg#
set statusline+=%{youcompleteme#GetErrorCount()}
set statusline+=%*

However, when I execute vim, I will get some errors as below:

Error detected while processing function 191[2]..192[20]..195[8]..159[25]..157[23]..nerdtree#echo[1]..youcompleteme#GetEr
rorCount:
line    1:
Traceback (most recent call last):
Press ENTER or type command to continue
Error detected while processing function 191[2]..192[20]..195[8]..159[25]..157[23]..nerdtree#echo[1]..youcompleteme#GetEr
rorCount:
line    1:
  File "<string>", line 1, in <module>
Press ENTER or type command to continue
Error detected while processing function 191[2]..192[20]..195[8]..159[25]..157[23]..nerdtree#echo[1]..youcompleteme#GetEr
rorCount:
line    1:
NameError: name 'ycm_state' is not defined
Press ENTER or type command to continue
Error detected while processing function 191[2]..192[20]..195[8]..159[25]..157[23]..nerdtree#echo[1]..youcompleteme#GetEr
rorCount:
line    1:
E858: Eval did not return a valid python object

Then, I type enter, everything works fine, I can see the error counts at the status line.

I don't quite know why but it seems that when I execute vim, it first loads the plugin Nerdtree, and the function youcompleteme#GetErrorCount() cause some error. After typing enter, it loads some files into buffer, then youcompleteme#GetErrorCount() can work well.

Can we solve this issue?

1
  • 1
    You might be better off diagnosing this with the help of the plugin maintainers/experts
    – D. Ben Knoble
    Commented Mar 30, 2020 at 13:03

1 Answer 1

0

Well, I can't figure out exactly what the problem is but the reason probably is YCM is not ready while loading Nerdtree. So I add a if condition to check if YCM is ready.

set statusline+=%#warningmsg#
function! YCMStatusLine() abort
    if exists(':YcmDiag')
        let l:errCounts = youcompleteme#GetErrorCount()
        let l:wrnCounts = youcompleteme#GetWarningCount()

        return printf(
        \   '%dW %dE',
        \   wrnCounts,
        \   errCounts,
        \)
    endif
    return ''
endfunction
set statusline+=%{YCMStatusLine()}
set statusline+=%*

If :YcmDiag exists, it means that YCM has been loaded, if not, return an empty string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.