[gnome-builder/1089-lsp-client-capabilites-notify-workspace-configuration-support] GVls: improved server initialization
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/1089-lsp-client-capabilites-notify-workspace-configuration-support] GVls: improved server initialization
- Date: Sun, 16 Feb 2020 19:15:04 +0000 (UTC)
commit 99b03a54bf1e902ba65f1f9fc76f58d208361f4f
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 | 256 ++++++++++++++++++++++++++++++++++++++--
1 file changed, 245 insertions(+), 11 deletions(-)
---
diff --git a/src/plugins/gvls/gvls_plugin.py b/src/plugins/gvls/gvls_plugin.py
index 8c322b76d..fb14a215c 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,19 @@ 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
+ pipeline = None
+ build_commands = None
@classmethod
def from_context(klass, context):
@@ -118,17 +132,222 @@ 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 _did_change_configuration(self, source_object, result, user_data):
+ try:
+ res = self._client.send_notification_finish(result)
+ except BaseException as exc:
+ print('\n\nChange Configuration Notification error:\n')
+ print(exc.args)
+ print('\n\n\n')
+
+ def _on_get_build_commands(self, source_object, result, user_data):
+ try:
+ self.build_commands = self.build_system.get_build_flags_for_dir_finish (result)
+ print(self.build_commands)
+ for cmm in self.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
+ vconf = self._on_load_configuration(None)
+ cancellable = self._client.ref_cancellable()
+ b = GLib.VariantBuilder(GLib.VariantType.new('a{sv}'))
+ vk = GLib.Variant.new_string ('settings')
+ vv = GLib.Variant.new_variant(GLib.Variant.new_variant(vconf))
+ de = GLib.Variant.new_dict_entry(vk, vv)
+ b.add_value(de)
+ vnotify = b.end()
+ self._client.send_notification_async("workspace/didChangeConfiguration", vnotify, cancellable,
self._did_change_configuration, None)
+ except BaseException as exc:
+ print('\n\nOn Pipeline Loaded notify configuration error:\n')
+ print(exc.args)
+ print('\n\n\n')
+
+ def _on_pipeline_loaded(self, data):
+ try:
+ pconfig = self.pipeline.get_config()
+ bc = pconfig.get_build_commands()
+ print(bc)
+ 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\nOn Pipeline Loaded start get build flags error:\n')
+ print(exc.args)
+ print('\n\n\n')
+
def _gvls_spawned(self, supervisor, subprocess):
"""
This callback is executed when the `org.gnome.gvls.stdio.Server` process is spawned.
@@ -149,6 +368,21 @@ 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_id () == 'meson':
+ self.meson_build_system = True
+ else:
+ self.meson_build_system = False
+ buildmgr = Ide.BuildManager.from_context (ctx)
+ self.pipeline = buildmgr.get_pipeline ()
+ self.pipeline.connect('loaded', self._on_pipeline_loaded)
+ except BaseException as exc:
+ print('\n\n\n Exception Arguments: \n')
+ print(exc.args)
+ print('\n\n')
+
def _create_launcher(self):
"""
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]