Commit eebbc229 authored by Christian Hergert's avatar Christian Hergert
Browse files

rust-langserv: restart rls when Cargo.toml changes

Fixes #685
parent 4e3f1fec
......@@ -39,6 +39,7 @@ class RustService(Ide.Object, Ide.Service):
_client = None
_has_started = False
_supervisor = None
_monitor = None
def client(self):
......@@ -49,12 +50,45 @@ class RustService(Ide.Object, Ide.Service):
self._client = value
def do_context_loaded(self):
After the context has been loaded, we want to watch the project
Cargo.toml for changes if we find one. That will allow us to
restart the process as necessary to pick up changes.
context = self.get_context()
project_file = context.get_project_file()
if project_file is not None:
if project_file.get_basename() == 'Cargo.toml':
self._monitor = project_file.monitor(0, None)
self._monitor.set_rate_limit(5 * 1000) # 5 Seconds
self._monitor.connect('changed', self._monitor_changed_cb)
except Exception as ex:
Ide.debug('Failed to monitor Cargo.toml for changes:', repr(ex))
def _monitor_changed_cb(self, monitor, file, other_file, event_type):
This method is called when Cargo.toml has changed. We need to
cancel any supervised process and force the language server to
restart. Otherwise, we risk it not picking up necessary changes.
if self._supervisor is not None:
subprocess = self._supervisor.get_subprocess()
if subprocess is not None:
def do_stop(self):
Stops the Rust Language Server upon request to shutdown the
if self._supervisor:
if self._monitor is not None:
monitor, self._monitor = self._monitor, None
if monitor is not None:
if self._supervisor is not None:
supervisor, self._supervisor = self._supervisor, None
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment