[gnome-builder/1089-lsp-client-capabilites-notify-workspace-configuration-support: 3/3] GVls: improved server initialization



commit f1b853ac389c88b6690de02770d7668906e07527
Author: Daniel Espinosa Ortiz <esodan gmail com>
Date:   Wed Feb 12 17:57:48 2020 -0600

    GVls: improved server initialization
    
    Fix issue #1089

 src/plugins/gvls/gvls_plugin.py | 220 ++++++++++++++++++++++++++++++++++++++--
 1 file changed, 209 insertions(+), 11 deletions(-)
---
diff --git a/src/plugins/gvls/gvls_plugin.py b/src/plugins/gvls/gvls_plugin.py
index 8c322b76d..c6a25b881 100644
--- a/src/plugins/gvls/gvls_plugin.py
+++ b/src/plugins/gvls/gvls_plugin.py
@@ -26,6 +26,7 @@ by bridging them to our supervised Vala Language Server.
 
 import gi
 import os
+import sys
 
 from gi.repository import GLib
 from gi.repository import Gio
@@ -42,6 +43,17 @@ class GVlsService(Ide.Object):
     _has_started = False
     _supervisor = None
     _monitor = None
+    meson_build_system = True
+    initialized = True
+    default_namespaces = True
+    default_vapi_dirs = True
+    scan_work_space = True
+    add_using_namespaces = True
+    files = []
+    packages = []
+    vala_args = {}
+    options = []
+    build_system = None
 
     @classmethod
     def from_context(klass, context):
@@ -118,17 +130,186 @@ class GVlsService(Ide.Object):
             self._supervisor.set_launcher(launcher)
             self._supervisor.start()
 
