def GetUserOptions(default_options={}): """Builds a dictionary mapping YCM Vim user options to values. Option names don't have the 'ycm_' prefix.""" user_options = {} # First load the default settings from ycmd. We do this to ensure that any # client-side code that assumes all options are loaded (such as the # omnicompleter) don't have to constantly check for values being present, and # so that we don't jave to dulicate the list of server settings in # youcomplete.vim defaults_file = os.path.join(paths.DIR_OF_YCMD, 'ycmd', 'default_settings.json') if os.path.exists(defaults_file): with open(defaults_file) as defaults_file_handle: user_options = json.load(defaults_file_handle) # Override the server defaults with any client-generated defaults user_options.update(default_options) # Finally, override with any user-specified values in the g: dict # We only evaluate the keys of the vim globals and not the whole dictionary # to avoid unicode issues. # See https://github.com/Valloric/YouCompleteMe/pull/2151 for details. keys = vimsupport.GetVimGlobalsKeys() for key in keys: if not key.startswith(YCM_VAR_PREFIX): continue new_key = key[len(YCM_VAR_PREFIX):] new_value = vimsupport.VimExpressionToPythonType('g:' + key) user_options[new_key] = new_value return user_options
def BuildExtraConfData( extra_conf_vim_data ): extra_conf_data = {} for expr in extra_conf_vim_data: try: extra_conf_data[ expr ] = vimsupport.VimExpressionToPythonType( expr ) except vim.error: message = ( "Error evaluating '{expr}' in the 'g:ycm_extra_conf_vim_data' " "option.".format( expr = expr ) ) vimsupport.PostVimMessage( message, truncate = True ) self._logger.exception( message ) return extra_conf_data
def GetUserOptions(): """Builds a dictionary mapping YCM Vim user options to values. Option names don't have the 'ycm_' prefix.""" # We only evaluate the keys of the vim globals and not the whole dictionary # to avoid unicode issues. # See https://github.com/Valloric/YouCompleteMe/pull/2151 for details. keys = vimsupport.GetVimGlobalsKeys() user_options = {} for key in keys: if not key.startswith(YCM_VAR_PREFIX): continue new_key = key[len(YCM_VAR_PREFIX):] new_value = vimsupport.VimExpressionToPythonType('g:' + key) user_options[new_key] = new_value return user_options
def BuildExtraConfData(extra_conf_vim_data): return dict((expr, vimsupport.VimExpressionToPythonType(expr)) for expr in extra_conf_vim_data)
def VimExpressionToPythonType_GeneratorPassthrough_test( *args ): gen = ( x**2 for x in [ 1, 2, 3 ] ) eq_( vimsupport.VimExpressionToPythonType( gen ), gen )
def VimExpressionToPythonType_ObjectPassthrough_test( *args ): eq_( vimsupport.VimExpressionToPythonType( { 1: 2 } ), { 1: 2 } )
def VimExpressionToPythonType_ListPassthrough_test( *args ): eq_( vimsupport.VimExpressionToPythonType( [ 1, 2 ] ), [ 1, 2 ] )
def VimExpressionToPythonType_StringAsBytes_test( *args ): eq_( vimsupport.VimExpressionToPythonType( ToBytes( 'foo' ) ), 'foo' )
def VimExpressionToPythonType_StringAsUnicode_test( *args ): eq_( vimsupport.VimExpressionToPythonType( 'foo' ), 'foo' )
def VimExpressionToPythonType_IntAsBytes_test( *args ): eq_( vimsupport.VimExpressionToPythonType( ToBytes( '123' ) ), 123 )
def VimExpressionToPythonType_IntAsUnicode_test( *args ): eq_( vimsupport.VimExpressionToPythonType( '123' ), 123 )
def SyntaxKeywordsForCurrentBuffer(): vim.command( 'redir => b:ycm_syntax' ) vim.command( 'silent! syntax list' ) vim.command( 'redir END' ) syntax_output = vimsupport.VimExpressionToPythonType( 'b:ycm_syntax' ) return _KeywordsFromSyntaxListOutput( syntax_output )