[gnome-builder/1151-vala-pass-dependencies-to-lsp: 7/7] GVls: implement runtime configuration notification



commit cb8455995744ea2f3e56cf870b39cbde71fc56ba
Author: Daniel Espinosa Ortiz <esodan gmail com>
Date:   Thu Mar 5 09:31:31 2020 -0600

    GVls: implement runtime configuration notification
    
    Plugin now takes current runtime to know vala API
    version and use 'pkg-config' to find libvala's VAPI
    directory and generic VAPI at ${datadir}/vala/vapi,
    both are provided to the server to find packages
    in use for current runtime
    
    Plugin now report the Vala API version in use

 src/plugins/gvls/gvls_plugin.py | 120 +++++++++++++++++++++++++++++++++++++++-
 1 file changed, 118 insertions(+), 2 deletions(-)
---
diff --git a/src/plugins/gvls/gvls_plugin.py b/src/plugins/gvls/gvls_plugin.py
index df8f47030..ec1ffc4c5 100644
--- a/src/plugins/gvls/gvls_plugin.py
+++ b/src/plugins/gvls/gvls_plugin.py
@@ -1,3 +1,4 @@
+
 #!/usr/bin/env python
 
 # gvls_plugin.py
@@ -35,7 +36,6 @@ from gi.repository import Ide
 from gi.repository import Gdk
 from gi.repository import Gtk
 from gi.repository import GtkSource
-from gi.repository import Json
 
 DEV_MODE = True
 
@@ -50,10 +50,13 @@ class GVlsService(Ide.Object):
     default_vapi_dirs = True
     scan_work_space = True
     add_using_namespaces = True
+    library_vapidir = ""
+    system_vapidir = ""
     files = []
     packages = []
     vala_args = {}
     options = []
+    vala_api_version = ""
     build_system = None
     pipeline = None
     build_args = None
@@ -166,6 +169,11 @@ class GVlsService(Ide.Object):
         vv = GLib.Variant.new_variant(GLib.Variant.new_boolean(val))
         return GLib.Variant.new_dict_entry(vk, vv)
 
+    def create_dict_entry_string(self, key, val):
+        vk = GLib.Variant.new_string (key)
+        vv = GLib.Variant.new_variant(GLib.Variant.new_string(val))
+        return GLib.Variant.new_dict_entry(vk, vv)
+
     def create_configuration_variant(self):
         try:
             b = GLib.VariantBuilder(GLib.VariantType.new('a{sv}'))
@@ -175,6 +183,9 @@ class GVlsService(Ide.Object):
             b.add_value(self.create_dict_entry_boolean('scanWorkspace', self.scan_work_space))
             b.add_value(self.create_dict_entry_boolean('addUsingNamespaces', self.add_using_namespaces))
             b.add_value(self.create_dict_entry_boolean('mesonBuildSystem', self.meson_build_system))
+            b.add_value(self.create_dict_entry_string('libraryVapi', self.library_vapidir))
+            b.add_value(self.create_dict_entry_string('systemVapi', self.system_vapidir))
+            b.add_value(self.create_dict_entry_string('valaApiVersion', self.vala_api_version))
             ad = GLib.Variant.new_string ('valaArgs')
             vadi = self.dict_to_array_variant(self.vala_args)
             adi = GLib.Variant.new_dict_entry(ad, GLib.Variant.new_variant (vadi))
@@ -389,7 +400,109 @@ class GVlsService(Ide.Object):
             print('\n\nOn Pipeline Loaded start get build flags error:\n')
             print(exc.args)
             print('\n\n\n')
-                     
+
+    def on_get_vala_data_dir(self, vdp, cancellable, data):
+        try:
+            if (self.pipeline == None):
+                return
+            rt = self.pipeline.get_runtime()
+            if (rt == None):
+                return
+            vdpio = vdp.get_stdout_pipe()
+            ddpp = Gio.DataInputStream.new(vdpio)
+            ldp = ddpp.read_line()
+            fgdvapi = Gio.File.new_for_path(str(ldp[0],encoding='utf8'))
+            rtfgdvapi = rt.translate_file(fgdvapi)
+            self.system_vapidir = rtfgdvapi.get_uri() + "/vala/vapi"
+        except BaseException as exc:
+            print('\n\nOn get Vala DATA VAPI DIR:\n')
+            print(str(exc))
+            print('\n\n\n')
+    
+    def on_get_vapidir(self, vpkgp, cancellable, data):
+        try:
+            if (self.pipeline == None):
+                return
+            rt = self.pipeline.get_runtime()
+            if (rt == None):
+                return
+            vpstdio = vpkgp.get_stdout_pipe()
+            dpp = Gio.DataInputStream.new(vpstdio)
+            lp = dpp.read_line()
+            flvapi = Gio.File.new_for_path(str(lp[0],encoding='utf8'))
+            rtfvapi = rt.translate_file(flvapi)
+            self.library_vapidir = rtfvapi.get_uri()
+            flags = Gio.SubprocessFlags.STDOUT_PIPE
+            launcher = rt.create_launcher()
+            if (launcher == None):
+                return
+            launcher.set_cwd(GLib.get_home_dir())
+            launcher.set_flags(flags)
+            launcher.set_argv (['pkg-config','--variable','datadir','libvala-'+self.vala_api_version])
+            vdp = launcher.spawn(None)
+            vdp.wait_async(None, self.on_get_vala_data_dir, None)
+        except BaseException as exc:
+            print('\n\nOn get Vala VAPI DIR:\n')
+            print(str(exc))
+            print('\n\n\n')
+    
+    def on_get_vala_api_version(self, valacp, cancellable, data):
+        try:
+            vstdio = valacp.get_stdout_pipe()
+            dp = Gio.DataInputStream.new(vstdio)
+            l = dp.read_line()
+            self.vala_api_version = str(l[0],encoding='utf8')
+            if (self.pipeline == None):
+                return
+            rt = self.pipeline.get_runtime()
+            if (rt == None):
+                return
+            flags = Gio.SubprocessFlags.STDOUT_PIPE
+            launcher = rt.create_launcher()
+            if (launcher == None):
+                return
+            launcher.set_cwd(GLib.get_home_dir())
+            launcher.set_flags(flags)
+            launcher.set_argv (['pkg-config','--variable','vapidir','libvala-'+self.vala_api_version])
+            vpkgp = launcher.spawn(None)
+            vpkgp.wait_async(None, self.on_get_vapidir, None)
+        except BaseException as exc:
+            print('\n\nOn get Vala API VERSION Runtime Configuration:\n')
+            print(str(exc))
+            print('\n\n\n')
+    
+    def _update_config_from_runtime(self):
+        try:
+            if (self.pipeline == None):
+                return
+            rt = self.pipeline.get_runtime()
+            if (rt == None):
+                return
+            flags = Gio.SubprocessFlags.STDOUT_PIPE
+            launcher = rt.create_launcher()
+            if (launcher == None):
+                return
+            launcher.set_cwd(GLib.get_home_dir())
+            launcher.set_flags(flags)
+            launcher.set_argv (['valac','--api-version'])
+            valacp = launcher.spawn(None)
+            valacp.wait_async(None, self.on_get_vala_api_version, None)
+        except BaseException as exc:
+            print('\n\nOn Update Runtime Configuration:\n')
+            print(str(exc))
+            print('\n\n\n')
+    
+    def on_config_changed_cb(self, data):
+        try:
+            ctx = self._client.ref_context()
+            buildmgr = Ide.BuildManager.from_context (ctx)
+            self.pipeline = buildmgr.get_pipeline ()
+            self.pipeline.connect('diagnostic', self._on_pipeline_diagnostic)
+        except BaseException as exc:
+            print('\n\nOn Config Changed CB:\n')
+            print(str(exc))
+            print('\n\n\n')
+
     def _gvls_spawned(self, supervisor, subprocess):
         """
         This callback is executed when the `org.gnome.gvls.stdio.Server` process is spawned.
@@ -420,6 +533,9 @@ class GVlsService(Ide.Object):
             buildmgr = Ide.BuildManager.from_context (ctx)
             self.pipeline = buildmgr.get_pipeline ()
             self.pipeline.connect('diagnostic', self._on_pipeline_diagnostic)
+            cfgmgr = Ide.ConfigManager.from_context(ctx)
+            cfgmgr.connect('notify::current', self.on_config_changed_cb)
+            self._update_config_from_runtime()
         except BaseException as exc:
             print('\n\n\n Exception Arguments: \n')
             print(exc.args)


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