[gnome-builder] vls: port to IdeLspClient
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] vls: port to IdeLspClient
- Date: Wed, 22 Dec 2021 01:02:50 +0000 (UTC)
commit 594925c67a1d0a2fb0e6813368fe4375779aea2f
Author: Christian Hergert <chergert redhat com>
Date: Tue Dec 21 17:02:45 2021 -0800
vls: port to IdeLspClient
src/plugins/vls/vala_langserv.py | 140 +++------------------------------------
1 file changed, 10 insertions(+), 130 deletions(-)
---
diff --git a/src/plugins/vls/vala_langserv.py b/src/plugins/vls/vala_langserv.py
index 3b8c6578a..6a420bff1 100644
--- a/src/plugins/vls/vala_langserv.py
+++ b/src/plugins/vls/vala_langserv.py
@@ -33,136 +33,16 @@ from gi.repository import Gio
from gi.repository import GObject
from gi.repository import Ide
-DEV_MODE = False
-
-class VlsService(Ide.Object):
- _client = None
- _has_started = False
- _supervisor = None
- _monitor = None
-
- @classmethod
- def from_context(cls, context):
- return context.ensure_child_typed(VlsService)
-
- @GObject.Property(type=Ide.LspClient)
- def client(self):
- return self._client
-
- @client.setter
- def client(self, value):
- self._client = value
- self.notify('client')
-
- def do_stop(self):
- """
- Stops the Vala Language Server upon request to shutdown the
- VlsService.
- """
- if self._monitor is not None:
- monitor, self._monitor = self._monitor, None
- if monitor is not None:
- monitor.cancel()
-
- if self._supervisor is not None:
- supervisor, self._supervisor = self._supervisor, None
- supervisor.stop()
-
- def _ensure_started(self):
- """
- Start the service which provides communication with the Vala Language
- Server. We supervise our own instance of the language server and
- restart it as necessary using the Ide.SubprocessSupervisor.
-
- Various extension points (diagnostics, symbol providers, etc) use
- the VlsService to access the rust components they need.
- """
- # To avoid starting the `vls` process unconditionally at startup,
- # we lazily start it when the first provider tries to bind a client
- # to its :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)
- if DEV_MODE:
- launcher.setenv('G_MESSAGES_DEBUG', 'all', True)
-
- # Locate the directory of the project and run vls from there.
- workdir = self.get_context().ref_workdir()
- launcher.set_cwd(workdir.get_path())
-
- # Setup our Argv. We want to communicate over STDIN/STDOUT,
- # so it does not require any command line options.
- launcher.push_argv("vala-language-server")
-
- # Spawn our peer process and monitor it for
- # crashes. We may need to restart it occasionally.
- self._supervisor = Ide.SubprocessSupervisor()
- self._supervisor.connect('spawned', self._vls_spawned)
- self._supervisor.set_launcher(launcher)
- self._supervisor.start()
-
- def _vls_spawned(self, supervisor, subprocess):
- """
- This callback is executed when the `vala-language-server` process is
- spawned. We can use the stdin/stdout to create a channel for our
- LspClient.
- """
- stdin = subprocess.get_stdin_pipe()
- stdout = subprocess.get_stdout_pipe()
- io_stream = Gio.SimpleIOStream.new(stdout, stdin)
-
- if self._client:
- self._client.stop()
- self._client.destroy()
-
- self._client = Ide.LspClient.new(io_stream)
- self.append(self._client)
- self._client.add_language('vala')
- self._client.start()
- self.notify('client')
-
- def _create_launcher(self):
- """
- Creates a launcher to be used by the rust service. This needs
- to be run on the host because we do not currently bundle rust
- inside our flatpak.
-
- In the future, we might be able to rely on the runtime for
- the tooling. Maybe even the program if flatpak-builder has
- prebuilt our dependencies.
- """
- flags = Gio.SubprocessFlags.STDIN_PIPE | Gio.SubprocessFlags.STDOUT_PIPE
- if not DEV_MODE:
- flags |= Gio.SubprocessFlags.STDERR_SILENCE
- launcher = Ide.SubprocessLauncher()
- launcher.set_flags(flags)
- launcher.set_cwd(GLib.get_home_dir())
- launcher.set_run_on_host(True)
- return launcher
-
- @classmethod
- def bind_client(cls, provider):
- """
- This helper tracks changes to our client as it might happen when
- our `vls` process has crashed.
- """
- context = provider.get_context()
- self = VlsService.from_context(context)
- self._ensure_started()
- self.bind_property('client', provider, 'client', GObject.BindingFlags.SYNC_CREATE)
-
- @classmethod
- def bind_client_lazy(cls, provider):
- """
- This helper will bind the client to the provider, but only after the
- client has started.
- """
- context = provider.get_context()
- self = VlsService.from_context(context)
- self.bind_property('client', provider, 'client', GObject.BindingFlags.SYNC_CREATE)
+DEV_MODE = os.getenv('DEV_MODE') and True or False
+
+class VlsService(Ide.LspService):
+ def __init__(self, *args, **kwargs):
+ super().__init__(self, *args, **kwargs)
+ self.set_program('vala-language-server')
+ self.set_inherit_stderr(DEV_MODE)
+
+ def do_configure_client(self, client):
+ client.add_language('vala')
class VlsDiagnosticProvider(Ide.LspDiagnosticProvider):
def do_load(self):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]