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



commit fc38f108620800d5836516b3a6edea97292beec6
Author: James Westman <james jwestman net>
Date:   Fri Dec 10 14:27:40 2021 -0600

    plugin: ts-language-server: Use IdeLspService

 .../ts_language_server_plugin.py                   | 93 +++-------------------
 1 file changed, 13 insertions(+), 80 deletions(-)
---
diff --git a/src/plugins/ts-language-server/ts_language_server_plugin.py 
b/src/plugins/ts-language-server/ts_language_server_plugin.py
index 86c7883d8..d3835fff2 100644
--- a/src/plugins/ts-language-server/ts_language_server_plugin.py
+++ b/src/plugins/ts-language-server/ts_language_server_plugin.py
@@ -26,86 +26,19 @@ from gi.repository import Gio
 from gi.repository import GObject
 from gi.repository import Ide
 
-DEV_MODE = True
-
-class TypescriptService(Ide.Object):
-    _client = None
-    _has_started = False
-    _supervisor = None
-
-    @classmethod
-    def from_context(klass, context):
-        return context.ensure_child_typed(TypescriptService)
-
-    @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 typescript-language-server from there
-            workdir = self.get_context().ref_workdir()
-            launcher.set_cwd(workdir.get_path())
-
-            # this needs https://github.com/typescript-language-server/typescript-language-server installed 
on the host
-            launcher.push_argv("typescript-language-server")
-            launcher.push_argv("--stdio")
-
-            # 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('javascript')
-        self._client.add_language('typescript')
-        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)
-        return launcher
-
-    @classmethod
-    def bind_client(klass, provider):
-        context = provider.get_context()
-        self = TypescriptService.from_context(context)
-        self._ensure_started()
-        self.bind_property('client', provider, 'client', GObject.BindingFlags.SYNC_CREATE)
+
+class TypescriptService(Ide.LspService):
+    def do_constructed(self):
+        self.set_inherit_stderr(True)
+
+    def do_configure_launcher(self, launcher):
+        # this needs https://github.com/typescript-language-server/typescript-language-server installed on 
the host
+        launcher.set_argv(["typescript-language-server", "--stdio"])
+
+    def do_configure_client(self, client):
+        client.add_language('javascript')
+        client.add_language('typescript')
+
 
 class TypescriptDiagnosticProvider(Ide.LspDiagnosticProvider, Ide.DiagnosticProvider):
     def do_load(self):


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