Add error messages when ycmd crashed
Display an error message to the user depending on the status code returned by the ycmd server. Remove ycm_core checks in plugin/youcompleteme.vim. These checks are now done by the ycmd server. Do not start a separate process to check the core version but rely on ycmd returning a specific exit code. This slightly improves the Vim startup time.
This commit is contained in:
parent
cb5756943f
commit
b440f682a8
@ -42,43 +42,6 @@ elseif !has( 'python' ) && !has( 'python3' )
|
|||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let s:script_folder_path = escape( expand( '<sfile>:p:h' ), '\' )
|
|
||||||
let s:python_folder_path = s:script_folder_path . '/../python/'
|
|
||||||
let s:ycmd_folder_path = s:script_folder_path . '/../third_party/ycmd/'
|
|
||||||
|
|
||||||
function! s:YcmLibsPresentIn( path_prefix )
|
|
||||||
if filereadable(a:path_prefix . 'ycm_core.so')
|
|
||||||
return 1
|
|
||||||
elseif filereadable(a:path_prefix . 'ycm_core.pyd')
|
|
||||||
return 1
|
|
||||||
elseif filereadable(a:path_prefix . 'ycm_core.dll')
|
|
||||||
return 1
|
|
||||||
endif
|
|
||||||
return 0
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
if s:YcmLibsPresentIn( s:python_folder_path )
|
|
||||||
echohl WarningMsg |
|
|
||||||
\ echomsg "YCM libraries found in old YouCompleteMe/python location; " .
|
|
||||||
\ "please RECOMPILE YCM." |
|
|
||||||
\ echohl None
|
|
||||||
call s:restore_cpo()
|
|
||||||
finish
|
|
||||||
endif
|
|
||||||
|
|
||||||
let g:ycm_check_if_ycm_core_present =
|
|
||||||
\ get( g:, 'ycm_check_if_ycm_core_present', 1 )
|
|
||||||
|
|
||||||
if g:ycm_check_if_ycm_core_present &&
|
|
||||||
\ !s:YcmLibsPresentIn( s:ycmd_folder_path )
|
|
||||||
echohl WarningMsg |
|
|
||||||
\ echomsg "ycm_core.[so|pyd|dll] not detected; you need to compile " .
|
|
||||||
\ "YCM before using it. Read the docs!" |
|
|
||||||
\ echohl None
|
|
||||||
call s:restore_cpo()
|
|
||||||
finish
|
|
||||||
endif
|
|
||||||
|
|
||||||
let g:loaded_youcompleteme = 1
|
let g:loaded_youcompleteme = 1
|
||||||
|
|
||||||
" NOTE: Most defaults are in third_party/ycmd/ycmd/default_settings.json. They
|
" NOTE: Most defaults are in third_party/ycmd/ycmd/default_settings.json. They
|
||||||
|
@ -133,7 +133,3 @@ def IsPythonVersionCorrect( path ):
|
|||||||
|
|
||||||
def PathToServerScript():
|
def PathToServerScript():
|
||||||
return os.path.join( DIR_OF_YCMD, 'ycmd' )
|
return os.path.join( DIR_OF_YCMD, 'ycmd' )
|
||||||
|
|
||||||
|
|
||||||
def PathToCheckCoreVersion():
|
|
||||||
return os.path.join( DIR_OF_YCMD, 'check_core_version.py' )
|
|
||||||
|
@ -42,18 +42,12 @@ def SetUpSystemPaths():
|
|||||||
|
|
||||||
|
|
||||||
def SetUpYCM():
|
def SetUpYCM():
|
||||||
from ycm import base, paths
|
from ycm import base
|
||||||
from ycmd import user_options_store, utils
|
from ycmd import user_options_store
|
||||||
from ycm.youcompleteme import YouCompleteMe
|
from ycm.youcompleteme import YouCompleteMe
|
||||||
|
|
||||||
base.LoadJsonDefaultsIntoVim()
|
base.LoadJsonDefaultsIntoVim()
|
||||||
|
|
||||||
user_options_store.SetAll( base.BuildServerConf() )
|
user_options_store.SetAll( base.BuildServerConf() )
|
||||||
|
|
||||||
popen_args = [ paths.PathToPythonInterpreter(),
|
|
||||||
paths.PathToCheckCoreVersion() ]
|
|
||||||
|
|
||||||
if utils.SafePopen( popen_args ).wait() == 2:
|
|
||||||
raise RuntimeError( 'YCM support libs too old, PLEASE RECOMPILE.' )
|
|
||||||
|
|
||||||
return YouCompleteMe( user_options_store.GetAll() )
|
return YouCompleteMe( user_options_store.GetAll() )
|
||||||
|
@ -34,7 +34,9 @@ from subprocess import PIPE
|
|||||||
from tempfile import NamedTemporaryFile
|
from tempfile import NamedTemporaryFile
|
||||||
from ycm import paths, vimsupport
|
from ycm import paths, vimsupport
|
||||||
from ycmd import utils
|
from ycmd import utils
|
||||||
|
from ycmd import server_utils
|
||||||
from ycmd.request_wrap import RequestWrap
|
from ycmd.request_wrap import RequestWrap
|
||||||
|
from ycmd.responses import ServerError
|
||||||
from ycm.diagnostic_interface import DiagnosticInterface
|
from ycm.diagnostic_interface import DiagnosticInterface
|
||||||
from ycm.omni_completer import OmniCompleter
|
from ycm.omni_completer import OmniCompleter
|
||||||
from ycm import syntax_parse
|
from ycm import syntax_parse
|
||||||
@ -47,7 +49,6 @@ from ycm.client.completion_request import ( CompletionRequest,
|
|||||||
from ycm.client.omni_completion_request import OmniCompletionRequest
|
from ycm.client.omni_completion_request import OmniCompletionRequest
|
||||||
from ycm.client.event_notification import ( SendEventNotificationAsync,
|
from ycm.client.event_notification import ( SendEventNotificationAsync,
|
||||||
EventNotification )
|
EventNotification )
|
||||||
from ycmd.responses import ServerError
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from UltiSnips import UltiSnips_Manager
|
from UltiSnips import UltiSnips_Manager
|
||||||
@ -77,13 +78,29 @@ PatchNoProxy()
|
|||||||
signal.signal( signal.SIGINT, signal.SIG_IGN )
|
signal.signal( signal.SIGINT, signal.SIG_IGN )
|
||||||
|
|
||||||
HMAC_SECRET_LENGTH = 16
|
HMAC_SECRET_LENGTH = 16
|
||||||
SERVER_CRASH_MESSAGE_STDERR_FILE = (
|
SERVER_SHUTDOWN_MESSAGE = (
|
||||||
"The ycmd server SHUT DOWN (restart with ':YcmRestartServer'). "
|
"The ycmd server SHUT DOWN (restart with ':YcmRestartServer')." )
|
||||||
|
STDERR_FILE_MESSAGE = (
|
||||||
"Run ':YcmToggleLogs stderr' to check the logs." )
|
"Run ':YcmToggleLogs stderr' to check the logs." )
|
||||||
SERVER_CRASH_MESSAGE_STDERR_FILE_DELETED = (
|
STDERR_FILE_DELETED_MESSAGE = (
|
||||||
"The ycmd server SHUT DOWN (restart with ':YcmRestartServer'). "
|
|
||||||
"Logfile was deleted; set 'g:ycm_server_keep_logfiles' to see errors "
|
"Logfile was deleted; set 'g:ycm_server_keep_logfiles' to see errors "
|
||||||
"in the future." )
|
"in the future." )
|
||||||
|
CORE_UNEXPECTED_MESSAGE = (
|
||||||
|
'Unexpected error while loading the YCM core library.' )
|
||||||
|
CORE_MISSING_MESSAGE = (
|
||||||
|
'YCM core library not detected; you need to compile YCM before using it. '
|
||||||
|
'Follow the instructions in the documentation.' )
|
||||||
|
CORE_PYTHON2_MESSAGE = (
|
||||||
|
"YCM core library compiled for Python 2 but loaded in Python 3. "
|
||||||
|
"Set the 'g:ycm_server_python_interpreter' option to a Python 2 "
|
||||||
|
"interpreter path." )
|
||||||
|
CORE_PYTHON3_MESSAGE = (
|
||||||
|
"YCM core library compiled for Python 3 but loaded in Python 2. "
|
||||||
|
"Set the 'g:ycm_server_python_interpreter' option to a Python 3 "
|
||||||
|
"interpreter path." )
|
||||||
|
CORE_OUTDATED_MESSAGE = (
|
||||||
|
'YCM core library too old; PLEASE RECOMPILE by running the install.py '
|
||||||
|
'script. See the documentation for more details.' )
|
||||||
SERVER_IDLE_SUICIDE_SECONDS = 10800 # 3 hours
|
SERVER_IDLE_SUICIDE_SECONDS = 10800 # 3 hours
|
||||||
DIAGNOSTIC_UI_FILETYPES = set( [ 'cpp', 'cs', 'c', 'objc', 'objcpp' ] )
|
DIAGNOSTIC_UI_FILETYPES = set( [ 'cpp', 'cs', 'c', 'objc', 'objcpp' ] )
|
||||||
|
|
||||||
@ -159,11 +176,28 @@ class YouCompleteMe( object ):
|
|||||||
if self._user_notified_about_crash or self.IsServerAlive():
|
if self._user_notified_about_crash or self.IsServerAlive():
|
||||||
return
|
return
|
||||||
self._user_notified_about_crash = True
|
self._user_notified_about_crash = True
|
||||||
|
|
||||||
try:
|
try:
|
||||||
vimsupport.CheckFilename( self._server_stderr )
|
vimsupport.CheckFilename( self._server_stderr )
|
||||||
vimsupport.PostVimMessage( SERVER_CRASH_MESSAGE_STDERR_FILE )
|
stderr_message = STDERR_FILE_MESSAGE
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
vimsupport.PostVimMessage( SERVER_CRASH_MESSAGE_STDERR_FILE_DELETED )
|
stderr_message = STDERR_FILE_DELETED_MESSAGE
|
||||||
|
|
||||||
|
message = SERVER_SHUTDOWN_MESSAGE
|
||||||
|
return_code = self._server_popen.poll()
|
||||||
|
if return_code == server_utils.CORE_UNEXPECTED_STATUS:
|
||||||
|
message += ' ' + CORE_UNEXPECTED_MESSAGE + ' ' + stderr_message
|
||||||
|
elif return_code == server_utils.CORE_MISSING_STATUS:
|
||||||
|
message += ' ' + CORE_MISSING_MESSAGE
|
||||||
|
elif return_code == server_utils.CORE_PYTHON2_STATUS:
|
||||||
|
message += ' ' + CORE_PYTHON2_MESSAGE
|
||||||
|
elif return_code == server_utils.CORE_PYTHON3_STATUS:
|
||||||
|
message += ' ' + CORE_PYTHON3_MESSAGE
|
||||||
|
elif return_code == server_utils.CORE_OUTDATED_STATUS:
|
||||||
|
message += ' ' + CORE_OUTDATED_MESSAGE
|
||||||
|
else:
|
||||||
|
message += ' ' + stderr_message
|
||||||
|
vimsupport.PostVimMessage( message )
|
||||||
|
|
||||||
|
|
||||||
def ServerPid( self ):
|
def ServerPid( self ):
|
||||||
|
Loading…
Reference in New Issue
Block a user