2012-04-15 19:57:10 -04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
2014-01-13 14:08:43 -05:00
|
|
|
# Copyright (C) 2011, 2012 Google Inc.
|
2012-04-15 19:57:10 -04:00
|
|
|
#
|
|
|
|
# This file is part of YouCompleteMe.
|
|
|
|
#
|
|
|
|
# YouCompleteMe is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# YouCompleteMe is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2012-08-01 01:01:41 -04:00
|
|
|
import os
|
2013-02-05 01:07:06 -05:00
|
|
|
import vim
|
2013-09-24 17:00:27 -04:00
|
|
|
import tempfile
|
|
|
|
import json
|
2014-01-29 13:18:07 -05:00
|
|
|
import signal
|
2014-04-25 14:07:08 -04:00
|
|
|
import base64
|
2014-03-02 01:14:14 -05:00
|
|
|
from subprocess import PIPE
|
2013-05-19 22:44:42 -04:00
|
|
|
from ycm import vimsupport
|
2014-05-13 16:09:19 -04:00
|
|
|
from ycmd import utils
|
2014-01-04 17:28:27 -05:00
|
|
|
from ycm.diagnostic_interface import DiagnosticInterface
|
2014-05-13 16:09:19 -04:00
|
|
|
from ycm.omni_completer import OmniCompleter
|
|
|
|
from ycm import syntax_parse
|
|
|
|
from ycmd.completers.completer_utils import FiletypeCompleterExistsForFiletype
|
2013-11-20 15:33:57 -05:00
|
|
|
from ycm.client.ycmd_keepalive import YcmdKeepalive
|
2013-09-24 17:48:14 -04:00
|
|
|
from ycm.client.base_request import BaseRequest, BuildRequestData
|
2013-09-24 13:17:38 -04:00
|
|
|
from ycm.client.command_request import SendCommandRequest
|
2013-09-20 20:24:34 -04:00
|
|
|
from ycm.client.completion_request import CompletionRequest
|
2013-10-07 18:47:48 -04:00
|
|
|
from ycm.client.omni_completion_request import OmniCompletionRequest
|
2013-10-03 16:15:43 -04:00
|
|
|
from ycm.client.event_notification import ( SendEventNotificationAsync,
|
|
|
|
EventNotification )
|
2014-05-13 16:09:19 -04:00
|
|
|
from ycmd.responses import ServerError
|
2013-09-07 20:39:52 -04:00
|
|
|
|
2013-09-25 13:56:46 -04:00
|
|
|
try:
|
|
|
|
from UltiSnips import UltiSnips_Manager
|
|
|
|
USE_ULTISNIPS_DATA = True
|
|
|
|
except ImportError:
|
|
|
|
USE_ULTISNIPS_DATA = False
|
|
|
|
|
2013-11-04 13:34:42 -05:00
|
|
|
# We need this so that Requests doesn't end up using the local HTTP proxy when
|
|
|
|
# talking to ycmd. Users should actually be setting this themselves when
|
|
|
|
# configuring a proxy server on their machine, but most don't know they need to
|
|
|
|
# or how to do it, so we do it for them.
|
|
|
|
# Relevant issues:
|
|
|
|
# https://github.com/Valloric/YouCompleteMe/issues/641
|
|
|
|
# https://github.com/kennethreitz/requests/issues/879
|
|
|
|
os.environ['no_proxy'] = '127.0.0.1,localhost'
|
|
|
|
|
2014-01-29 13:18:07 -05:00
|
|
|
# Force the Python interpreter embedded in Vim (in which we are running) to
|
|
|
|
# ignore the SIGINT signal. This helps reduce the fallout of a user pressing
|
|
|
|
# Ctrl-C in Vim.
|
|
|
|
signal.signal( signal.SIGINT, signal.SIG_IGN )
|
|
|
|
|
2014-04-25 14:07:08 -04:00
|
|
|
HMAC_SECRET_LENGTH = 16
|
2013-11-04 14:15:03 -05:00
|
|
|
NUM_YCMD_STDERR_LINES_ON_CRASH = 30
|
2014-05-16 22:23:14 -04:00
|
|
|
SERVER_CRASH_MESSAGE_STDERR_FILE_DELETED = (
|
|
|
|
'The ycmd server SHUT DOWN (restart with :YcmRestartServer). '
|
|
|
|
'Logfile was deleted; set g:ycm_server_keep_logfiles to see errors '
|
|
|
|
'in the future.' )
|
2013-11-04 14:15:03 -05:00
|
|
|
SERVER_CRASH_MESSAGE_STDERR_FILE = (
|
|
|
|
'The ycmd server SHUT DOWN (restart with :YcmRestartServer). ' +
|
|
|
|
'Stderr (last {0} lines):\n\n'.format( NUM_YCMD_STDERR_LINES_ON_CRASH ) )
|
2013-10-15 14:19:56 -04:00
|
|
|
SERVER_CRASH_MESSAGE_SAME_STDERR = (
|
2013-11-04 14:15:03 -05:00
|
|
|
'The ycmd server SHUT DOWN (restart with :YcmRestartServer). '
|
|
|
|
' check console output for logs!' )
|
2013-11-20 15:33:57 -05:00
|
|
|
SERVER_IDLE_SUICIDE_SECONDS = 10800 # 3 hours
|
2013-10-15 14:19:56 -04:00
|
|
|
|
|
|
|
|
2012-08-04 20:46:54 -04:00
|
|
|
class YouCompleteMe( object ):
|
2013-09-02 17:45:53 -04:00
|
|
|
def __init__( self, user_options ):
|
|
|
|
self._user_options = user_options
|
2013-12-09 05:32:01 -05:00
|
|
|
self._user_notified_about_crash = False
|
2014-01-08 21:43:17 -05:00
|
|
|
self._diag_interface = DiagnosticInterface( user_options )
|
2013-09-02 17:45:53 -04:00
|
|
|
self._omnicomp = OmniCompleter( user_options )
|
2013-10-03 13:14:31 -04:00
|
|
|
self._latest_completion_request = None
|
2013-10-03 16:15:43 -04:00
|
|
|
self._latest_file_parse_request = None
|
2013-09-23 16:27:32 -04:00
|
|
|
self._server_stdout = None
|
|
|
|
self._server_stderr = None
|
2013-09-23 17:33:14 -04:00
|
|
|
self._server_popen = None
|
2013-09-23 18:31:11 -04:00
|
|
|
self._filetypes_with_keywords_loaded = set()
|
2013-11-20 15:33:57 -05:00
|
|
|
self._ycmd_keepalive = YcmdKeepalive()
|
2013-09-23 16:27:32 -04:00
|
|
|
self._SetupServer()
|
2013-11-20 15:33:57 -05:00
|
|
|
self._ycmd_keepalive.Start()
|
2013-09-02 22:46:30 -04:00
|
|
|
|
2013-09-23 16:27:32 -04:00
|
|
|
def _SetupServer( self ):
|
2013-10-14 23:38:45 -04:00
|
|
|
server_port = utils.GetUnusedLocalhostPort()
|
2014-04-25 14:07:08 -04:00
|
|
|
# The temp options file is deleted by ycmd during startup
|
2013-09-24 17:00:27 -04:00
|
|
|
with tempfile.NamedTemporaryFile( delete = False ) as options_file:
|
2014-04-25 14:07:08 -04:00
|
|
|
hmac_secret = os.urandom( HMAC_SECRET_LENGTH )
|
|
|
|
options_dict = dict( self._user_options )
|
|
|
|
options_dict[ 'hmac_secret' ] = base64.b64encode( hmac_secret )
|
|
|
|
json.dump( options_dict, options_file )
|
2014-01-14 09:05:03 -05:00
|
|
|
options_file.flush()
|
2014-03-02 01:14:14 -05:00
|
|
|
|
2013-10-11 14:11:02 -04:00
|
|
|
args = [ utils.PathToPythonInterpreter(),
|
2013-10-09 22:28:27 -04:00
|
|
|
_PathToServerScript(),
|
|
|
|
'--port={0}'.format( server_port ),
|
|
|
|
'--options_file={0}'.format( options_file.name ),
|
2013-10-23 14:02:25 -04:00
|
|
|
'--log={0}'.format( self._user_options[ 'server_log_level' ] ),
|
2013-10-23 15:33:27 -04:00
|
|
|
'--idle_suicide_seconds={0}'.format(
|
2014-03-02 01:14:14 -05:00
|
|
|
SERVER_IDLE_SUICIDE_SECONDS )]
|
2013-09-24 17:00:27 -04:00
|
|
|
|
2014-03-02 01:14:14 -05:00
|
|
|
if not self._user_options[ 'server_use_vim_stdout' ]:
|
2013-09-24 17:00:27 -04:00
|
|
|
filename_format = os.path.join( utils.PathToTempDir(),
|
|
|
|
'server_{port}_{std}.log' )
|
|
|
|
|
|
|
|
self._server_stdout = filename_format.format( port = server_port,
|
|
|
|
std = 'stdout' )
|
|
|
|
self._server_stderr = filename_format.format( port = server_port,
|
|
|
|
std = 'stderr' )
|
2014-03-02 01:14:14 -05:00
|
|
|
args.append('--stdout={0}'.format( self._server_stdout ))
|
|
|
|
args.append('--stderr={0}'.format( self._server_stderr ))
|
2013-09-24 17:00:27 -04:00
|
|
|
|
2014-03-02 01:14:14 -05:00
|
|
|
if self._user_options[ 'server_keep_logfiles' ]:
|
|
|
|
args.append('--keep_logfiles')
|
2013-10-15 14:19:56 -04:00
|
|
|
|
2014-03-02 01:14:14 -05:00
|
|
|
self._server_popen = utils.SafePopen( args, stdout = PIPE, stderr = PIPE)
|
2014-05-21 16:40:47 -04:00
|
|
|
BaseRequest.server_location = 'http://127.0.0.1:' + str( server_port )
|
2014-04-25 14:07:08 -04:00
|
|
|
BaseRequest.hmac_secret = hmac_secret
|
2014-03-02 01:14:14 -05:00
|
|
|
|
|
|
|
self._NotifyUserIfServerCrashed()
|
2013-10-15 14:19:56 -04:00
|
|
|
|
2013-10-15 18:27:54 -04:00
|
|
|
def _IsServerAlive( self ):
|
|
|
|
returncode = self._server_popen.poll()
|
|
|
|
# When the process hasn't finished yet, poll() returns None.
|
|
|
|
return returncode is None
|
|
|
|
|
|
|
|
|
|
|
|
def _NotifyUserIfServerCrashed( self ):
|
2013-12-09 05:32:01 -05:00
|
|
|
if self._user_notified_about_crash or self._IsServerAlive():
|
2013-10-15 18:27:54 -04:00
|
|
|
return
|
2013-12-09 05:32:01 -05:00
|
|
|
self._user_notified_about_crash = True
|
2013-10-15 18:27:54 -04:00
|
|
|
if self._server_stderr:
|
2014-05-16 22:23:14 -04:00
|
|
|
try:
|
|
|
|
with open( self._server_stderr, 'r' ) as server_stderr_file:
|
|
|
|
error_output = ''.join( server_stderr_file.readlines()[
|
|
|
|
: - NUM_YCMD_STDERR_LINES_ON_CRASH ] )
|
|
|
|
vimsupport.PostMultiLineNotice( SERVER_CRASH_MESSAGE_STDERR_FILE +
|
|
|
|
error_output )
|
|
|
|
except IOError:
|
|
|
|
vimsupport.PostVimMessage( SERVER_CRASH_MESSAGE_STDERR_FILE_DELETED )
|
2013-10-15 18:27:54 -04:00
|
|
|
else:
|
|
|
|
vimsupport.PostVimMessage( SERVER_CRASH_MESSAGE_SAME_STDERR )
|
|
|
|
|
|
|
|
|
2013-10-22 13:51:37 -04:00
|
|
|
def ServerPid( self ):
|
|
|
|
if not self._server_popen:
|
|
|
|
return -1
|
|
|
|
return self._server_popen.pid
|
|
|
|
|
|
|
|
|
2013-12-20 16:01:48 -05:00
|
|
|
def _ServerCleanup( self ):
|
|
|
|
if self._IsServerAlive():
|
|
|
|
self._server_popen.terminate()
|
|
|
|
|
2014-03-07 14:28:53 -05:00
|
|
|
|
2013-10-15 18:27:54 -04:00
|
|
|
def RestartServer( self ):
|
|
|
|
vimsupport.PostVimMessage( 'Restarting ycmd server...' )
|
2013-12-09 05:32:01 -05:00
|
|
|
self._user_notified_about_crash = False
|
2013-12-20 16:01:48 -05:00
|
|
|
self._ServerCleanup()
|
2013-10-15 18:27:54 -04:00
|
|
|
self._SetupServer()
|
2013-09-24 15:53:44 -04:00
|
|
|
|
2013-09-02 22:46:30 -04:00
|
|
|
|
2013-10-07 16:09:34 -04:00
|
|
|
def CreateCompletionRequest( self, force_semantic = False ):
|
2013-09-02 22:46:30 -04:00
|
|
|
# We have to store a reference to the newly created CompletionRequest
|
|
|
|
# because VimScript can't store a reference to a Python object across
|
|
|
|
# function calls... Thus we need to keep this request somewhere.
|
2013-10-07 18:47:48 -04:00
|
|
|
if ( not self.NativeFiletypeCompletionAvailable() and
|
|
|
|
self.CurrentFiletypeCompletionEnabled() and
|
2013-10-14 16:29:28 -04:00
|
|
|
self._omnicomp.ShouldUseNow() ):
|
2013-10-07 18:47:48 -04:00
|
|
|
self._latest_completion_request = OmniCompletionRequest( self._omnicomp )
|
|
|
|
else:
|
2013-10-26 19:22:43 -04:00
|
|
|
extra_data = {}
|
|
|
|
self._AddExtraConfDataIfNeeded( extra_data )
|
|
|
|
if force_semantic:
|
|
|
|
extra_data[ 'force_semantic' ] = True
|
|
|
|
|
|
|
|
self._latest_completion_request = ( CompletionRequest( extra_data )
|
2013-10-15 18:27:54 -04:00
|
|
|
if self._IsServerAlive() else
|
|
|
|
None )
|
2013-10-03 13:14:31 -04:00
|
|
|
return self._latest_completion_request
|
2013-09-02 22:46:30 -04:00
|
|
|
|
|
|
|
|
2013-09-06 02:43:14 -04:00
|
|
|
def SendCommandRequest( self, arguments, completer ):
|
2013-10-15 18:27:54 -04:00
|
|
|
if self._IsServerAlive():
|
|
|
|
return SendCommandRequest( arguments, completer )
|
2013-09-06 02:43:14 -04:00
|
|
|
|
|
|
|
|
2013-09-27 19:20:35 -04:00
|
|
|
def GetDefinedSubcommands( self ):
|
2013-10-15 18:27:54 -04:00
|
|
|
if self._IsServerAlive():
|
2014-05-22 17:12:51 -04:00
|
|
|
try:
|
|
|
|
return BaseRequest.PostDataToHandler( BuildRequestData(),
|
|
|
|
'defined_subcommands' )
|
|
|
|
except ServerError:
|
|
|
|
return []
|
2013-10-15 18:27:54 -04:00
|
|
|
else:
|
|
|
|
return []
|
2013-09-27 19:20:35 -04:00
|
|
|
|
|
|
|
|
2013-09-02 22:46:30 -04:00
|
|
|
def GetCurrentCompletionRequest( self ):
|
2013-10-03 13:14:31 -04:00
|
|
|
return self._latest_completion_request
|
2012-08-01 01:01:41 -04:00
|
|
|
|
2012-07-22 18:19:28 -04:00
|
|
|
|
2013-02-25 09:14:01 -05:00
|
|
|
def GetOmniCompleter( self ):
|
2013-09-01 23:19:46 -04:00
|
|
|
return self._omnicomp
|
2013-02-25 09:14:01 -05:00
|
|
|
|
|
|
|
|
2013-02-10 22:55:05 -05:00
|
|
|
def NativeFiletypeCompletionAvailable( self ):
|
2013-10-07 19:10:48 -04:00
|
|
|
return any( [ FiletypeCompleterExistsForFiletype( x ) for x in
|
|
|
|
vimsupport.CurrentFiletypes() ] )
|
2013-02-10 22:55:05 -05:00
|
|
|
|
|
|
|
|
|
|
|
def NativeFiletypeCompletionUsable( self ):
|
2013-09-02 17:45:53 -04:00
|
|
|
return ( self.CurrentFiletypeCompletionEnabled() and
|
2013-02-10 22:55:05 -05:00
|
|
|
self.NativeFiletypeCompletionAvailable() )
|
|
|
|
|
2013-01-31 19:19:56 -05:00
|
|
|
|
2012-08-04 20:46:54 -04:00
|
|
|
def OnFileReadyToParse( self ):
|
2013-10-07 18:47:48 -04:00
|
|
|
self._omnicomp.OnFileReadyToParse( None )
|
|
|
|
|
2013-10-15 18:27:54 -04:00
|
|
|
if not self._IsServerAlive():
|
|
|
|
self._NotifyUserIfServerCrashed()
|
|
|
|
|
2013-09-07 20:39:52 -04:00
|
|
|
extra_data = {}
|
2013-10-26 19:22:43 -04:00
|
|
|
self._AddTagsFilesIfNeeded( extra_data )
|
|
|
|
self._AddSyntaxDataIfNeeded( extra_data )
|
|
|
|
self._AddExtraConfDataIfNeeded( extra_data )
|
2012-04-15 19:57:10 -04:00
|
|
|
|
2013-10-03 16:15:43 -04:00
|
|
|
self._latest_file_parse_request = EventNotification( 'FileReadyToParse',
|
|
|
|
extra_data )
|
|
|
|
self._latest_file_parse_request.Start()
|
2012-05-08 00:23:38 -04:00
|
|
|
|
2013-03-14 23:39:44 -04:00
|
|
|
|
2013-09-07 20:39:52 -04:00
|
|
|
def OnBufferUnload( self, deleted_buffer_file ):
|
2013-10-15 18:27:54 -04:00
|
|
|
if not self._IsServerAlive():
|
|
|
|
return
|
2013-09-07 20:39:52 -04:00
|
|
|
SendEventNotificationAsync( 'BufferUnload',
|
|
|
|
{ 'unloaded_buffer': deleted_buffer_file } )
|
2013-03-14 23:39:44 -04:00
|
|
|
|
|
|
|
|
2013-04-24 16:31:28 -04:00
|
|
|
def OnBufferVisit( self ):
|
2013-10-15 18:27:54 -04:00
|
|
|
if not self._IsServerAlive():
|
|
|
|
return
|
2013-09-25 13:56:46 -04:00
|
|
|
extra_data = {}
|
|
|
|
_AddUltiSnipsDataIfNeeded( extra_data )
|
|
|
|
SendEventNotificationAsync( 'BufferVisit', extra_data )
|
2013-04-24 16:31:28 -04:00
|
|
|
|
|
|
|
|
2012-08-04 20:46:54 -04:00
|
|
|
def OnInsertLeave( self ):
|
2013-10-15 18:27:54 -04:00
|
|
|
if not self._IsServerAlive():
|
|
|
|
return
|
2013-09-20 20:24:34 -04:00
|
|
|
SendEventNotificationAsync( 'InsertLeave' )
|
2012-05-12 18:20:03 -04:00
|
|
|
|
2012-07-31 18:30:50 -04:00
|
|
|
|
2014-01-04 19:45:34 -05:00
|
|
|
def OnCursorMoved( self ):
|
|
|
|
self._diag_interface.OnCursorMoved()
|
|
|
|
|
|
|
|
|
2013-07-07 13:59:48 -04:00
|
|
|
def OnVimLeave( self ):
|
2013-12-20 16:01:48 -05:00
|
|
|
self._ServerCleanup()
|
2013-10-17 15:21:59 -04:00
|
|
|
|
2013-09-07 20:39:52 -04:00
|
|
|
|
|
|
|
def OnCurrentIdentifierFinished( self ):
|
2013-10-15 18:27:54 -04:00
|
|
|
if not self._IsServerAlive():
|
|
|
|
return
|
2013-09-20 20:24:34 -04:00
|
|
|
SendEventNotificationAsync( 'CurrentIdentifierFinished' )
|
2013-07-07 13:59:48 -04:00
|
|
|
|
|
|
|
|
2012-08-04 20:46:54 -04:00
|
|
|
def DiagnosticsForCurrentFileReady( self ):
|
2013-10-03 16:15:43 -04:00
|
|
|
return bool( self._latest_file_parse_request and
|
|
|
|
self._latest_file_parse_request.Done() )
|
2013-10-03 13:14:31 -04:00
|
|
|
|
|
|
|
|
2014-01-05 15:58:13 -05:00
|
|
|
def GetDiagnosticsFromStoredRequest( self, qflist_format = False ):
|
2013-10-11 22:09:21 -04:00
|
|
|
if self.DiagnosticsForCurrentFileReady():
|
2014-01-05 15:58:13 -05:00
|
|
|
diagnostics = self._latest_file_parse_request.Response()
|
2013-10-03 13:14:31 -04:00
|
|
|
# We set the diagnostics request to None because we want to prevent
|
|
|
|
# Syntastic from repeatedly refreshing the buffer with the same diags.
|
|
|
|
# Setting this to None makes DiagnosticsForCurrentFileReady return False
|
|
|
|
# until the next request is created.
|
2013-10-03 16:15:43 -04:00
|
|
|
self._latest_file_parse_request = None
|
2014-01-05 15:58:13 -05:00
|
|
|
if qflist_format:
|
2014-01-08 22:09:40 -05:00
|
|
|
return vimsupport.ConvertDiagnosticsToQfList( diagnostics )
|
2014-01-05 15:58:13 -05:00
|
|
|
else:
|
|
|
|
return diagnostics
|
2012-08-06 23:14:21 -04:00
|
|
|
return []
|
|
|
|
|
|
|
|
|
2014-01-04 17:28:27 -05:00
|
|
|
def UpdateDiagnosticInterface( self ):
|
|
|
|
if not self.DiagnosticsForCurrentFileReady():
|
|
|
|
return
|
|
|
|
self._diag_interface.UpdateWithNewDiagnostics(
|
|
|
|
self.GetDiagnosticsFromStoredRequest() )
|
|
|
|
|
|
|
|
|
2013-10-03 17:49:51 -04:00
|
|
|
def ShowDetailedDiagnostic( self ):
|
2013-10-15 18:27:54 -04:00
|
|
|
if not self._IsServerAlive():
|
|
|
|
return
|
2013-10-16 17:37:42 -04:00
|
|
|
try:
|
|
|
|
debug_info = BaseRequest.PostDataToHandler( BuildRequestData(),
|
|
|
|
'detailed_diagnostic' )
|
|
|
|
if 'message' in debug_info:
|
|
|
|
vimsupport.EchoText( debug_info[ 'message' ] )
|
|
|
|
except ServerError as e:
|
|
|
|
vimsupport.PostVimMessage( str( e ) )
|
2012-08-15 22:39:03 -04:00
|
|
|
|
|
|
|
|
2013-01-26 14:44:42 -05:00
|
|
|
def DebugInfo( self ):
|
2013-10-15 18:27:54 -04:00
|
|
|
if self._IsServerAlive():
|
|
|
|
debug_info = BaseRequest.PostDataToHandler( BuildRequestData(),
|
|
|
|
'debug_info' )
|
|
|
|
else:
|
|
|
|
debug_info = 'Server crashed, no debug info from server'
|
2013-10-04 18:44:16 -04:00
|
|
|
debug_info += '\nServer running at: {0}'.format(
|
2013-09-27 20:26:14 -04:00
|
|
|
BaseRequest.server_location )
|
2013-10-22 13:53:31 -04:00
|
|
|
debug_info += '\nServer process ID: {0}'.format( self._server_popen.pid )
|
2013-09-27 20:26:14 -04:00
|
|
|
if self._server_stderr or self._server_stdout:
|
2013-10-04 18:44:16 -04:00
|
|
|
debug_info += '\nServer logfiles:\n {0}\n {1}'.format(
|
2013-09-27 20:26:14 -04:00
|
|
|
self._server_stdout,
|
|
|
|
self._server_stderr )
|
|
|
|
|
|
|
|
return debug_info
|
2013-01-26 14:44:42 -05:00
|
|
|
|
|
|
|
|
2013-09-02 17:45:53 -04:00
|
|
|
def CurrentFiletypeCompletionEnabled( self ):
|
|
|
|
filetypes = vimsupport.CurrentFiletypes()
|
|
|
|
filetype_to_disable = self._user_options[
|
|
|
|
'filetype_specific_completion_to_disable' ]
|
|
|
|
return not all([ x in filetype_to_disable for x in filetypes ])
|
2013-02-10 22:55:05 -05:00
|
|
|
|
2013-01-26 14:44:42 -05:00
|
|
|
|
2013-09-23 18:31:11 -04:00
|
|
|
def _AddSyntaxDataIfNeeded( self, extra_data ):
|
2013-10-26 19:22:43 -04:00
|
|
|
if not self._user_options[ 'seed_identifiers_with_syntax' ]:
|
|
|
|
return
|
2013-09-23 18:31:11 -04:00
|
|
|
filetype = vimsupport.CurrentFiletypes()[ 0 ]
|
|
|
|
if filetype in self._filetypes_with_keywords_loaded:
|
|
|
|
return
|
|
|
|
|
|
|
|
self._filetypes_with_keywords_loaded.add( filetype )
|
|
|
|
extra_data[ 'syntax_keywords' ] = list(
|
|
|
|
syntax_parse.SyntaxKeywordsForCurrentBuffer() )
|
|
|
|
|
2013-09-07 20:39:52 -04:00
|
|
|
|
2013-10-26 19:22:43 -04:00
|
|
|
def _AddTagsFilesIfNeeded( self, extra_data ):
|
|
|
|
def GetTagFiles():
|
|
|
|
tag_files = vim.eval( 'tagfiles()' )
|
|
|
|
current_working_directory = os.getcwd()
|
|
|
|
return [ os.path.join( current_working_directory, x ) for x in tag_files ]
|
|
|
|
|
|
|
|
if not self._user_options[ 'collect_identifiers_from_tags_files' ]:
|
|
|
|
return
|
|
|
|
extra_data[ 'tag_files' ] = GetTagFiles()
|
|
|
|
|
|
|
|
|
|
|
|
def _AddExtraConfDataIfNeeded( self, extra_data ):
|
|
|
|
def BuildExtraConfData( extra_conf_vim_data ):
|
|
|
|
return dict( ( expr, vimsupport.VimExpressionToPythonType( expr ) )
|
|
|
|
for expr in extra_conf_vim_data )
|
|
|
|
|
|
|
|
extra_conf_vim_data = self._user_options[ 'extra_conf_vim_data' ]
|
|
|
|
if extra_conf_vim_data:
|
|
|
|
extra_data[ 'extra_conf_data' ] = BuildExtraConfData(
|
|
|
|
extra_conf_vim_data )
|
2013-09-20 20:24:34 -04:00
|
|
|
|
|
|
|
|
|
|
|
def _PathToServerScript():
|
|
|
|
dir_of_current_script = os.path.dirname( os.path.abspath( __file__ ) )
|
2014-05-13 16:09:19 -04:00
|
|
|
return os.path.join( dir_of_current_script, '../../third_party/ycmd/ycmd' )
|
2013-09-23 18:31:11 -04:00
|
|
|
|
2013-09-25 13:56:46 -04:00
|
|
|
|
|
|
|
def _AddUltiSnipsDataIfNeeded( extra_data ):
|
|
|
|
if not USE_ULTISNIPS_DATA:
|
|
|
|
return
|
|
|
|
|
|
|
|
try:
|
|
|
|
rawsnips = UltiSnips_Manager._snips( '', 1 )
|
|
|
|
except:
|
|
|
|
return
|
|
|
|
|
|
|
|
# UltiSnips_Manager._snips() returns a class instance where:
|
|
|
|
# class.trigger - name of snippet trigger word ( e.g. defn or testcase )
|
|
|
|
# class.description - description of the snippet
|
|
|
|
extra_data[ 'ultisnips_snippets' ] = [ { 'trigger': x.trigger,
|
|
|
|
'description': x.description
|
|
|
|
} for x in rawsnips ]
|
2014-01-05 15:58:13 -05:00
|
|
|
|
|
|
|
|