|
@@ -131,38 +131,38 @@ endfunction
|
|
|
|
|
|
function! s:SetUpPython() abort
|
|
|
python << EOF
|
|
|
+import os
|
|
|
import sys
|
|
|
+import traceback
|
|
|
import vim
|
|
|
-import os
|
|
|
-import subprocess
|
|
|
|
|
|
+# Add python sources folder to the system path.
|
|
|
script_folder = vim.eval( 's:script_folder_path' )
|
|
|
-sys.path.insert( 0, os.path.join( script_folder, '../python' ) )
|
|
|
-sys.path.insert( 0, os.path.join( script_folder, '../third_party/ycmd' ) )
|
|
|
-from ycmd import server_utils
|
|
|
-server_utils.AddNearestThirdPartyFoldersToSysPath( script_folder )
|
|
|
-
|
|
|
-# We need to import ycmd's third_party folders as well since we import and
|
|
|
-# use ycmd code in the client.
|
|
|
-server_utils.AddNearestThirdPartyFoldersToSysPath( server_utils.__file__ )
|
|
|
-from ycmd import utils
|
|
|
-from ycm import base
|
|
|
-base.LoadJsonDefaultsIntoVim()
|
|
|
-from ycmd import user_options_store
|
|
|
-user_options_store.SetAll( base.BuildServerConf() )
|
|
|
-from ycm import paths, vimsupport
|
|
|
-
|
|
|
-popen_args = [ paths.PathToPythonInterpreter(),
|
|
|
- paths.PathToCheckCoreVersion() ]
|
|
|
-
|
|
|
-if utils.SafePopen( popen_args ).wait() == 2:
|
|
|
- vimsupport.PostVimMessage(
|
|
|
- 'YouCompleteMe unavailable: YCM support libs too old, PLEASE RECOMPILE' )
|
|
|
- vim.command( 'return 0' )
|
|
|
+sys.path.insert( 0, os.path.join( script_folder, '..', 'python' ) )
|
|
|
+
|
|
|
+from ycm.setup import SetUpSystemPaths, SetUpYCM
|
|
|
|
|
|
-from ycm.youcompleteme import YouCompleteMe
|
|
|
-ycm_state = YouCompleteMe( user_options_store.GetAll() )
|
|
|
-vim.command( 'return 1' )
|
|
|
+# We enclose this code in a try/except block to avoid backtraces in Vim.
|
|
|
+try:
|
|
|
+ SetUpSystemPaths()
|
|
|
+
|
|
|
+ # Import the modules used in this file.
|
|
|
+ from ycm import base, vimsupport
|
|
|
+
|
|
|
+ ycm_state = SetUpYCM()
|
|
|
+except Exception as error:
|
|
|
+ # We don't use PostVimMessage or EchoText from the vimsupport module because
|
|
|
+ # importing this module may fail.
|
|
|
+ vim.command( 'redraw | echohl WarningMsg' )
|
|
|
+ for line in traceback.format_exc().splitlines():
|
|
|
+ vim.command( "echom '{0}'".format( line.replace( "'", "''" ) ) )
|
|
|
+
|
|
|
+ vim.command( "echo 'YouCompleteMe unavailable: {0}'"
|
|
|
+ .format( str( error ).replace( "'", "''" ) ) )
|
|
|
+ vim.command( 'echohl None' )
|
|
|
+ vim.command( 'return 0' )
|
|
|
+else:
|
|
|
+ vim.command( 'return 1' )
|
|
|
EOF
|
|
|
endfunction
|
|
|
|