Auto merge of #1727 - micbou:vim-commands, r=Valloric

Define Vim commands only if setup is successful

Vim commands (`YcmDebugInfo`, `YcmCompleter`, etc.) should not be defined if an error is encountered when processing the `s:SetUpPython` function. Why? Because those commands will return errors like `name 'ycm_state' is not defined`.

Note: due to an unexpected behavior, those commands work fine when libraries are found outdated. See issue #1726.

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/valloric/youcompleteme/1727)
<!-- Reviewable:end -->
This commit is contained in:
Homu 2015-10-19 04:04:48 +09:00
commit 76ff85bf75

View File

@ -51,6 +51,7 @@ function! youcompleteme#Enable()
return
endif
call s:SetUpCommands()
call s:SetUpCpoptions()
call s:SetUpCompleteopt()
call s:SetUpKeyMappings()
@ -305,6 +306,17 @@ function! s:AllowedToCompleteInCurrentFile()
endfunction
function! s:SetUpCommands()
command! YcmRestartServer call s:RestartServer()
command! YcmShowDetailedDiagnostic call s:ShowDetailedDiagnostic()
command! YcmDebugInfo call s:DebugInfo()
command! -nargs=* -complete=custom,youcompleteme#SubCommandsComplete
\ YcmCompleter call s:CompleterCommand(<f-args>)
command! YcmForceCompileAndDiagnostics call s:ForceCompileAndDiagnostics()
command! YcmDiags call s:ShowDiagnostics()
endfunction
function! s:SetUpCpoptions()
" Without this flag in cpoptions, critical YCM mappings do not work. There's
" no way to not have this and have YCM working, so force the flag.
@ -736,15 +748,11 @@ function! s:RestartServer()
py ycm_state.RestartServer()
endfunction
command! YcmRestartServer call s:RestartServer()
function! s:ShowDetailedDiagnostic()
py ycm_state.ShowDetailedDiagnostic()
endfunction
command! YcmShowDetailedDiagnostic call s:ShowDetailedDiagnostic()
function! s:DebugInfo()
echom "Printing YouCompleteMe debug information..."
@ -754,8 +762,6 @@ function! s:DebugInfo()
endfor
endfunction
command! YcmDebugInfo call s:DebugInfo()
function! s:CompleterCommand(...)
" CompleterCommand will call the OnUserCommand function of a completer.
@ -790,9 +796,6 @@ function! youcompleteme#OpenGoToList()
endfunction
command! -nargs=* -complete=custom,youcompleteme#SubCommandsComplete
\ YcmCompleter call s:CompleterCommand(<f-args>)
function! youcompleteme#SubCommandsComplete( arglead, cmdline, cursorpos )
return join( pyeval( 'ycm_state.GetDefinedSubcommands()' ),
\ "\n")
@ -831,8 +834,6 @@ function! s:ForceCompileAndDiagnostics()
echom "Diagnostics refreshed."
endfunction
command! YcmForceCompileAndDiagnostics call s:ForceCompileAndDiagnostics()
function! s:ShowDiagnostics()
let compilation_succeeded = s:ForceCompile()
@ -853,8 +854,6 @@ function! s:ShowDiagnostics()
endif
endfunction
command! YcmDiags call s:ShowDiagnostics()
" This is basic vim plugin boilerplate
let &cpo = s:save_cpo