Skip to content
This repository was archived by the owner on Sep 21, 2019. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions autoload/ensime.vim
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ function! ensime#teardown() abort
return s:call_plugin('teardown', [])
endfunction

function! ensime#restart() abort
return s:call_plugin('restart', [])
endfunction

function! ensime#current_client(create, quiet, allow_classpath_file_creation) abort
return s:call_plugin('current_client', [a:create, a:quiet, a:allow_classpath_file_creation])
endfunction
Expand Down
24 changes: 20 additions & 4 deletions ensime_shared/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,21 @@ def fetch_runtime_paths():
self.number_try_connection = 1

self.debug_thread_id = None
self.running = True

thread = Thread(name='queue-poller', target=self.queue_poll)
thread.daemon = True
thread.start()
self.start_polling()

self.websocket_exists = module_exists("websocket")
if not self.websocket_exists:
self.tell_module_missing("websocket-client")
if not module_exists("sexpdata"):
self.tell_module_missing("sexpdata")

def start_polling(self):
self.running = True
thread = Thread(name='queue-poller', target=self.queue_poll)
thread.daemon = True
thread.start()

def queue_poll(self, sleep_t=0.5):
"""Put new messages on the queue as they arrive. Blocking in a thread.

Expand All @@ -158,9 +161,11 @@ def queue_poll(self, sleep_t=0.5):
connection_alive = True

while self.running:
self.log.debug('Polling...')
if self.ws:
def logger_and_close(msg):
self.log.error('Websocket exception', exc_info=True)
self.log.debug(self.running)
if not self.running:
# Tear down has been invoked
# Prepare to exit the program
Expand Down Expand Up @@ -291,7 +296,11 @@ def shutdown_server(self):
"""Shut down server if it is alive."""
self.log.debug('shutdown_server: in')
if self.ensime and self.toggle_teardown:
self.log.debug('Stopping server process...')
self.ws.shutdown()
self.ws = None
self.ensime.stop()
self.ensime = None

def teardown(self):
"""Tear down the server or keep it alive."""
Expand All @@ -300,6 +309,13 @@ def teardown(self):
self.shutdown_server()
shutil.rmtree(self.tmp_diff_folder, ignore_errors=True)

def restart_server(self):
"""Restart server process"""
self.log.debug('restart_server: in')
self.teardown()
self.start_polling()
# self.setup()

def send_at_position(self, what, where="range"):
self.log.debug('send_at_position: in')
b, e = self.editor.start_end_pos()
Expand Down
5 changes: 5 additions & 0 deletions ensime_shared/ensime.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ def teardown(self):
for c in self.clients.values():
c.teardown()

def restart(self):
"""Restarting servers..."""
for c in self.clients.values():
c.restart_server()

def current_client(self, quiet, bootstrap_server, create_client):
"""Return the client for current file in the editor."""
current_file = self._vim.current.buffer.name
Expand Down
1 change: 1 addition & 0 deletions plugin/ensime.vim
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ augroup ensime
autocmd CursorMoved *.scala call ensime#au_cursor_moved(expand("<afile>"))
augroup END

command! -nargs=* -range EnRestart call ensime#restart([<f-args>], '')
command! -nargs=* -range EnInstall call ensime#com_en_install([<f-args>], '')
command! -nargs=* -range EnNoTeardown call ensime#com_en_no_teardown([<f-args>], '')
command! -nargs=* -range EnTypeCheck call ensime#com_en_type_check([<f-args>], '')
Expand Down
4 changes: 4 additions & 0 deletions rplugin/python/ensime.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ def com_en_debug_clear_breaks(self, *args, **kwargs):
def com_en_debug_start(self, *args, **kwargs):
super(NeovimEnsime, self).com_en_debug_start(*args, **kwargs)

@neovim.command('EnRestart', **command_params)
def com_en_restart(self, *args, **kwargs):
super(NeovimEnsime, self).restart()

@neovim.command('EnInstall', **command_params)
def com_en_install(self, *args, **kwargs):
super(NeovimEnsime, self).com_en_install(*args, **kwargs)
Expand Down