2016-10-11 22:40:25 -04:00
|
|
|
# Copyright (C) 2011-2012 Google Inc.
|
|
|
|
# 2016 YouCompleteMe contributors
|
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/>.
|
|
|
|
|
2016-02-27 19:12:24 -05:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
from __future__ import print_function
|
|
|
|
from __future__ import division
|
|
|
|
from __future__ import absolute_import
|
|
|
|
from future import standard_library
|
|
|
|
standard_library.install_aliases()
|
|
|
|
from builtins import * # noqa
|
|
|
|
|
|
|
|
from future.utils import iteritems
|
2016-05-06 01:52:04 -04:00
|
|
|
import base64
|
2013-09-24 17:00:27 -04:00
|
|
|
import json
|
2016-05-06 01:52:04 -04:00
|
|
|
import logging
|
|
|
|
import os
|
2015-08-31 12:51:23 -04:00
|
|
|
import re
|
2014-01-29 13:18:07 -05:00
|
|
|
import signal
|
2016-05-06 01:52:04 -04:00
|
|
|
import vim
|
2014-03-02 01:14:14 -05:00
|
|
|
from subprocess import PIPE
|
2016-02-28 21:01:19 -05:00
|
|
|
from tempfile import NamedTemporaryFile
|
2016-08-18 14:39:50 -04:00
|
|
|
from ycm import base, paths, vimsupport
|
2014-05-13 16:09:19 -04:00
|
|
|
from ycmd import utils
|
2016-03-18 02:10:24 -04:00
|
|
|
from ycmd import server_utils
|
2014-05-27 20:38:34 -04:00
|
|
|
from ycmd.request_wrap import RequestWrap
|
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
|
2013-11-20 15:33:57 -05:00
|
|
|
from ycm.client.ycmd_keepalive import YcmdKeepalive
|
2016-11-05 09:57:02 -04:00
|
|
|
from ycm.client.base_request import ( BaseRequest, BuildRequestData,
|
|
|
|
HandleServerException )
|
2015-06-11 18:04:56 -04:00
|
|
|
from ycm.client.completer_available_request import SendCompleterAvailableRequest
|
2013-09-24 13:17:38 -04:00
|
|
|
from ycm.client.command_request import SendCommandRequest
|
2015-09-09 10:27:15 -04:00
|
|
|
from ycm.client.completion_request import ( CompletionRequest,
|
|
|
|
ConvertCompletionDataToVimData )
|
2016-11-05 09:57:02 -04:00
|
|
|
from ycm.client.debug_info_request import SendDebugInfoRequest
|
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 )
|
2015-05-26 08:57:11 -04:00
|
|
|
from ycm.client.shutdown_request import SendShutdownRequest
|
2013-09-07 20:39:52 -04:00
|
|
|
|
2016-03-06 12:13:43 -05:00
|
|
|
|
2014-09-11 18:19:26 -04:00
|
|
|
def PatchNoProxy():
|
|
|
|
current_value = os.environ.get('no_proxy', '')
|
|
|
|
additions = '127.0.0.1,localhost'
|
|
|
|
os.environ['no_proxy'] = ( additions if not current_value
|
|
|
|
else current_value + ',' + additions )
|
|
|
|
|
2016-11-15 05:15:16 -05:00
|
|
|
|
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
|
2014-09-11 18:19:26 -04:00
|
|
|
PatchNoProxy()
|
2013-11-04 13:34:42 -05:00
|
|
|
|
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
|
2016-03-18 02:10:24 -04:00
|
|
|
SERVER_SHUTDOWN_MESSAGE = (
|
|
|
|
"The ycmd server SHUT DOWN (restart with ':YcmRestartServer')." )
|
2016-05-06 01:52:04 -04:00
|
|
|
EXIT_CODE_UNEXPECTED_MESSAGE = (
|
|
|
|
"Unexpected exit code {code}. "
|
|
|
|
"Use the ':YcmToggleLogs' command to check the logs." )
|
2016-03-18 02:10:24 -04:00
|
|
|
CORE_UNEXPECTED_MESSAGE = (
|
2016-05-06 01:52:04 -04:00
|
|
|
"Unexpected error while loading the YCM core library. "
|
|
|
|
"Use the ':YcmToggleLogs' command to check the logs." )
|
2016-03-18 02:10:24 -04:00
|
|
|
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.' )
|
2013-11-20 15:33:57 -05:00
|
|
|
SERVER_IDLE_SUICIDE_SECONDS = 10800 # 3 hours
|
2016-01-11 14:16:49 -05:00
|
|
|
DIAGNOSTIC_UI_FILETYPES = set( [ 'cpp', 'cs', 'c', 'objc', 'objcpp' ] )
|
2016-05-06 01:52:04 -04:00
|
|
|
CLIENT_LOGFILE_FORMAT = 'ycm_'
|
|
|
|
SERVER_LOGFILE_FORMAT = 'ycmd_{port}_{std}_'
|
|
|
|
|
|
|
|
# Flag to set a file handle inheritable by child processes on Windows. See
|
|
|
|
# https://msdn.microsoft.com/en-us/library/ms724935.aspx
|
|
|
|
HANDLE_FLAG_INHERIT = 0x00000001
|
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 ):
|
2015-05-26 08:57:11 -04:00
|
|
|
self._available_completers = {}
|
2013-09-02 17:45:53 -04:00
|
|
|
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 16:15:43 -04:00
|
|
|
self._latest_file_parse_request = None
|
2014-05-27 20:38:34 -04:00
|
|
|
self._latest_completion_request = None
|
2016-01-11 14:16:49 -05:00
|
|
|
self._latest_diagnostics = []
|
2016-05-06 01:52:04 -04:00
|
|
|
self._logger = logging.getLogger( 'ycm' )
|
|
|
|
self._client_logfile = 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()
|
2016-05-06 01:52:04 -04:00
|
|
|
self._SetupLogging()
|
2013-09-23 16:27:32 -04:00
|
|
|
self._SetupServer()
|
2013-11-20 15:33:57 -05:00
|
|
|
self._ycmd_keepalive.Start()
|
2015-08-31 12:51:23 -04:00
|
|
|
self._complete_done_hooks = {
|
2016-02-28 17:41:09 -05:00
|
|
|
'cs': lambda self: self._OnCompleteDone_Csharp()
|
2015-08-31 12:51:23 -04:00
|
|
|
}
|
2013-09-02 22:46:30 -04:00
|
|
|
|
2013-09-23 16:27:32 -04:00
|
|
|
def _SetupServer( self ):
|
2015-06-11 18:04:56 -04:00
|
|
|
self._available_completers = {}
|
2015-05-26 08:57:11 -04:00
|
|
|
self._user_notified_about_crash = False
|
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
|
2016-02-28 21:01:19 -05:00
|
|
|
with NamedTemporaryFile( delete = False, mode = 'w+' ) as options_file:
|
2014-04-25 14:07:08 -04:00
|
|
|
hmac_secret = os.urandom( HMAC_SECRET_LENGTH )
|
|
|
|
options_dict = dict( self._user_options )
|
2016-02-28 17:41:09 -05:00
|
|
|
options_dict[ 'hmac_secret' ] = utils.ToUnicode(
|
|
|
|
base64.b64encode( hmac_secret ) )
|
2016-05-06 01:52:04 -04:00
|
|
|
options_dict[ 'server_keep_logfiles' ] = self._user_options[
|
|
|
|
'keep_logfiles' ]
|
2014-04-25 14:07:08 -04:00
|
|
|
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
|
|
|
|
2015-10-08 05:36:34 -04:00
|
|
|
args = [ paths.PathToPythonInterpreter(),
|
|
|
|
paths.PathToServerScript(),
|
2013-10-09 22:28:27 -04:00
|
|
|
'--port={0}'.format( server_port ),
|
|
|
|
'--options_file={0}'.format( options_file.name ),
|
2016-05-06 01:52:04 -04:00
|
|
|
'--log={0}'.format( self._user_options[ 'log_level' ] ),
|
2013-10-23 15:33:27 -04:00
|
|
|
'--idle_suicide_seconds={0}'.format(
|
2015-05-26 08:57:11 -04:00
|
|
|
SERVER_IDLE_SUICIDE_SECONDS ) ]
|
2013-09-24 17:00:27 -04:00
|
|
|
|
2016-10-20 04:33:59 -04:00
|
|
|
self._server_stdout = utils.CreateLogfile(
|
2016-05-06 01:52:04 -04:00
|
|
|
SERVER_LOGFILE_FORMAT.format( port = server_port, std = 'stdout' ) )
|
2016-10-20 04:33:59 -04:00
|
|
|
self._server_stderr = utils.CreateLogfile(
|
2016-05-06 01:52:04 -04:00
|
|
|
SERVER_LOGFILE_FORMAT.format( port = server_port, std = 'stderr' ) )
|
2015-10-27 08:12:58 -04:00
|
|
|
args.append( '--stdout={0}'.format( self._server_stdout ) )
|
|
|
|
args.append( '--stderr={0}'.format( self._server_stderr ) )
|
|
|
|
|
2016-05-06 01:52:04 -04:00
|
|
|
if self._user_options[ 'keep_logfiles' ]:
|
2015-10-27 08:12:58 -04:00
|
|
|
args.append( '--keep_logfiles' )
|
2013-10-15 14:19:56 -04:00
|
|
|
|
2015-07-02 14:47:13 -04:00
|
|
|
self._server_popen = utils.SafePopen( args, stdin_windows = PIPE,
|
2016-02-19 14:02:58 -05:00
|
|
|
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
|
|
|
|
2016-02-19 14:02:58 -05:00
|
|
|
|
2016-05-06 01:52:04 -04:00
|
|
|
def _SetupLogging( self ):
|
|
|
|
def FreeFileFromOtherProcesses( file_object ):
|
|
|
|
if utils.OnWindows():
|
|
|
|
from ctypes import windll
|
|
|
|
import msvcrt
|
|
|
|
|
|
|
|
file_handle = msvcrt.get_osfhandle( file_object.fileno() )
|
|
|
|
windll.kernel32.SetHandleInformation( file_handle,
|
|
|
|
HANDLE_FLAG_INHERIT,
|
|
|
|
0 )
|
|
|
|
|
|
|
|
self._client_logfile = utils.CreateLogfile( CLIENT_LOGFILE_FORMAT )
|
|
|
|
|
|
|
|
log_level = self._user_options[ 'log_level' ]
|
|
|
|
numeric_level = getattr( logging, log_level.upper(), None )
|
|
|
|
if not isinstance( numeric_level, int ):
|
|
|
|
raise ValueError( 'Invalid log level: {0}'.format( log_level ) )
|
|
|
|
self._logger.setLevel( numeric_level )
|
|
|
|
|
|
|
|
handler = logging.FileHandler( self._client_logfile )
|
|
|
|
|
|
|
|
# On Windows and Python prior to 3.4, file handles are inherited by child
|
|
|
|
# processes started with at least one replaced standard stream, which is the
|
|
|
|
# case when we start the ycmd server (we are redirecting all standard
|
|
|
|
# outputs into a pipe). These files cannot be removed while the child
|
|
|
|
# processes are still up. This is not desirable for a logfile because we
|
|
|
|
# want to remove it at Vim exit without having to wait for the ycmd server
|
|
|
|
# to be completely shut down. We need to make the logfile handle
|
|
|
|
# non-inheritable. See https://www.python.org/dev/peps/pep-0446 for more
|
|
|
|
# details.
|
|
|
|
FreeFileFromOtherProcesses( handler.stream )
|
|
|
|
|
|
|
|
formatter = logging.Formatter( '%(asctime)s - %(levelname)s - %(message)s' )
|
|
|
|
handler.setFormatter( formatter )
|
|
|
|
|
|
|
|
self._logger.addHandler( handler )
|
|
|
|
|
|
|
|
|
2014-05-27 20:38:34 -04:00
|
|
|
def IsServerAlive( self ):
|
2016-05-06 01:52:04 -04:00
|
|
|
return_code = self._server_popen.poll()
|
2013-10-15 18:27:54 -04:00
|
|
|
# When the process hasn't finished yet, poll() returns None.
|
2016-05-06 01:52:04 -04:00
|
|
|
return return_code is None
|
2013-10-15 18:27:54 -04:00
|
|
|
|
|
|
|
|
|
|
|
def _NotifyUserIfServerCrashed( self ):
|
2014-05-27 20:38:34 -04: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
|
2016-03-18 02:10:24 -04:00
|
|
|
|
|
|
|
return_code = self._server_popen.poll()
|
|
|
|
if return_code == server_utils.CORE_UNEXPECTED_STATUS:
|
2016-05-06 01:52:04 -04:00
|
|
|
error_message = CORE_UNEXPECTED_MESSAGE
|
2016-03-18 02:10:24 -04:00
|
|
|
elif return_code == server_utils.CORE_MISSING_STATUS:
|
2016-05-06 01:52:04 -04:00
|
|
|
error_message = CORE_MISSING_MESSAGE
|
2016-03-18 02:10:24 -04:00
|
|
|
elif return_code == server_utils.CORE_PYTHON2_STATUS:
|
2016-05-06 01:52:04 -04:00
|
|
|
error_message = CORE_PYTHON2_MESSAGE
|
2016-03-18 02:10:24 -04:00
|
|
|
elif return_code == server_utils.CORE_PYTHON3_STATUS:
|
2016-05-06 01:52:04 -04:00
|
|
|
error_message = CORE_PYTHON3_MESSAGE
|
2016-03-18 02:10:24 -04:00
|
|
|
elif return_code == server_utils.CORE_OUTDATED_STATUS:
|
2016-05-06 01:52:04 -04:00
|
|
|
error_message = CORE_OUTDATED_MESSAGE
|
2016-03-18 02:10:24 -04:00
|
|
|
else:
|
2016-05-06 01:52:04 -04:00
|
|
|
error_message = EXIT_CODE_UNEXPECTED_MESSAGE.format( code = return_code )
|
|
|
|
|
|
|
|
server_stderr = '\n'.join( self._server_popen.stderr.read().splitlines() )
|
|
|
|
if server_stderr:
|
|
|
|
self._logger.error( server_stderr )
|
|
|
|
|
|
|
|
error_message = SERVER_SHUTDOWN_MESSAGE + ' ' + error_message
|
|
|
|
self._logger.error( error_message )
|
|
|
|
vimsupport.PostVimMessage( error_message )
|
2013-10-15 18:27:54 -04:00
|
|
|
|
|
|
|
|
2013-10-22 13:51:37 -04:00
|
|
|
def ServerPid( self ):
|
|
|
|
if not self._server_popen:
|
|
|
|
return -1
|
|
|
|
return self._server_popen.pid
|
|
|
|
|
|
|
|
|
2015-05-26 08:57:11 -04:00
|
|
|
def _ShutdownServer( self ):
|
2014-05-27 20:38:34 -04:00
|
|
|
if self.IsServerAlive():
|
2015-05-26 08:57:11 -04:00
|
|
|
SendShutdownRequest()
|
2013-12-20 16:01:48 -05:00
|
|
|
|
2014-03-07 14:28:53 -05:00
|
|
|
|
2013-10-15 18:27:54 -04:00
|
|
|
def RestartServer( self ):
|
|
|
|
vimsupport.PostVimMessage( 'Restarting ycmd server...' )
|
2015-05-26 08:57:11 -04:00
|
|
|
self._ShutdownServer()
|
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 ):
|
2014-05-27 20:38:34 -04:00
|
|
|
request_data = BuildRequestData()
|
2013-10-07 18:47:48 -04:00
|
|
|
if ( not self.NativeFiletypeCompletionAvailable() and
|
2014-05-27 20:38:34 -04:00
|
|
|
self.CurrentFiletypeCompletionEnabled() ):
|
|
|
|
wrapped_request_data = RequestWrap( request_data )
|
|
|
|
if self._omnicomp.ShouldUseNow( wrapped_request_data ):
|
|
|
|
self._latest_completion_request = OmniCompletionRequest(
|
|
|
|
self._omnicomp, wrapped_request_data )
|
|
|
|
return self._latest_completion_request
|
|
|
|
|
2016-10-11 22:40:25 -04:00
|
|
|
request_data[ 'working_dir' ] = utils.GetCurrentDirectory()
|
2015-08-26 18:41:40 -04:00
|
|
|
|
2014-05-27 20:38:34 -04:00
|
|
|
self._AddExtraConfDataIfNeeded( request_data )
|
|
|
|
if force_semantic:
|
|
|
|
request_data[ 'force_semantic' ] = True
|
|
|
|
self._latest_completion_request = CompletionRequest( request_data )
|
2013-10-03 13:14:31 -04:00
|
|
|
return self._latest_completion_request
|
2013-09-02 22:46:30 -04:00
|
|
|
|
|
|
|
|
2016-08-18 14:39:50 -04:00
|
|
|
def GetCompletions( self ):
|
|
|
|
request = self.GetCurrentCompletionRequest()
|
|
|
|
request.Start()
|
|
|
|
while not request.Done():
|
|
|
|
try:
|
|
|
|
if vimsupport.GetBoolValue( 'complete_check()' ):
|
|
|
|
return { 'words' : [], 'refresh' : 'always' }
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
return { 'words' : [], 'refresh' : 'always' }
|
|
|
|
|
|
|
|
results = base.AdjustCandidateInsertionText( request.Response() )
|
|
|
|
return { 'words' : results, 'refresh' : 'always' }
|
|
|
|
|
|
|
|
|
2013-09-06 02:43:14 -04:00
|
|
|
def SendCommandRequest( self, arguments, completer ):
|
2014-05-27 20:38:34 -04:00
|
|
|
if self.IsServerAlive():
|
2013-10-15 18:27:54 -04:00
|
|
|
return SendCommandRequest( arguments, completer )
|
2013-09-06 02:43:14 -04:00
|
|
|
|
|
|
|
|
2013-09-27 19:20:35 -04:00
|
|
|
def GetDefinedSubcommands( self ):
|
2014-05-27 20:38:34 -04:00
|
|
|
if self.IsServerAlive():
|
2016-11-05 09:57:02 -04:00
|
|
|
with HandleServerException():
|
2014-05-22 17:12:51 -04:00
|
|
|
return BaseRequest.PostDataToHandler( BuildRequestData(),
|
2016-11-05 09:57:02 -04:00
|
|
|
'defined_subcommands' )
|
|
|
|
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
|
|
|
|
|
|
|
|
2015-06-11 18:04:56 -04:00
|
|
|
def FiletypeCompleterExistsForFiletype( self, filetype ):
|
|
|
|
try:
|
|
|
|
return self._available_completers[ filetype ]
|
|
|
|
except KeyError:
|
|
|
|
pass
|
|
|
|
|
2016-01-12 13:58:18 -05:00
|
|
|
if not self.IsServerAlive():
|
|
|
|
return False
|
|
|
|
|
|
|
|
exists_completer = SendCompleterAvailableRequest( filetype )
|
|
|
|
if exists_completer is None:
|
|
|
|
return False
|
|
|
|
|
2015-06-11 18:04:56 -04:00
|
|
|
self._available_completers[ filetype ] = exists_completer
|
|
|
|
return exists_completer
|
|
|
|
|
|
|
|
|
2013-02-10 22:55:05 -05:00
|
|
|
def NativeFiletypeCompletionAvailable( self ):
|
2015-06-11 18:04:56 -04:00
|
|
|
return any( [ self.FiletypeCompleterExistsForFiletype( x ) for x in
|
2013-10-07 19:10:48 -04:00
|
|
|
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 ):
|
2014-05-27 20:38:34 -04:00
|
|
|
if not self.IsServerAlive():
|
2013-10-15 18:27:54 -04:00
|
|
|
self._NotifyUserIfServerCrashed()
|
2016-03-09 07:39:11 -05:00
|
|
|
return
|
|
|
|
|
|
|
|
self._omnicomp.OnFileReadyToParse( None )
|
2013-10-15 18:27:54 -04:00
|
|
|
|
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
|
|
|
|
2016-09-05 11:33:30 -04:00
|
|
|
self._latest_file_parse_request = EventNotification(
|
|
|
|
'FileReadyToParse', extra_data = extra_data )
|
2013-10-03 16:15:43 -04:00
|
|
|
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 ):
|
2014-05-27 20:38:34 -04:00
|
|
|
if not self.IsServerAlive():
|
2013-10-15 18:27:54 -04:00
|
|
|
return
|
2016-10-25 18:24:08 -04:00
|
|
|
SendEventNotificationAsync( 'BufferUnload', filepath = deleted_buffer_file )
|
2013-03-14 23:39:44 -04:00
|
|
|
|
|
|
|
|
2013-04-24 16:31:28 -04:00
|
|
|
def OnBufferVisit( self ):
|
2014-05-27 20:38:34 -04:00
|
|
|
if not self.IsServerAlive():
|
2013-10-15 18:27:54 -04:00
|
|
|
return
|
2013-09-25 13:56:46 -04:00
|
|
|
extra_data = {}
|
2016-09-08 12:09:27 -04:00
|
|
|
self._AddUltiSnipsDataIfNeeded( extra_data )
|
2016-09-05 11:33:30 -04:00
|
|
|
SendEventNotificationAsync( 'BufferVisit', extra_data = extra_data )
|
2013-04-24 16:31:28 -04:00
|
|
|
|
|
|
|
|
2012-08-04 20:46:54 -04:00
|
|
|
def OnInsertLeave( self ):
|
2014-05-27 20:38:34 -04:00
|
|
|
if not self.IsServerAlive():
|
2013-10-15 18:27:54 -04:00
|
|
|
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()
|
|
|
|
|
|
|
|
|
2016-05-06 01:52:04 -04:00
|
|
|
def _CleanLogfile( self ):
|
|
|
|
logging.shutdown()
|
|
|
|
if not self._user_options[ 'keep_logfiles' ]:
|
|
|
|
if self._client_logfile:
|
|
|
|
utils.RemoveIfExists( self._client_logfile )
|
|
|
|
|
|
|
|
|
2013-07-07 13:59:48 -04:00
|
|
|
def OnVimLeave( self ):
|
2015-05-26 08:57:11 -04:00
|
|
|
self._ShutdownServer()
|
2016-05-06 01:52:04 -04:00
|
|
|
self._CleanLogfile()
|
2013-10-17 15:21:59 -04:00
|
|
|
|
2013-09-07 20:39:52 -04:00
|
|
|
|
|
|
|
def OnCurrentIdentifierFinished( self ):
|
2014-05-27 20:38:34 -04:00
|
|
|
if not self.IsServerAlive():
|
2013-10-15 18:27:54 -04:00
|
|
|
return
|
2013-09-20 20:24:34 -04:00
|
|
|
SendEventNotificationAsync( 'CurrentIdentifierFinished' )
|
2013-07-07 13:59:48 -04:00
|
|
|
|
|
|
|
|
2015-08-28 10:26:18 -04:00
|
|
|
def OnCompleteDone( self ):
|
2015-08-31 12:51:23 -04:00
|
|
|
complete_done_actions = self.GetCompleteDoneHooks()
|
|
|
|
for action in complete_done_actions:
|
|
|
|
action(self)
|
|
|
|
|
|
|
|
|
|
|
|
def GetCompleteDoneHooks( self ):
|
|
|
|
filetypes = vimsupport.CurrentFiletypes()
|
2016-02-27 19:12:24 -05:00
|
|
|
for key, value in iteritems( self._complete_done_hooks ):
|
2015-08-31 12:51:23 -04:00
|
|
|
if key in filetypes:
|
|
|
|
yield value
|
|
|
|
|
2015-08-28 10:26:18 -04:00
|
|
|
|
2015-09-10 11:18:48 -04:00
|
|
|
def GetCompletionsUserMayHaveCompleted( self ):
|
2015-08-28 10:26:18 -04:00
|
|
|
latest_completion_request = self.GetCurrentCompletionRequest()
|
2015-09-09 10:27:15 -04:00
|
|
|
if not latest_completion_request or not latest_completion_request.Done():
|
2015-08-31 12:51:23 -04:00
|
|
|
return []
|
2015-08-28 10:26:18 -04:00
|
|
|
|
|
|
|
completions = latest_completion_request.RawResponse()
|
2015-09-09 10:27:15 -04:00
|
|
|
|
2015-09-10 11:18:48 -04:00
|
|
|
result = self._FilterToMatchingCompletions( completions, True )
|
2015-09-09 10:27:15 -04:00
|
|
|
result = list( result )
|
|
|
|
if result:
|
|
|
|
return result
|
|
|
|
|
2015-09-10 11:18:48 -04:00
|
|
|
if self._HasCompletionsThatCouldBeCompletedWithMoreText( completions ):
|
2015-08-31 12:51:23 -04:00
|
|
|
# Since the way that YCM works leads to CompleteDone called on every
|
|
|
|
# character, return blank if the completion might not be done. This won't
|
|
|
|
# match if the completion is ended with typing a non-keyword character.
|
|
|
|
return []
|
|
|
|
|
2015-09-10 11:18:48 -04:00
|
|
|
result = self._FilterToMatchingCompletions( completions, False )
|
2015-08-31 12:51:23 -04:00
|
|
|
|
|
|
|
return list( result )
|
|
|
|
|
|
|
|
|
2015-09-10 11:18:48 -04:00
|
|
|
def _FilterToMatchingCompletions( self, completions, full_match_only ):
|
|
|
|
self._PatchBasedOnVimVersion()
|
|
|
|
return self._FilterToMatchingCompletions( completions, full_match_only)
|
|
|
|
|
|
|
|
|
|
|
|
def _HasCompletionsThatCouldBeCompletedWithMoreText( self, completions ):
|
|
|
|
self._PatchBasedOnVimVersion()
|
|
|
|
return self._HasCompletionsThatCouldBeCompletedWithMoreText( completions )
|
|
|
|
|
|
|
|
|
|
|
|
def _PatchBasedOnVimVersion( self ):
|
2015-09-09 10:27:15 -04:00
|
|
|
if vimsupport.VimVersionAtLeast( "7.4.774" ):
|
2015-09-10 11:18:48 -04:00
|
|
|
self._HasCompletionsThatCouldBeCompletedWithMoreText = \
|
|
|
|
self._HasCompletionsThatCouldBeCompletedWithMoreText_NewerVim
|
|
|
|
self._FilterToMatchingCompletions = \
|
|
|
|
self._FilterToMatchingCompletions_NewerVim
|
2015-09-09 10:27:15 -04:00
|
|
|
else:
|
2015-09-10 11:18:48 -04:00
|
|
|
self._FilterToMatchingCompletions = \
|
|
|
|
self._FilterToMatchingCompletions_OlderVim
|
|
|
|
self._HasCompletionsThatCouldBeCompletedWithMoreText = \
|
|
|
|
self._HasCompletionsThatCouldBeCompletedWithMoreText_OlderVim
|
|
|
|
|
|
|
|
|
2016-03-25 23:40:17 -04:00
|
|
|
def _FilterToMatchingCompletions_NewerVim( self,
|
|
|
|
completions,
|
2015-09-10 11:18:48 -04:00
|
|
|
full_match_only ):
|
2016-03-25 23:40:17 -04:00
|
|
|
"""Filter to completions matching the item Vim said was completed"""
|
2015-09-10 11:18:48 -04:00
|
|
|
completed = vimsupport.GetVariableValue( 'v:completed_item' )
|
|
|
|
for completion in completions:
|
|
|
|
item = ConvertCompletionDataToVimData( completion )
|
|
|
|
match_keys = ( [ "word", "abbr", "menu", "info" ] if full_match_only
|
|
|
|
else [ 'word' ] )
|
2016-03-06 12:13:43 -05:00
|
|
|
|
|
|
|
def matcher( key ):
|
2016-03-25 23:40:17 -04:00
|
|
|
return ( utils.ToUnicode( completed.get( key, "" ) ) ==
|
|
|
|
utils.ToUnicode( item.get( key, "" ) ) )
|
2016-03-06 12:13:43 -05:00
|
|
|
|
2015-09-10 11:18:48 -04:00
|
|
|
if all( [ matcher( i ) for i in match_keys ] ):
|
|
|
|
yield completion
|
|
|
|
|
|
|
|
|
|
|
|
def _FilterToMatchingCompletions_OlderVim( self, completions,
|
|
|
|
full_match_only ):
|
|
|
|
""" Filter to completions matching the buffer text """
|
|
|
|
if full_match_only:
|
|
|
|
return # Only supported in 7.4.774+
|
|
|
|
# No support for multiple line completions
|
|
|
|
text = vimsupport.TextBeforeCursor()
|
|
|
|
for completion in completions:
|
|
|
|
word = completion[ "insertion_text" ]
|
|
|
|
# Trim complete-ending character if needed
|
|
|
|
text = re.sub( r"[^a-zA-Z0-9_]$", "", text )
|
|
|
|
buffer_text = text[ -1 * len( word ) : ]
|
|
|
|
if buffer_text == word:
|
|
|
|
yield completion
|
|
|
|
|
|
|
|
|
|
|
|
def _HasCompletionsThatCouldBeCompletedWithMoreText_NewerVim( self,
|
|
|
|
completions ):
|
|
|
|
completed_item = vimsupport.GetVariableValue( 'v:completed_item' )
|
2015-12-27 12:46:05 -05:00
|
|
|
if not completed_item:
|
|
|
|
return False
|
|
|
|
|
2016-03-25 23:40:17 -04:00
|
|
|
completed_word = utils.ToUnicode( completed_item[ 'word' ] )
|
2015-09-10 11:18:48 -04:00
|
|
|
if not completed_word:
|
|
|
|
return False
|
|
|
|
|
2016-03-25 23:40:17 -04:00
|
|
|
# Sometimes CompleteDone is called after the next character is inserted.
|
|
|
|
# If so, use inserted character to filter possible completions further.
|
2015-09-10 11:18:48 -04:00
|
|
|
text = vimsupport.TextBeforeCursor()
|
|
|
|
reject_exact_match = True
|
|
|
|
if text and text[ -1 ] != completed_word[ -1 ]:
|
|
|
|
reject_exact_match = False
|
|
|
|
completed_word += text[ -1 ]
|
|
|
|
|
|
|
|
for completion in completions:
|
2016-03-25 23:40:17 -04:00
|
|
|
word = utils.ToUnicode(
|
|
|
|
ConvertCompletionDataToVimData( completion )[ 'word' ] )
|
2015-09-10 11:18:48 -04:00
|
|
|
if reject_exact_match and word == completed_word:
|
|
|
|
continue
|
|
|
|
if word.startswith( completed_word ):
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
def _HasCompletionsThatCouldBeCompletedWithMoreText_OlderVim( self,
|
|
|
|
completions ):
|
|
|
|
# No support for multiple line completions
|
|
|
|
text = vimsupport.TextBeforeCursor()
|
|
|
|
for completion in completions:
|
2016-03-25 23:40:17 -04:00
|
|
|
word = utils.ToUnicode(
|
|
|
|
ConvertCompletionDataToVimData( completion )[ 'word' ] )
|
2015-09-10 11:18:48 -04:00
|
|
|
for i in range( 1, len( word ) - 1 ): # Excluding full word
|
2016-03-25 23:40:17 -04:00
|
|
|
if text[ -1 * i : ] == word[ : i ]:
|
2015-08-31 12:51:23 -04:00
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2015-08-28 10:26:18 -04:00
|
|
|
|
2015-09-10 11:18:48 -04:00
|
|
|
def _OnCompleteDone_Csharp( self ):
|
|
|
|
completions = self.GetCompletionsUserMayHaveCompleted()
|
|
|
|
namespaces = [ self._GetRequiredNamespaceImport( c )
|
2015-08-28 10:26:18 -04:00
|
|
|
for c in completions ]
|
|
|
|
namespaces = [ n for n in namespaces if n ]
|
|
|
|
if not namespaces:
|
|
|
|
return
|
|
|
|
|
|
|
|
if len( namespaces ) > 1:
|
2015-08-31 12:51:23 -04:00
|
|
|
choices = [ "{0} {1}".format( i + 1, n )
|
2016-03-06 12:13:43 -05:00
|
|
|
for i, n in enumerate( namespaces ) ]
|
2015-08-31 12:51:23 -04:00
|
|
|
choice = vimsupport.PresentDialog( "Insert which namespace:", choices )
|
2015-08-28 10:26:18 -04:00
|
|
|
if choice < 0:
|
|
|
|
return
|
|
|
|
namespace = namespaces[ choice ]
|
|
|
|
else:
|
|
|
|
namespace = namespaces[ 0 ]
|
|
|
|
|
|
|
|
vimsupport.InsertNamespace( namespace )
|
|
|
|
|
|
|
|
|
2015-09-10 11:18:48 -04:00
|
|
|
def _GetRequiredNamespaceImport( self, completion ):
|
2015-08-28 10:26:18 -04:00
|
|
|
if ( "extra_data" not in completion
|
|
|
|
or "required_namespace_import" not in completion[ "extra_data" ] ):
|
2015-08-31 12:51:23 -04:00
|
|
|
return None
|
2015-08-28 10:26:18 -04:00
|
|
|
return completion[ "extra_data" ][ "required_namespace_import" ]
|
|
|
|
|
2016-01-11 14:16:49 -05:00
|
|
|
|
2015-12-04 17:45:11 -05:00
|
|
|
def GetErrorCount( self ):
|
|
|
|
return self._diag_interface.GetErrorCount()
|
|
|
|
|
2016-01-11 14:16:49 -05:00
|
|
|
|
2015-12-04 17:45:11 -05:00
|
|
|
def GetWarningCount( self ):
|
|
|
|
return self._diag_interface.GetWarningCount()
|
2015-08-28 10:26:18 -04:00
|
|
|
|
2013-10-03 13:14:31 -04:00
|
|
|
|
2016-01-11 14:16:49 -05:00
|
|
|
def DiagnosticUiSupportedForCurrentFiletype( self ):
|
|
|
|
return any( [ x in DIAGNOSTIC_UI_FILETYPES
|
|
|
|
for x in vimsupport.CurrentFiletypes() ] )
|
|
|
|
|
|
|
|
|
|
|
|
def ShouldDisplayDiagnostics( self ):
|
|
|
|
return bool( self._user_options[ 'show_diagnostics_ui' ] and
|
|
|
|
self.DiagnosticUiSupportedForCurrentFiletype() )
|
2013-10-03 13:14:31 -04:00
|
|
|
|
2016-01-11 14:16:49 -05:00
|
|
|
|
|
|
|
def PopulateLocationListWithLatestDiagnostics( self ):
|
|
|
|
# Do nothing if loc list is already populated by diag_interface
|
|
|
|
if not self._user_options[ 'always_populate_location_list' ]:
|
|
|
|
self._diag_interface.PopulateLocationList( self._latest_diagnostics )
|
|
|
|
return bool( self._latest_diagnostics )
|
2012-08-06 23:14:21 -04:00
|
|
|
|
|
|
|
|
2014-01-04 17:28:27 -05:00
|
|
|
def UpdateDiagnosticInterface( self ):
|
2016-01-11 14:16:49 -05:00
|
|
|
self._diag_interface.UpdateWithNewDiagnostics( self._latest_diagnostics )
|
2014-01-04 17:28:27 -05:00
|
|
|
|
|
|
|
|
2016-01-11 14:16:49 -05:00
|
|
|
def FileParseRequestReady( self, block = False ):
|
|
|
|
return bool( self._latest_file_parse_request and
|
|
|
|
( block or self._latest_file_parse_request.Done() ) )
|
2015-12-13 14:28:24 -05:00
|
|
|
|
|
|
|
|
2016-01-11 14:16:49 -05:00
|
|
|
def HandleFileParseRequest( self, block = False ):
|
|
|
|
# Order is important here:
|
|
|
|
# FileParseRequestReady has a low cost, while
|
|
|
|
# NativeFiletypeCompletionUsable is a blocking server request
|
|
|
|
if ( self.FileParseRequestReady( block ) and
|
|
|
|
self.NativeFiletypeCompletionUsable() ):
|
|
|
|
|
|
|
|
if self.ShouldDisplayDiagnostics():
|
|
|
|
self._latest_diagnostics = self._latest_file_parse_request.Response()
|
|
|
|
self.UpdateDiagnosticInterface()
|
|
|
|
else:
|
|
|
|
# YCM client has a hard-coded list of filetypes which are known
|
|
|
|
# to support diagnostics, self.DiagnosticUiSupportedForCurrentFiletype()
|
|
|
|
#
|
|
|
|
# For filetypes which don't support diagnostics, we just want to check
|
|
|
|
# the _latest_file_parse_request for any exception or UnknownExtraConf
|
|
|
|
# response, to allow the server to raise configuration warnings, etc.
|
|
|
|
# to the user. We ignore any other supplied data.
|
|
|
|
self._latest_file_parse_request.Response()
|
|
|
|
|
|
|
|
# We set the file parse request to None because we want to prevent
|
2015-12-13 14:28:24 -05:00
|
|
|
# repeated issuing of the same warnings/errors/prompts. Setting this to
|
2016-01-11 14:16:49 -05:00
|
|
|
# None makes FileParseRequestReady return False until the next
|
2015-12-13 14:28:24 -05:00
|
|
|
# request is created.
|
|
|
|
#
|
|
|
|
# Note: it is the server's responsibility to determine the frequency of
|
|
|
|
# error/warning/prompts when receiving a FileReadyToParse event, but
|
|
|
|
# it our responsibility to ensure that we only apply the
|
|
|
|
# warning/error/prompt received once (for each event).
|
|
|
|
self._latest_file_parse_request = None
|
|
|
|
|
|
|
|
|
2013-10-03 17:49:51 -04:00
|
|
|
def ShowDetailedDiagnostic( self ):
|
2014-05-27 20:38:34 -04:00
|
|
|
if not self.IsServerAlive():
|
2013-10-15 18:27:54 -04:00
|
|
|
return
|
2016-11-05 09:57:02 -04:00
|
|
|
with HandleServerException():
|
|
|
|
detailed_diagnostic = BaseRequest.PostDataToHandler(
|
|
|
|
BuildRequestData(), 'detailed_diagnostic' )
|
|
|
|
|
|
|
|
if 'message' in detailed_diagnostic:
|
|
|
|
vimsupport.PostVimMessage( detailed_diagnostic[ 'message' ],
|
2016-08-28 02:34:09 -04:00
|
|
|
warning = False )
|
2012-08-15 22:39:03 -04:00
|
|
|
|
|
|
|
|
2013-01-26 14:44:42 -05:00
|
|
|
def DebugInfo( self ):
|
2016-05-06 01:52:04 -04:00
|
|
|
debug_info = ''
|
|
|
|
if self._client_logfile:
|
|
|
|
debug_info += 'Client logfile: {0}\n'.format( self._client_logfile )
|
2014-05-27 20:38:34 -04:00
|
|
|
if self.IsServerAlive():
|
2016-11-05 09:57:02 -04:00
|
|
|
debug_info += SendDebugInfoRequest()
|
2013-10-15 18:27:54 -04:00
|
|
|
else:
|
2016-05-06 01:52:04 -04:00
|
|
|
debug_info += 'Server crashed, no debug info from server'
|
|
|
|
debug_info += '\nServer running at: {0}\n'.format(
|
2013-09-27 20:26:14 -04:00
|
|
|
BaseRequest.server_location )
|
2016-05-06 01:52:04 -04:00
|
|
|
debug_info += 'Server process ID: {0}\n'.format( self._server_popen.pid )
|
2013-09-27 20:26:14 -04:00
|
|
|
if self._server_stderr or self._server_stdout:
|
2016-05-06 01:52:04 -04:00
|
|
|
debug_info += ( 'Server logfiles:\n'
|
|
|
|
' {0}\n'
|
|
|
|
' {1}'.format( self._server_stdout,
|
|
|
|
self._server_stderr ) )
|
2013-09-27 20:26:14 -04:00
|
|
|
return debug_info
|
2013-01-26 14:44:42 -05:00
|
|
|
|
|
|
|
|
2016-05-06 01:52:04 -04:00
|
|
|
def GetLogfiles( self ):
|
|
|
|
logfiles_list = [ self._client_logfile,
|
|
|
|
self._server_stdout,
|
|
|
|
self._server_stderr ]
|
|
|
|
logfiles = {}
|
|
|
|
for logfile in logfiles_list:
|
|
|
|
logfiles[ os.path.basename( logfile ) ] = logfile
|
|
|
|
return logfiles
|
|
|
|
|
|
|
|
|
|
|
|
def _OpenLogfile( self, logfile ):
|
2015-10-27 12:00:11 -04:00
|
|
|
# Open log files in a horizontal window with the same behavior as the
|
|
|
|
# preview window (same height and winfixheight enabled). Automatically
|
|
|
|
# watch for changes. Set the cursor position at the end of the file.
|
|
|
|
options = {
|
|
|
|
'size': vimsupport.GetIntValue( '&previewheight' ),
|
|
|
|
'fix': True,
|
2016-05-06 01:52:04 -04:00
|
|
|
'focus': False,
|
2015-10-27 12:00:11 -04:00
|
|
|
'watch': True,
|
|
|
|
'position': 'end'
|
|
|
|
}
|
|
|
|
|
2016-05-06 01:52:04 -04:00
|
|
|
vimsupport.OpenFilename( logfile, options )
|
|
|
|
|
|
|
|
|
|
|
|
def _CloseLogfile( self, logfile ):
|
|
|
|
vimsupport.CloseBuffersForFilename( logfile )
|
2015-10-27 12:00:11 -04:00
|
|
|
|
|
|
|
|
2016-05-06 01:52:04 -04:00
|
|
|
def ToggleLogs( self, *filenames ):
|
|
|
|
logfiles = self.GetLogfiles()
|
|
|
|
if not filenames:
|
|
|
|
vimsupport.PostVimMessage(
|
|
|
|
'Available logfiles are:\n'
|
|
|
|
'{0}'.format( '\n'.join( sorted( list( logfiles ) ) ) ) )
|
|
|
|
return
|
2015-10-27 12:00:11 -04:00
|
|
|
|
2016-05-06 01:52:04 -04:00
|
|
|
for filename in set( filenames ):
|
|
|
|
if filename not in logfiles:
|
|
|
|
continue
|
2015-10-27 12:00:11 -04:00
|
|
|
|
2016-05-06 01:52:04 -04:00
|
|
|
logfile = logfiles[ filename ]
|
2015-10-27 12:00:11 -04:00
|
|
|
|
2016-05-06 01:52:04 -04:00
|
|
|
if not vimsupport.BufferIsVisibleForFilename( logfile ):
|
|
|
|
self._OpenLogfile( logfile )
|
|
|
|
continue
|
2015-11-11 08:32:01 -05:00
|
|
|
|
2016-05-06 01:52:04 -04:00
|
|
|
self._CloseLogfile( logfile )
|
2015-10-27 12:00:11 -04: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' ]
|
2014-03-06 11:43:44 -05:00
|
|
|
if '*' in filetype_to_disable:
|
|
|
|
return False
|
|
|
|
else:
|
2015-06-12 06:59:34 -04:00
|
|
|
return not any([ 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()' )
|
2016-10-11 22:40:25 -04:00
|
|
|
return [ os.path.join( utils.GetCurrentDirectory(), tag_file )
|
|
|
|
for tag_file in tag_files ]
|
2013-10-26 19:22:43 -04:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
2016-09-08 12:09:27 -04:00
|
|
|
def _AddUltiSnipsDataIfNeeded( self, extra_data ):
|
|
|
|
# See :h UltiSnips#SnippetsInCurrentScope.
|
|
|
|
try:
|
|
|
|
vim.eval( 'UltiSnips#SnippetsInCurrentScope( 1 )' )
|
|
|
|
except vim.error:
|
|
|
|
return
|
|
|
|
|
|
|
|
snippets = vimsupport.GetVariableValue( 'g:current_ulti_dict_info' )
|
|
|
|
extra_data[ 'ultisnips_snippets' ] = [
|
|
|
|
{ 'trigger': trigger,
|
|
|
|
'description': snippet[ 'description' ] }
|
|
|
|
for trigger, snippet in iteritems( snippets )
|
|
|
|
]
|