Skip to content

Commit

Permalink
add restart
Browse files Browse the repository at this point in the history
  • Loading branch information
hy172574895 committed Aug 1, 2020
1 parent 504f875 commit 7bff632
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 11 deletions.
2 changes: 2 additions & 0 deletions autoload/ECY_main.vim
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,8 @@ function! s:EventSort(id, data, event) abort
call timer_start(1, function('ECY#install#ListEngine_cb', [l:data_dict]))
elseif l:Event == 'CachedBufferList'
call s:CachedBufferList_cb(l:data_dict)
elseif l:Event == 'restart'
call ECY#utility#ShowMsg("[ECY] restared :" . l:data_dict['EngineName'], 2)
endif
endfor
" catch
Expand Down
1 change: 1 addition & 0 deletions plugin/easycompleteyou.vim
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ command! -bar -nargs=0 ECYWorkSpaceSymbols call ECY_main#Execute('get_workspace_
command! -bar -nargs=0 ECYDocumentSymbols call ECY_main#Execute('get_symbols')
command! -bar -nargs=0 ECYToggleDiagnosis call ECY#diagnosis#Toggle()
command! -bar -nargs=0 ECYDiagnosisLists call ECY#diagnosis#ShowSelecting()
command! -bar -nargs=0 ECYRestartServer call ECY_main#Do("Restart", v:true)
command! -bar -nargs=0 ECYAutoInstall call ECY#auto_installer#AutoInstall()
command! -bar -nargs=0 ECYListEngine call ECY_main#Do("GetAllEngineInfo", v:true)
command! -bar -nargs=0 ECYDocHelp call ECY_main#Do("OnDocumentHelp", v:true)
Expand Down
3 changes: 3 additions & 0 deletions python/client/ECY/utils/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ def InstallSource(self):
msg['EngineName'] = temp['EngineName']
return self._pack(msg, 'InstallSource')

def Restart(self):
return self._pack({}, 'Restart')

def DoCompletion(self):
return self._pack({}, 'DoCompletion')

Expand Down
35 changes: 28 additions & 7 deletions python/server/lib/completor_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ def _load_config(self):
installed_engine_path = self.conf['installed_engine_path']
return installed_engine_lib, installed_engine_path

def NewObj(self, module_name):
module_temp = importlib.import_module(module_name)
obj_temp = module_temp.Operate()
module_info = obj_temp.GetInfo() # return a dict
module_info['Object'] = obj_temp
name = module_info['Name']
self.sources_info[name] = module_info
return module_info

def _load_engine(self, specify_lib=None, specify_path={}):
""" load the installed source list when specify_lib is None
e.g.
Expand All @@ -92,26 +101,38 @@ def _load_engine(self, specify_lib=None, specify_path={}):
# e.g.
# name = 'label'
# lib = 'lib.sources.label.Label'
if name in self.sources_info:
# already inited, so we pass this
continue
try:
if name in loading_source_path and \
loading_source_path[name] != '':
temp = loading_source_path[name]
sys.path.append(temp)
g_logger.debug('appended a new path:' + temp)
module_temp = importlib.import_module(lib)
obj_temp = module_temp.Operate()
module_temp = obj_temp.GetInfo() # return a dict
module_temp['Object'] = obj_temp
name = module_temp['Name']
self.sources_info[name] = module_temp
g_logger.debug('installed: ' + name + " from " + lib)
module_temp = self.NewObj(lib)
g_logger.debug('Installed: "%s" from "%s" ' % (module_temp['Name'],lib))
except:
# return erro
g_logger.exception("failed to load engine.")
return module_temp
except:
raise "Failed to load engine."

def ReLoadEngine(self, engine_name):
del self.sources_info[engine_name]
try:
self._load_engine()
return {'Event': 'restart',
'Status': 0,
'EngineName': engine_name,
'Description': 'ok'}
except:
return {'Event': 'restart',
'Status': 1,
'EngineName': engine_name,
'Description': 'Failed to reload. Check log file for more.'}

def InstallSource(self, engine_name, engine_lib, package_path=''):
"""this method will not check if engine is runable.
the engine's depence must be checked in the vim side.
Expand Down
9 changes: 7 additions & 2 deletions python/server/lib/request_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def HandleIt(self, version_dict):
version_dict = version_dict['Msg']
event_ = version_dict['Event']
file_type = version_dict['FileType']
source_name = version_dict['SourceName']
engine_name = version_dict['SourceName']
self._is_debug = version_dict['IsDebugging']

results_ = []
Expand All @@ -49,12 +49,17 @@ def HandleIt(self, version_dict):
results_.append(temp)
return results_

if event_ == 'Restart':
temp = self.source_manager.ReLoadEngine(engine_name)
results_.append(temp)
return results_

# we passing that queue to let source handle asyn by itself.
# if the source's event will block for a while, the source can return
# None, and then put the result into deamon_queue when it finished
version_dict['DeamonQueue'] = self._pass_results_queue
engine_obj = self.source_manager.GetSourceObjByName(
source_name, file_type)
engine_name, file_type)

lists = self.BufferHanlder(version_dict)
if lists is None:
Expand Down
2 changes: 1 addition & 1 deletion python/server/lib/sources/lsp_servers/clangd.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def GetInfo(self):
'WhiteList': ['c', 'cpp', 'objc', 'objcpp', 'cuda'],
'Regex': r'[A-Za-z0-9\_]',
'NotCache': self._is_incomplete_items,
'TriggerKey': [".","<",":","#"]}
'TriggerKey': [".","<",":","#",">"]}

def _check(self, version):
self._deamon_queue = version['DeamonQueue']
Expand Down
1 change: 0 additions & 1 deletion python/server/lib/sources/python/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ def _get_auto_env(self):
self._using_jedi_env['auto'] = \
jedi.api.environment.get_cached_default_environment()
return self._using_jedi_env['auto']


def _get_environment(self, force_to_use):
if force_to_use == 'auto':
Expand Down

0 comments on commit 7bff632

Please sign in to comment.