[gnome-builder] plugin: jedi-language-server: Use IdeLspService



commit 8392c9f9ae53b63ec849ad6cdda495116d2ffb46
Author: James Westman <james jwestman net>
Date:   Tue Dec 14 19:39:39 2021 -0600

    plugin: jedi-language-server: Use IdeLspService

 src/libide/lsp/ide-lsp-service.c                   |  2 +-
 .../jedi_language_server_plugin.py                 | 89 +++-------------------
 2 files changed, 11 insertions(+), 80 deletions(-)
---
diff --git a/src/libide/lsp/ide-lsp-service.c b/src/libide/lsp/ide-lsp-service.c
index e06b4a5bc..211cdfd5a 100644
--- a/src/libide/lsp/ide-lsp-service.c
+++ b/src/libide/lsp/ide-lsp-service.c
@@ -31,7 +31,7 @@ typedef struct
   guint inherit_stderr : 1;
 } IdeLspServicePrivate;
 
-G_DEFINE_TYPE_WITH_PRIVATE (IdeLspService, ide_lsp_service, IDE_TYPE_OBJECT)
+G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (IdeLspService, ide_lsp_service, IDE_TYPE_OBJECT)
 
 enum {
   PROP_0,
diff --git a/src/plugins/jedi-language-server/jedi_language_server_plugin.py 
b/src/plugins/jedi-language-server/jedi_language_server_plugin.py
index 8c7b6c07f..e1f76a2e9 100644
--- a/src/plugins/jedi-language-server/jedi_language_server_plugin.py
+++ b/src/plugins/jedi-language-server/jedi_language_server_plugin.py
@@ -26,85 +26,16 @@ from gi.repository import Gio
 from gi.repository import GObject
 from gi.repository import Ide
 
-DEV_MODE = True
-
-class JediService(Ide.Object):
-    _client = None
-    _has_started = False
-    _supervisor = None
-
-    @classmethod
-    def from_context(klass, context):
-        return context.ensure_child_typed(JediService)
-
-    @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):
-        if self._supervisor:
-            supervisor, self._supervisor = self._supervisor, None
-            supervisor.stop()
-
-    def _ensure_started(self):
-        # To avoid starting the process unconditionally at startup, 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
-
-            launcher = self._create_launcher()
-            launcher.set_clear_env(False)
-
-            # Locate the directory of the project and run jedi-language-server from there
-            workdir = self.get_context().ref_workdir()
-            launcher.set_cwd(workdir.get_path())
-
-            launcher.push_argv("jedi-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._ls_spawned)
-            self._supervisor.set_launcher(launcher)
-            self._supervisor.start()
-
-    def _ls_spawned(self, supervisor, subprocess):
-        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('python')
-        self._client.add_language('python3')
-        self._client.start()
-        self.notify('client')
-
-    def _create_launcher(self):
-        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_run_on_host(True)
-        return launcher
-
-    @classmethod
-    def bind_client(klass, provider):
-        context = provider.get_context()
-        self = JediService.from_context(context)
-        self._ensure_started()
-        self.bind_property('client', provider, 'client', GObject.BindingFlags.SYNC_CREATE)
+class JediService(Ide.LspService):
+    def do_constructed(self):
+        self.set_inherit_stderr(True)
+
+    def do_configure_launcher(self, launcher):
+        launcher.push_argv("jedi-language-server")
+
+    def do_configure_client(self, client):
+        client.add_language('python')
+        client.add_language('python3')
 
 class JediDiagnosticProvider(Ide.LspDiagnosticProvider, Ide.DiagnosticProvider):
     def do_load(self):


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]