Skip to content

Commit

Permalink
Auto merge of #2142 - micbou:check-core, r=vheon
Browse files Browse the repository at this point in the history
[READY] Add error messages when ycmd crashed

See PR ycm-core/ycmd#467.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/valloric/youcompleteme/2142)
<!-- Reviewable:end -->
  • Loading branch information
homu committed May 3, 2016
2 parents cb57569 + d2beb20 commit 87f0f7e
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 57 deletions.
37 changes: 0 additions & 37 deletions plugin/youcompleteme.vim
Expand Up @@ -42,43 +42,6 @@ elseif !has( 'python' ) && !has( 'python3' )
finish
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

" NOTE: Most defaults are in third_party/ycmd/ycmd/default_settings.json. They
Expand Down
4 changes: 0 additions & 4 deletions python/ycm/paths.py
Expand Up @@ -133,7 +133,3 @@ def IsPythonVersionCorrect( path ):

def PathToServerScript():
return os.path.join( DIR_OF_YCMD, 'ycmd' )


def PathToCheckCoreVersion():
return os.path.join( DIR_OF_YCMD, 'check_core_version.py' )
10 changes: 2 additions & 8 deletions python/ycm/setup.py
Expand Up @@ -42,18 +42,12 @@ def SetUpSystemPaths():


def SetUpYCM():
from ycm import base, paths
from ycmd import user_options_store, utils
from ycm import base
from ycmd import user_options_store
from ycm.youcompleteme import YouCompleteMe

base.LoadJsonDefaultsIntoVim()

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() )
48 changes: 41 additions & 7 deletions python/ycm/youcompleteme.py
Expand Up @@ -34,7 +34,9 @@
from tempfile import NamedTemporaryFile
from ycm import paths, vimsupport
from ycmd import utils
from ycmd import server_utils
from ycmd.request_wrap import RequestWrap
from ycmd.responses import ServerError
from ycm.diagnostic_interface import DiagnosticInterface
from ycm.omni_completer import OmniCompleter
from ycm import syntax_parse
Expand All @@ -47,7 +49,6 @@
from ycm.client.omni_completion_request import OmniCompletionRequest
from ycm.client.event_notification import ( SendEventNotificationAsync,
EventNotification )
from ycmd.responses import ServerError

try:
from UltiSnips import UltiSnips_Manager
Expand Down Expand Up @@ -77,13 +78,29 @@ def PatchNoProxy():
signal.signal( signal.SIGINT, signal.SIG_IGN )

HMAC_SECRET_LENGTH = 16
SERVER_CRASH_MESSAGE_STDERR_FILE = (
"The ycmd server SHUT DOWN (restart with ':YcmRestartServer'). "
SERVER_SHUTDOWN_MESSAGE = (
"The ycmd server SHUT DOWN (restart with ':YcmRestartServer')." )
STDERR_FILE_MESSAGE = (
"Run ':YcmToggleLogs stderr' to check the logs." )
SERVER_CRASH_MESSAGE_STDERR_FILE_DELETED = (
"The ycmd server SHUT DOWN (restart with ':YcmRestartServer'). "
STDERR_FILE_DELETED_MESSAGE = (
"Logfile was deleted; set 'g:ycm_server_keep_logfiles' to see errors "
"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
DIAGNOSTIC_UI_FILETYPES = set( [ 'cpp', 'cs', 'c', 'objc', 'objcpp' ] )

Expand Down Expand Up @@ -159,11 +176,28 @@ def _NotifyUserIfServerCrashed( self ):
if self._user_notified_about_crash or self.IsServerAlive():
return
self._user_notified_about_crash = True

try:
vimsupport.CheckFilename( self._server_stderr )
vimsupport.PostVimMessage( SERVER_CRASH_MESSAGE_STDERR_FILE )
stderr_message = STDERR_FILE_MESSAGE
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 ):
Expand Down
2 changes: 1 addition & 1 deletion third_party/ycmd
Submodule ycmd updated from 89e558 to ff72c8

0 comments on commit 87f0f7e

Please sign in to comment.