[gnome-builder] rust-langserv: make rust service startup lazy
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] rust-langserv: make rust service startup lazy
- Date: Sat, 29 Oct 2016 22:00:19 +0000 (UTC)
commit ba8795f2cb5b9f66c13dcbdeb1eb2fe846b802cd
Author: Christian Hergert <chergert redhat com>
Date: Sat Oct 29 14:59:57 2016 -0700
rust-langserv: make rust service startup lazy
This ensures that we don't spawn our rls process until a provider has
requested that we bind the client property.
plugins/rust-langserv/rust_langserv_plugin.py | 52 ++++++++++++++----------
1 files changed, 30 insertions(+), 22 deletions(-)
---
diff --git a/plugins/rust-langserv/rust_langserv_plugin.py b/plugins/rust-langserv/rust_langserv_plugin.py
index 3086d79..6144332 100644
--- a/plugins/rust-langserv/rust_langserv_plugin.py
+++ b/plugins/rust-langserv/rust_langserv_plugin.py
@@ -37,6 +37,7 @@ from gi.repository import Ide
class RustService(Ide.Object, Ide.Service):
_client = None
+ _has_started = False
@GObject.Property(type=Ide.LangservClient)
def client(self):
@@ -47,7 +48,7 @@ class RustService(Ide.Object, Ide.Service):
self._client = value
self.notify('client')
- def do_start(self):
+ def _ensure_started(self):
"""
Start the rust service which provides communication with the
Rust Language Server. We supervise our own instance of the
@@ -57,27 +58,33 @@ class RustService(Ide.Object, Ide.Service):
Various extension points (diagnostics, symbol providers, etc) use
the RustService to access the rust components they need.
"""
- # Setup a launcher to spawn the rust language server
- launcher = self._create_launcher()
- launcher.set_clear_env(False)
- launcher.setenv("SYS_ROOT", self._discover_sysroot(), True)
-
- # If rls was installed with Cargo, try to discover that
- # to save the user having to update PATH.
- path_to_rls = os.path.expanduser("~/.cargo/bin/rls")
- if not os.path.exists(path_to_rls):
- path_to_rls = "rls"
-
- # Setup our Argv. We want to communicate over STDIN/STDOUT,
- # so it does not require any command line options.
- launcher.push_argv(path_to_rls)
-
- # Spawn our peer process and monitor it for
- # crashes. We may need to restart it occasionally.
- supervisor = Ide.SubprocessSupervisor()
- supervisor.connect('spawned', self._rls_spawned)
- supervisor.set_launcher(launcher)
- supervisor.start()
+ # To avoid starting the `rls` process unconditionally at startup,
+ # we lazily start it when the first provider tries to bind a client
+ # to it's :client property.
+ if not self._has_started:
+ self._has_started = True
+
+ # Setup a launcher to spawn the rust language server
+ launcher = self._create_launcher()
+ launcher.set_clear_env(False)
+ launcher.setenv("SYS_ROOT", self._discover_sysroot(), True)
+
+ # If rls was installed with Cargo, try to discover that
+ # to save the user having to update PATH.
+ path_to_rls = os.path.expanduser("~/.cargo/bin/rls")
+ if not os.path.exists(path_to_rls):
+ path_to_rls = "rls"
+
+ # Setup our Argv. We want to communicate over STDIN/STDOUT,
+ # so it does not require any command line options.
+ launcher.push_argv(path_to_rls)
+
+ # Spawn our peer process and monitor it for
+ # crashes. We may need to restart it occasionally.
+ supervisor = Ide.SubprocessSupervisor()
+ supervisor.connect('spawned', self._rls_spawned)
+ supervisor.set_launcher(launcher)
+ supervisor.start()
def _rls_spawned(self, supervisor, subprocess):
"""
@@ -136,6 +143,7 @@ class RustService(Ide.Object, Ide.Service):
"""
context = provider.get_context()
self = context.get_service_typed(RustService)
+ self._ensure_started()
self.bind_property('client', provider, 'client', GObject.BindingFlags.SYNC_CREATE)
class RustDiagnosticProvider(Ide.LangservDiagnosticProvider):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]