-    def _on_load_configuration(self, client):
-        return GLib.Variant('a{sv}', {
-            'initialized': GLib.Variant.new_boolean(True),
-            'defaultNamespaces': GLib.Variant.new_boolean(True),
-            'defaultVapiDirs': GLib.Variant.new_boolean(True),
-            'scanWorkspace': GLib.Variant.new_boolean(True),
-            'addUsingNamespaces': GLib.Variant.new_boolean(True),
-            'packages': GLib.Variant.new_strv([]),
-            'options': GLib.Variant.new_strv([]),
-        })
-
+    def list_to_variant(self, l):
+        b = GLib.VariantBuilder(GLib.VariantType.new('av'))
+        for s in l:
+            v = GLib.Variant.new_string (s)
+            b.add_value(GLib.Variant.new_variant(v))
+        return b.end()
+
+    def dict_to_array_variant(self, d):
+        b = GLib.VariantBuilder(GLib.VariantType.new('av'))
+        for k in d.keys():
+            a = d[k]
+            b2 = GLib.VariantBuilder(GLib.VariantType.new('a{sv}'))
+            ndi = GLib.Variant.new_string ('name')
+            vndi = GLib.Variant.new_variant(GLib.Variant.new_string(k))
+            di = GLib.Variant.new_dict_entry(ndi, vndi)
+            vdi = GLib.Variant.new_variant(di)
+            b2.add_value(di)
+            vdi = GLib.Variant.new_string ('value')
+            vvdi = GLib.Variant.new_variant(GLib.Variant.new_string(a))
+            div = GLib.Variant.new_dict_entry(vdi, vvdi)
+            vdi = GLib.Variant.new_variant(div)
+            b2.add_value(div)
+            b.add_value(GLib.Variant.new_variant(b2.end()))
+        return b.end()
+    
+    def create_dict_entry_boolean(self, key, val):
+        vk = GLib.Variant.new_string (key)
+        vv = GLib.Variant.new_variant(GLib.Variant.new_boolean(val))
+        return GLib.Variant.new_dict_entry(vk, vv)
+
+    def _on_load_configuration(self, data):
+        try:
+            b = GLib.VariantBuilder(GLib.VariantType.new('a{sv}'))
+            b.add_value(self.create_dict_entry_boolean('initialized', self.initialized))
+            b.add_value(self.create_dict_entry_boolean('defaultNamespaces', self.default_namespaces))
+            b.add_value(self.create_dict_entry_boolean('defaultVapiDirs', self.default_vapi_dirs))
+            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))
+            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))
+            b.add_value(adi)
+            od = GLib.Variant.new_string ('options')
+            vodi = self.list_to_variant(self.options)
+            odi = GLib.Variant.new_dict_entry(od, GLib.Variant.new_variant (vodi))
+            b.add_value(odi)
+            pd = GLib.Variant.new_string ('packages')
+            vpdi = self.list_to_variant(self.packages)
+            pdi = GLib.Variant.new_dict_entry(pd, GLib.Variant.new_variant (vpdi))
+            b.add_value(pdi)
+            return b.end()
+        except:
+            print ('>>>>>>>>>>>>>>>> Invalid code!!!\n\n\n')
+            return GLib.Variant ('a{sv}', {})
+
+    def _on_get_build_commands(self, source_object, result, user_data):
+        build_commands = self.bs.get_build_flags_for_dir_finish (result)
+        for cmm in build_commands.values():
+            if cmm.startswith('valac'):
+                self.build_args = cmm
+                self.files = []
+                self.packages = []
+                self.vala_args = {}
+                self.options = []
+                args = targs.split(' ')
+                found_package = False
+                found_arg = False
+                for s in self.build_args:
+                    if found_package:
+                        self.packages += [s]
+                        found_package = False
+                        continue
+                    if found_arg:
+                        self.vala_args[arg_name] = s
+                        found_arg = False
+                        continue
+                    if s == '--pkg' or s == 'pkg':
+                        found_package = True
+                    if s.startswith('-') and not (s == '--pkg' or s == 'pkg'):
+                        if s.startswith('--version'):
+                            continue
+                        if s.startswith('--api-version'):
+                            continue
+                        if s == '-C' or s == '--ccode':
+                            self.options += [s]
+                            continue
+                        if s == '--use-header':
+                            self.options += [s]
+                            continue
+                        if s == '--fast-vapi':
+                            self.options += [s]
+                            continue
+                        if s == '--use-fast-vapi':
+                            self.options += [s]
+                            continue
+                        if s == '--vapi-comments':
+                            self.options += [s]
+                            continue
+                        if s == '--deps':
+                            self.options += [s]
+                            continue
+                        if s == '-c' or s == '--compile':
+                            self.options += [s]
+                            continue
+                        if s == '-g' or s == '--debug':
+                            self.options += [s]
+                            continue
+                        if s == '--enable-mem-profiler':
+                            self.options += [s]
+                            continue
+                        if s == '--nostdpkg':
+                            self.options += [s]
+                            continue
+                        if s == '--disable-assert':
+                            self.options += [s]
+                            continue
+                        if s == '--enable-checking':
+                            self.options += [s]
+                            continue
+                        if s == '--enable-deprecated':
+                            self.options += [s]
+                            continue
+                        if s == '--hide-internal':
+                            self.options += [s]
+                            continue
+                        if s == '--enable-experimental':
+                            self.options += [s]
+                            continue
+                        if s == '--disable-warnings':
+                            self.options += [s]
+                            continue
+                        if s == '--fatal-warnings':
+                            self.options += [s]
+                            continue
+                        if s == '--disable-since-check':
+                            self.options += [s]
+                            continue
+                        if s == '--enable-experimental-non-null':
+                            self.options += [s]
+                            continue
+                        if s == '--enable-gobject-tracing':
+                            self.options += [s]
+                            continue
+                        if s == '--save-temps':
+                            self.options += [s]
+                            continue
+                        if s == '-q' or s == '--quiet':
+                            self.options += [s]
+                            continue
+                        if s == '-v' or s == '--verbose':
+                            self.options += [s]
+                            continue
+                        if s == '--no-color':
+                            self.options += [s]
+                            continue
+                        if s == '--enable-version-header':
+                            self.options += [s]
+                            continue
+                        if s == '--disable-version-header':
+                            self.options += [s]
+                            continue
+                        if s == '--run-args':
+                            self.options += [s]
+                            continue
+                        if s == '--abi-stability':
+                            self.options += [s]
+                            continue
+                        if '--color=' in s:
+                            self.options += [s]
+                            continue
+                        if '=' in s:
+                            ps = s.split('=')
+                            if len(ps) == 2:
+                                vala_args[ps[0]] = ps[1]
+                            continue
+                        found_arg = True
+                        arg_name = s
+                        continue
+                        
     def _gvls_spawned(self, supervisor, subprocess):
         """
         This callback is executed when the `org.gnome.gvls.stdio.Server` process is spawned.
@@ -149,6 +330,23 @@ class GVlsService(Ide.Object):
         self._client.add_language('vala')
         self._client.start()
         self.notify('client')
+        try:
+            ctx = self._client.ref_context()
+            self.build_system = Ide.BuildSystem.from_context (ctx)
+            if self.build_system.get_display_name () == 'meson':
+                self.meson_build_system = True
+            else:
+                self.meson_build_system = False
+            buildmgr = Ide.BuildManager.from_context (ctx)
+            self.pipeline = buildmgr.get_pipeline ()
+            builddir = self.build_system.get_builddir(self.pipeline)
+            file_builddir = Gio.File.new_for_path(builddir)
+            self.build_system.get_build_flags_for_dir_async(file_builddir, None, 
self._on_get_build_commands, None)
+        except BaseException as exc:
+            print('\n\n\n Exception Arguments: \n')
+            print(exc.args)
+            print('')
+            
 
     def _create_launcher(self):
         """


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