def _parse_differ_commands(self): infos = vim_lib.GetVariableValue('g:ECY_buffer_need_to_update') buffer_info = vim_lib.GetVariableValue( 'g:ECY_cached_buffer_nr_to_path') vim_lib.Command('let g:ECY_buffer_need_to_update = {}') commands = {} g_logger.debug(infos) for buffer_nr in infos: info = infos[buffer_nr] buffer_path = buffer_info[buffer_nr] commands[buffer_path] = [] # last_command = None for item in info: kind = item[0] start_line = int(item[1]) end_line = int(item[2]) # if last_command == item: # continue # last_command = item deleted_line = 0 for line in range(start_line, end_line + 1): temp = {'kind': kind, 'line': line} if kind != 'delete': try: evals = 'getbufline({0}, {1})'.format( buffer_nr, line + 1) temp['newtext'] = vim_lib.CallEval(evals)[0] except: continue else: temp['line'] -= deleted_line deleted_line += 1 commands[buffer_path].append(temp) g_logger.debug(commands) return commands
def OnBufferEnter(self): msg = {} msg['DictFileName'] = self._get_dictionary_file_name() msg['Frequency'] = vim_lib.GetVariableValue( 'g:dictionary_frequency_of_filtering_words') msg['UseChinese'] = vim_lib.GetVariableValue( 'g:dictionary_show_chinese_in_preview_windows') msg['AdditionalPath'] = vim_lib.GetVariableValue( 'g:dictionary_additional_dict_path') return self._pack(msg, 'OnBufferEnter')
def _generate(self, msg, event_name): msg['Event'] = event_name if event_name == 'DoCompletion': msg['TriggerLength'] = self._trigger_len msg['ReturnMatchPoint'] = self._is_return_match_point if event_name == 'Goto': msg['GotoLists'] = vim_lib.GetVariableValue('g:ECY_goto_info') if event_name == 'OnBufferEnter': # update WorkSpace self._workspace = self.GetCurrentWorkSpace() if event_name == 'Integration': msg['Integration_event'] = vim_lib.GetVariableValue( 'g:ECY_do_something_event') return self._basic(msg)
def _return_buffer(self, msg, file_path): """ return current buffer difference text. """ msg['IsFullList'] = False msg['IsDebugging'] = self._is_debugging msg['UsingTextDiffer'] = self._use_textdiffer if self._use_textdiffer: cached_buffer = vim_lib.GetVariableValue( 'g:ECY_server_cached_buffer') else: cached_buffer = [] if self._is_debugging and self._use_textdiffer: current_buffer = vim_lib.CallEval('getbufline(bufnr(), 1, "$")') msg['AllTextList'] = current_buffer # TODO, there are bug in vim, check # https://github.com/vim/vim/issues/5840 if self._use_textdiffer and file_path in cached_buffer: msg['Commands'] = self._parse_differ_commands() else: current_buffer = vim_lib.CallEval('getbufline(bufnr(), 1, "$")') msg['IsFullList'] = True msg['AllTextList'] = current_buffer return msg
def __init__(self, source_name): self._workspace = None self.source_name = source_name self._is_return_match_point = vim_lib.GetVariableValue( "g:ECY_use_floating_windows_to_be_popup_windows") self._trigger_len = vim_lib.GetVariableValue("g:ECY_triggering_length") self._is_debugging = vim_lib.GetVariableValue("g:ECY_debug") self._use_textdiffer = vim_lib.CallEval( 'ECY_main#UsingTextDifferEvent()') self._snippets_cache = None self._lsp_setting = None self.preview_file_dir = None self.preview_file_list = [] self.preview_content = {} # self._get_difference = MyDiffer() self.buffer_cache = {}
def InstallSource(self): """ user should not rewrite this method """ msg = {} temp = vim_lib.GetVariableValue('g:ecy_source_name_2_install') msg['EngineLib'] = temp['EngineLib'] msg['EnginePath'] = temp['EnginePath'] msg['EngineName'] = temp['EngineName'] return self._pack(msg, 'InstallSource')
def _get_snippets(self, is_reflesh=False): results = {'HasSnippetSupport': True} try: if is_reflesh or self._snippets_cache is None: vim_lib.CallEval('UltiSnips#SnippetsInCurrentScope(1)') self._snippets_cache =\ vim_lib.GetVariableValue('g:current_ulti_dict_info') preview = self._get_preview_content() for key in self._snippets_cache: if key in preview.keys(): self._snippets_cache[key]['preview'] = preview[key][ 'preview'] else: self._snippets_cache[key]['preview'] = [] results['UltisnipsSnippets'] = self._snippets_cache except: results = {'HasSnippetSupport': False} g_logger.debug("Failed to load snippets.") return results
def Log(self): g_logger.debug("From Vim: " + vim_lib.GetVariableValue('g:ECY_log_msg')) return 'ok'
def UpdateClientModule(self): self.available_engine_name_dict = vim_lib.GetVariableValue( 'g:ECY_engine_client_info')
import random import threading import logging import sys import os import importlib from socket import * # noqa # local lib BASE_DIR = os.path.dirname(os.path.abspath(__file__)) sys.path.append(BASE_DIR) from ECY.utils import socket_ from ECY.utils import vim_or_neovim_support as vim_lib import lib.event.genernal as genernal g_is_debug = vim_lib.GetVariableValue('g:ECY_debug') if g_is_debug: fileHandler = logging.FileHandler(BASE_DIR + "/ECY_client.log", mode="w", encoding="UTF-8") formatter = logging.Formatter( '%(asctime)s %(filename)s:%(lineno)d | %(message)s') fileHandler.setFormatter(formatter) global g_logger g_logger = logging.getLogger('ECY_client') if g_is_debug: g_logger.addHandler(fileHandler) g_logger.setLevel(logging.DEBUG) class _do(object):
def _get_dictionary_file_name(self): if self._dictionary_file_name is None: self._dictionary_file_name = vim_lib.GetVariableValue( 'g:dictionary_csv_file_path') return self._dictionary_file_name
def _get_runtimepath(self): if self._runtimepath is None: self._runtimepath = vim_lib.GetVariableValue("&runtimepath") return self._runtimepath
def _get_vimruntime(self): if self._vimruntime is None: self._vimruntime = vim_lib.GetVariableValue("$VIMRUNTIME") return self._vimruntime
def _is_return_diagnosis(self): return vim_lib.GetVariableValue("g:ECY_enable_diagnosis")