From f9240265159eafc16d36f22f57725bb189b2cb2e Mon Sep 17 00:00:00 2001 From: Daniel Espinosa Date: Fri, 23 Nov 2018 19:19:09 -0600 Subject: [PATCH 01/23] gvls: added new GVls completion plugin --- plugins/gvls/gvls-code-plugin.vala | 102 +++++++++++++++++++++++++++++ plugins/gvls/gvls-code.plugin | 8 +++ plugins/gvls/meson.build | 38 +++++++++++ plugins/meson.build | 1 + 4 files changed, 149 insertions(+) create mode 100644 plugins/gvls/gvls-code-plugin.vala create mode 100644 plugins/gvls/gvls-code.plugin create mode 100644 plugins/gvls/meson.build diff --git a/plugins/gvls/gvls-code-plugin.vala b/plugins/gvls/gvls-code-plugin.vala new file mode 100644 index 0000000000..4752bf246d --- /dev/null +++ b/plugins/gvls/gvls-code-plugin.vala @@ -0,0 +1,102 @@ +/* gvls-sourceview.vala + * + * Copyright 2018 Daniel Espinosa + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +using Gee; +using GVls; + +public class Scratch.Plugins.GVlsCompletion : Peas.ExtensionBase, Peas.Activatable { + MainWindow main_window; + private GVls.Server _server; + private ulong cn = 0; + private uint timeout_id = -1; + + public Object object { owned get; construct; } + public Gtk.SourceView view { get; set; } + Scratch.Services.Interface plugins; + + construct { + _server = new GVls.GServer (); + try { + _server.add_default_vapi_dirs (); + _server.add_default_namespaces (); + } catch (GLib.Error e) { + warning ("Initialization Error: %s", e.message); + } + } + ~GVlsCompletion () { + if (timeout_id != -1) { + var source = MainContext.@default ().find_source_by_id (timeout_id); + if (source != null) { + source.destroy (); + } + } + } + + public void activate () { + plugins = (Scratch.Services.Interface) object; + plugins.hook_window.connect ((w) => { + this.main_window = w; + }); + cn = plugins.hook_document.connect ((doc)=>{ + try { + var view = doc.source_view; + var prov = new GVlsui.CompletionProvider (); + prov.server = _server; + view.get_completion ().add_provider (prov); + view.set_data ("gvls-provider", prov); + view.set_data ("gvls-view-dirty", true); + var buf = view.get_buffer (); + buf.insert_text.connect ((ref pos, ntext, tlen)=>{ + view.set_data ("gvls-view-dirty", true); + }); + } catch (GLib.Error e) { + warning ("Error setting completion provider: %s", e.message); + } + + }); + timeout_id = GLib.Timeout.add (1, update_symbols); + } + public void deactivate () { + plugins.disconnect (cn); + var prov = view.get_data ("gvls-provider"); + if (prov == null) return; + view.get_completion ().remove_provider (prov); + } + public void update_state () { + } + + private bool update_symbols () { + if (view == null) return true; + var prov = view.get_data ("gvls-provider"); + if (prov == null) return true; + bool dirty = view.get_data ("gvls-view-dirty"); + if (!dirty) return true; + prov.current_server.content = view.get_buffer ().text; + view.set_data ("gvls-view-dirty", false); + return true; + } +} + +[ModuleInit] +public void peas_register_types (TypeModule module) +{ + var objmodule = module as Peas.ObjectModule; + objmodule.register_extension_type (typeof (Peas.Activatable), + typeof (Scratch.Plugins.GVlsCompletion)); +} + diff --git a/plugins/gvls/gvls-code.plugin b/plugins/gvls/gvls-code.plugin new file mode 100644 index 0000000000..29e0f70adf --- /dev/null +++ b/plugins/gvls/gvls-code.plugin @@ -0,0 +1,8 @@ +[Plugin] +Module=libgvls-plugin +IAge=0 +Name=GVls Vala Completion Plugin +Description= Provides completion for Vala sources +Authors=Daniel Espinosa +Copyright=Copyright © 2018 Daniel Espinosa Ortiz +Website=https://gitlab.gnome.org/esodan/gvls/wikis/home diff --git a/plugins/gvls/meson.build b/plugins/gvls/meson.build new file mode 100644 index 0000000000..b8a51bb7dc --- /dev/null +++ b/plugins/gvls/meson.build @@ -0,0 +1,38 @@ +module_name = 'gvls-code' + +gvls_dep = dependency ('gvlsui-0.10') + +gvls_plugin_sources = files([ + 'gvls-code-plugin.vala' + ]) + +install_data('gvls-code.plugin', install_dir: pluginsdir) + +plugin_deps = [ + gvls_dep, + codecore_dep, + ] + +shared_module(module_name, gvls_plugin_sources, + dependencies: plugin_deps, + install: true, + install_dir: pluginsdir, + vala_args: [ + '--target-glib=2.52', + ] +) + +custom_target(module_name + '.plugin_merge', + input: module_name + '.plugin', + output: module_name + '.plugin', + command : [msgfmt, + '--desktop', + '--keyword=Description', + '--keyword=Name', + '-d' + join_paths(meson.source_root (), 'po', 'plugins'), + '--template=@INPUT@', + '-o@OUTPUT@', + ], + install : true, + install_dir: join_paths(pluginsdir, module_name), +) diff --git a/plugins/meson.build b/plugins/meson.build index 2e8855ee1d..20e4916c61 100644 --- a/plugins/meson.build +++ b/plugins/meson.build @@ -13,3 +13,4 @@ subdir('strip-trailing-save') subdir('terminal') subdir('vim-emulation') subdir('word-completion') +subdir('gvls') From d0d37d43626d6ab900de270dfb55f07057abd2b6 Mon Sep 17 00:00:00 2001 From: Daniel Espinosa Date: Fri, 30 Nov 2018 13:14:05 -0600 Subject: [PATCH 02/23] gvls: fixed completion plugin --- plugins/gvls/gvls-code-plugin.vala | 33 ++++++++++++++++++++++++++---- plugins/gvls/gvls-code.plugin | 2 +- plugins/gvls/meson.build | 6 ++++-- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/plugins/gvls/gvls-code-plugin.vala b/plugins/gvls/gvls-code-plugin.vala index 4752bf246d..00fd9cafb9 100644 --- a/plugins/gvls/gvls-code-plugin.vala +++ b/plugins/gvls/gvls-code-plugin.vala @@ -20,13 +20,12 @@ using Gee; using GVls; public class Scratch.Plugins.GVlsCompletion : Peas.ExtensionBase, Peas.Activatable { - MainWindow main_window; + private MainWindow main_window; private GVls.Server _server; private ulong cn = 0; private uint timeout_id = -1; public Object object { owned get; construct; } - public Gtk.SourceView view { get; set; } Scratch.Services.Interface plugins; construct { @@ -53,8 +52,13 @@ public class Scratch.Plugins.GVlsCompletion : Peas.ExtensionBase, Peas.Activatab this.main_window = w; }); cn = plugins.hook_document.connect ((doc)=>{ + message ("Adding GVls-Completion to View"); try { var view = doc.source_view; + var ptmp = view.get_data ("gvls-provider"); + if (ptmp != null) { + return; + } var prov = new GVlsui.CompletionProvider (); prov.server = _server; view.get_completion ().add_provider (prov); @@ -67,20 +71,41 @@ public class Scratch.Plugins.GVlsCompletion : Peas.ExtensionBase, Peas.Activatab } catch (GLib.Error e) { warning ("Error setting completion provider: %s", e.message); } - }); timeout_id = GLib.Timeout.add (1, update_symbols); + message ("GVls-Completion: activated"); } public void deactivate () { - plugins.disconnect (cn); + plugins.disconnect (cn); + if (main_window == null) { + message ("No MainWindow was set"); + return; + } + var docview = main_window.get_current_view (); + foreach (Services.Document doc in docview.docs) { + var view = doc.source_view; var prov = view.get_data ("gvls-provider"); if (prov == null) return; + try { view.get_completion ().remove_provider (prov); + } catch (GLib.Error e) { + warning (_("Error deactivating GVls Plugin: %s"), e.message); + } + } + message ("GVls-Completion: deactivated"); } public void update_state () { } private bool update_symbols () { + if (main_window == null) { + return true; + } + var doc = main_window.get_current_document (); + if (doc == null) { + return true; + } + var view = main_window.get_current_document ().source_view; if (view == null) return true; var prov = view.get_data ("gvls-provider"); if (prov == null) return true; diff --git a/plugins/gvls/gvls-code.plugin b/plugins/gvls/gvls-code.plugin index 29e0f70adf..631b5dee9a 100644 --- a/plugins/gvls/gvls-code.plugin +++ b/plugins/gvls/gvls-code.plugin @@ -1,5 +1,5 @@ [Plugin] -Module=libgvls-plugin +Module=libgvls-code IAge=0 Name=GVls Vala Completion Plugin Description= Provides completion for Vala sources diff --git a/plugins/gvls/meson.build b/plugins/gvls/meson.build index b8a51bb7dc..f550c328a7 100644 --- a/plugins/gvls/meson.build +++ b/plugins/gvls/meson.build @@ -6,7 +6,9 @@ gvls_plugin_sources = files([ 'gvls-code-plugin.vala' ]) -install_data('gvls-code.plugin', install_dir: pluginsdir) +gvls_install_dir=join_paths(pluginsdir, module_name) + +install_data('gvls-code.plugin', install_dir: gvls_install_dir) plugin_deps = [ gvls_dep, @@ -16,7 +18,7 @@ plugin_deps = [ shared_module(module_name, gvls_plugin_sources, dependencies: plugin_deps, install: true, - install_dir: pluginsdir, + install_dir: gvls_install_dir, vala_args: [ '--target-glib=2.52', ] From 88747ddb36b72b11e81d1abff699335d90803356 Mon Sep 17 00:00:00 2001 From: Daniel Espinosa Date: Fri, 30 Nov 2018 13:59:44 -0600 Subject: [PATCH 03/23] gvls: code style fixes --- plugins/gvls/gvls-code-plugin.vala | 178 ++++++++++++++--------------- 1 file changed, 89 insertions(+), 89 deletions(-) diff --git a/plugins/gvls/gvls-code-plugin.vala b/plugins/gvls/gvls-code-plugin.vala index 00fd9cafb9..cea94b9b2c 100644 --- a/plugins/gvls/gvls-code-plugin.vala +++ b/plugins/gvls/gvls-code-plugin.vala @@ -20,107 +20,107 @@ using Gee; using GVls; public class Scratch.Plugins.GVlsCompletion : Peas.ExtensionBase, Peas.Activatable { - private MainWindow main_window; - private GVls.Server _server; - private ulong cn = 0; - private uint timeout_id = -1; + private MainWindow main_window; + private GVls.Server _server; + private ulong cn = 0; + private uint timeout_id = -1; - public Object object { owned get; construct; } - Scratch.Services.Interface plugins; + public Object object { owned get; construct; } + Scratch.Services.Interface plugins; - construct { - _server = new GVls.GServer (); - try { - _server.add_default_vapi_dirs (); - _server.add_default_namespaces (); - } catch (GLib.Error e) { - warning ("Initialization Error: %s", e.message); - } - } - ~GVlsCompletion () { - if (timeout_id != -1) { - var source = MainContext.@default ().find_source_by_id (timeout_id); - if (source != null) { - source.destroy (); - } + construct { + _server = new GVls.GServer (); + try { + _server.add_default_vapi_dirs (); + _server.add_default_namespaces (); + } catch (GLib.Error e) { + warning ("Initialization Error: %s", e.message); + } } - } - - public void activate () { - plugins = (Scratch.Services.Interface) object; - plugins.hook_window.connect ((w) => { - this.main_window = w; - }); - cn = plugins.hook_document.connect ((doc)=>{ - message ("Adding GVls-Completion to View"); - try { - var view = doc.source_view; - var ptmp = view.get_data ("gvls-provider"); - if (ptmp != null) { - return; + ~GVlsCompletion () { + if (timeout_id != -1) { + var source = MainContext.@default ().find_source_by_id (timeout_id); + if (source != null) { + source.destroy (); + } } - var prov = new GVlsui.CompletionProvider (); - prov.server = _server; - view.get_completion ().add_provider (prov); - view.set_data ("gvls-provider", prov); - view.set_data ("gvls-view-dirty", true); - var buf = view.get_buffer (); - buf.insert_text.connect ((ref pos, ntext, tlen)=>{ - view.set_data ("gvls-view-dirty", true); + } + public void activate () { + plugins = (Scratch.Services.Interface) object; + plugins.hook_window.connect ((w) => { + this.main_window = w; }); - } catch (GLib.Error e) { - warning ("Error setting completion provider: %s", e.message); - } - }); - timeout_id = GLib.Timeout.add (1, update_symbols); - message ("GVls-Completion: activated"); - } - public void deactivate () { - plugins.disconnect (cn); - if (main_window == null) { - message ("No MainWindow was set"); - return; + cn = plugins.hook_document.connect ((doc)=>{ + try { + var view = doc.source_view; + var ptmp = view.get_data ("gvls-provider"); + if (ptmp != null) { + return; + } + var prov = new GVlsui.CompletionProvider (); + prov.server = _server; + view.get_completion ().add_provider (prov); + view.set_data ("gvls-provider", prov); + view.set_data ("gvls-view-dirty", true); + var buf = view.get_buffer (); + buf.insert_text.connect ((ref pos, ntext, tlen)=>{ + view.set_data ("gvls-view-dirty", true); + }); + } catch (GLib.Error e) { + warning ("Error setting completion provider: %s", e.message); + } + }); + timeout_id = GLib.Timeout.add (1, update_symbols); } - var docview = main_window.get_current_view (); - foreach (Services.Document doc in docview.docs) { - var view = doc.source_view; - var prov = view.get_data ("gvls-provider"); - if (prov == null) return; - try { - view.get_completion ().remove_provider (prov); - } catch (GLib.Error e) { - warning (_("Error deactivating GVls Plugin: %s"), e.message); - } + public void deactivate () { + plugins.disconnect (cn); + if (main_window == null) { + message ("No MainWindow was set"); + return; + } + var docview = main_window.get_current_view (); + foreach (Services.Document doc in docview.docs) { + var view = doc.source_view; + var prov = view.get_data ("gvls-provider"); + if (prov == null) return; + try { + view.get_completion ().remove_provider (prov); + } catch (GLib.Error e) { + warning (_("Error deactivating GVls Plugin: %s"), e.message); + } + } } - message ("GVls-Completion: deactivated"); - } - public void update_state () { - } - - private bool update_symbols () { - if (main_window == null) { - return true; + public void update_state () { } - var doc = main_window.get_current_document (); - if (doc == null) { - return true; + private bool update_symbols () { + if (main_window == null) { + return true; + } + var doc = main_window.get_current_document (); + if (doc == null) { + return true; + } + var view = main_window.get_current_document ().source_view; + if (view == null) { + return true; + } + var prov = view.get_data ("gvls-provider"); + if (prov == null) { + return true; + } + bool dirty = view.get_data ("gvls-view-dirty"); + if (!dirty) { + return true; + } + prov.current_server.content = view.get_buffer ().text; + view.set_data ("gvls-view-dirty", false); + return true; } - var view = main_window.get_current_document ().source_view; - if (view == null) return true; - var prov = view.get_data ("gvls-provider"); - if (prov == null) return true; - bool dirty = view.get_data ("gvls-view-dirty"); - if (!dirty) return true; - prov.current_server.content = view.get_buffer ().text; - view.set_data ("gvls-view-dirty", false); - return true; - } } [ModuleInit] -public void peas_register_types (TypeModule module) -{ - var objmodule = module as Peas.ObjectModule; +public void peas_register_types (TypeModule module) { + var objmodule = module as Peas.ObjectModule; objmodule.register_extension_type (typeof (Peas.Activatable), typeof (Scratch.Plugins.GVlsCompletion)); } From 9d25772d9039c18979383fe18b374bde1ee31667 Mon Sep 17 00:00:00 2001 From: Daniel Espinosa Date: Wed, 12 Dec 2018 09:36:06 -0600 Subject: [PATCH 04/23] gvls: plugin now is optional --- plugins/gvls/meson.build | 2 -- plugins/meson.build | 4 ++++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/gvls/meson.build b/plugins/gvls/meson.build index f550c328a7..b384a6b622 100644 --- a/plugins/gvls/meson.build +++ b/plugins/gvls/meson.build @@ -1,7 +1,5 @@ module_name = 'gvls-code' -gvls_dep = dependency ('gvlsui-0.10') - gvls_plugin_sources = files([ 'gvls-code-plugin.vala' ]) diff --git a/plugins/meson.build b/plugins/meson.build index 20e4916c61..c4b4460070 100644 --- a/plugins/meson.build +++ b/plugins/meson.build @@ -13,4 +13,8 @@ subdir('strip-trailing-save') subdir('terminal') subdir('vim-emulation') subdir('word-completion') + +gvls_dep = dependency ('gvlsui-0.10', required: false) +if gvls_dep.found() subdir('gvls') +endif From f488344283f4db7824fd967d0defe2f87c849e69 Mon Sep 17 00:00:00 2001 From: Daniel Espinosa Ortiz Date: Wed, 13 Nov 2019 19:21:34 -0600 Subject: [PATCH 05/23] GVls: initial port to 0.12 API --- plugins/gvls/gvls-code-plugin.vala | 121 ++++++++++++++++++++++------- plugins/meson.build | 2 +- 2 files changed, 93 insertions(+), 30 deletions(-) diff --git a/plugins/gvls/gvls-code-plugin.vala b/plugins/gvls/gvls-code-plugin.vala index cea94b9b2c..5fd2b0f004 100644 --- a/plugins/gvls/gvls-code-plugin.vala +++ b/plugins/gvls/gvls-code-plugin.vala @@ -21,25 +21,16 @@ using GVls; public class Scratch.Plugins.GVlsCompletion : Peas.ExtensionBase, Peas.Activatable { private MainWindow main_window; - private GVls.Server _server; private ulong cn = 0; - private uint timeout_id = -1; + private uint timed_id = -1; + private bool lsp_sync_in_progress = false; public Object object { owned get; construct; } Scratch.Services.Interface plugins; - construct { - _server = new GVls.GServer (); - try { - _server.add_default_vapi_dirs (); - _server.add_default_namespaces (); - } catch (GLib.Error e) { - warning ("Initialization Error: %s", e.message); - } - } ~GVlsCompletion () { - if (timeout_id != -1) { - var source = MainContext.@default ().find_source_by_id (timeout_id); + if (timed_id != -1) { + var source = MainContext.@default ().find_source_by_id (timed_id); if (source != null) { source.destroy (); } @@ -47,30 +38,74 @@ public class Scratch.Plugins.GVlsCompletion : Peas.ExtensionBase, Peas.Activatab } public void activate () { plugins = (Scratch.Services.Interface) object; + + GVlsp.ServerInetLocal server = new GVlsp.ServerInetLocal (); + + try { + server.run (); + server.server.add_default_vapi_dirs (); + } catch (GLib.Error e) { + warning ("Initialization Error: %s", e.message); + } + + plugins.set_data ("gvls-server", server); + + GVls.Client client = new GVlsp.ClientInetLocal (); + plugins.set_data ("gvls-client", client); + + timed_id = Timeout.add (1000, push_document_changes); + plugins.hook_window.connect ((w) => { this.main_window = w; }); cn = plugins.hook_document.connect ((doc)=>{ try { + var cl = plugins.get_data ("gvls-client"); + if (cl == null) { + return; + } var view = doc.source_view; + var file = doc.file; + if (file == null) { + return; + } var ptmp = view.get_data ("gvls-provider"); if (ptmp != null) { return; } var prov = new GVlsui.CompletionProvider (); - prov.server = _server; + prov.client = client; view.get_completion ().add_provider (prov); view.set_data ("gvls-provider", prov); view.set_data ("gvls-view-dirty", true); + GVls.Container changes = new GVls.GContainer.for_type (typeof (GTextDocumentContentChangeEvent)); + view.set_data ("gvls-changes", changes); var buf = view.get_buffer (); - buf.insert_text.connect ((ref pos, ntext, tlen)=>{ - view.set_data ("gvls-view-dirty", true); + buf.delete_range.connect ((start, end)=>{ + var chgs = view.get_data ("gvls-changes"); + var pstart = new GPosition.from_values (start.get_line (), start.get_line_offset ()); + var pend = new GPosition.from_values (end.get_line (), end.get_line_offset ()); + var change = new GTextDocumentContentChangeEvent (); + change.range.start = pstart; + change.range.end = pend; + change.text = null; + chgs.add (change); + }); + buf.insert_text.connect ((ref pos, text)=>{ + var chgs = view.get_data ("gvls-changes"); + var pstart = new GPosition.from_values (pos.get_line (), pos.get_line_offset ()); + var pend = new GPosition.from_values (pos.get_line (), pos.get_line_offset ()); + var change = new GTextDocumentContentChangeEvent (); + change.range.start = pstart; + change.range.end = pend; + change.text = text; + chgs.add (change); }); + cl.document_open.begin (file.get_uri (), buf.text); } catch (GLib.Error e) { warning ("Error setting completion provider: %s", e.message); } }); - timeout_id = GLib.Timeout.add (1, update_symbols); } public void deactivate () { plugins.disconnect (cn); @@ -89,31 +124,59 @@ public class Scratch.Plugins.GVlsCompletion : Peas.ExtensionBase, Peas.Activatab warning (_("Error deactivating GVls Plugin: %s"), e.message); } } + + var client = plugins.get_data ("gvls-client"); + if (client != null) { + client.server_shutdown.begin (); + } + if (timed_id != -1) { + var source = MainContext.@default ().find_source_by_id (timed_id); + if (source != null) { + source.destroy (); + } + } } public void update_state () { } - private bool update_symbols () { - if (main_window == null) { + private bool push_document_changes () { + if (lsp_sync_in_progress) { return true; } - var doc = main_window.get_current_document (); - if (doc == null) { + var client = plugins.get_data ("gvls-client"); + if (client == null) { return true; } - var view = main_window.get_current_document ().source_view; - if (view == null) { + if (main_window == null) { + message ("No MainWindow was set"); return true; } - var prov = view.get_data ("gvls-provider"); - if (prov == null) { + var doc = main_window.get_current_document (); + var view = main_window.get_current_view (); + var file = doc.file; + if (file == null) { return true; } - bool dirty = view.get_data ("gvls-view-dirty"); - if (!dirty) { + var chgs = view.get_data ("gvls-changes"); + if (chgs == null) { return true; } - prov.current_server.content = view.get_buffer ().text; - view.set_data ("gvls-view-dirty", false); + + if (chgs.get_n_items () != 0) { + GVls.Container current_changes = chgs; + chgs = new GVls.GContainer.for_type (typeof (GTextDocumentContentChangeEvent)); + view.set_data ("gvls-changes", chgs); + lsp_sync_in_progress = true; + var uri = file.get_uri (); + client.document_change.begin (uri, current_changes, (obj, res)=>{ + try { + client.document_change.end (res); + lsp_sync_in_progress = false; + } catch (GLib.Error e) { + warning ("Error while pushing changes to the server: %s", e.message); + } + }); + } + return true; } } diff --git a/plugins/meson.build b/plugins/meson.build index c4b4460070..f7d0213f3d 100644 --- a/plugins/meson.build +++ b/plugins/meson.build @@ -14,7 +14,7 @@ subdir('terminal') subdir('vim-emulation') subdir('word-completion') -gvls_dep = dependency ('gvlsui-0.10', required: false) +gvls_dep = dependency ('gvlsui-0.12', required: false) if gvls_dep.found() subdir('gvls') endif From 0599dfb80d33a0da399aff3573b9b1de56209f41 Mon Sep 17 00:00:00 2001 From: Daniel Espinosa Ortiz Date: Wed, 13 Nov 2019 20:10:57 -0600 Subject: [PATCH 06/23] GVls: fixes to work with welcome view Current welcome view is not a document, so a workaround has been provided even in Code to avoid invalid casts --- plugins/gvls/gvls-code-plugin.vala | 26 +++++++++++++++++++++++++- src/Widgets/DocumentView.vala | 6 +++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/plugins/gvls/gvls-code-plugin.vala b/plugins/gvls/gvls-code-plugin.vala index 5fd2b0f004..15114709d5 100644 --- a/plugins/gvls/gvls-code-plugin.vala +++ b/plugins/gvls/gvls-code-plugin.vala @@ -24,6 +24,7 @@ public class Scratch.Plugins.GVlsCompletion : Peas.ExtensionBase, Peas.Activatab private ulong cn = 0; private uint timed_id = -1; private bool lsp_sync_in_progress = false; + private bool initiated = false; public Object object { owned get; construct; } Scratch.Services.Interface plugins; @@ -69,6 +70,11 @@ public class Scratch.Plugins.GVlsCompletion : Peas.ExtensionBase, Peas.Activatab if (file == null) { return; } + if (!initiated) { + cl.initialize.begin (file.get_uri (), ()=>{ + initiated = true; + }); + } var ptmp = view.get_data ("gvls-provider"); if (ptmp != null) { return; @@ -114,6 +120,9 @@ public class Scratch.Plugins.GVlsCompletion : Peas.ExtensionBase, Peas.Activatab return; } var docview = main_window.get_current_view (); + if (!(docview is Scratch.Widgets.DocumentView)) { + return; + } foreach (Services.Document doc in docview.docs) { var view = doc.source_view; var prov = view.get_data ("gvls-provider"); @@ -142,20 +151,35 @@ public class Scratch.Plugins.GVlsCompletion : Peas.ExtensionBase, Peas.Activatab if (lsp_sync_in_progress) { return true; } + var client = plugins.get_data ("gvls-client"); if (client == null) { return true; } + if (main_window == null) { message ("No MainWindow was set"); return true; } - var doc = main_window.get_current_document (); + var view = main_window.get_current_view (); + if (view == null) { + return true; + } + if (!(view is Scratch.Widgets.DocumentView)) { + return true; + } + + var doc = main_window.get_current_document (); + if (doc == null) { + return true; + } + var file = doc.file; if (file == null) { return true; } + var chgs = view.get_data ("gvls-changes"); if (chgs == null) { return true; diff --git a/src/Widgets/DocumentView.vala b/src/Widgets/DocumentView.vala index a3ae2a0a0c..4cd261a050 100644 --- a/src/Widgets/DocumentView.vala +++ b/src/Widgets/DocumentView.vala @@ -26,7 +26,11 @@ public class Scratch.Widgets.DocumentView : Granite.Widgets.DynamicNotebook { public Services.Document current_document { get { - return (Services.Document) current; + unowned Services.Document doc = null; + if (current is Services.Document) { + doc = (Services.Document) current; + } + return doc; } set { current = value; From 2ed4beafea8fb477759df18dfe83afecad2cc6a5 Mon Sep 17 00:00:00 2001 From: Daniel Espinosa Ortiz Date: Wed, 13 Nov 2019 20:28:58 -0600 Subject: [PATCH 07/23] GVls: fix server initialization --- plugins/gvls/gvls-code-plugin.vala | 101 +++++++++++++++++++---------- 1 file changed, 65 insertions(+), 36 deletions(-) diff --git a/plugins/gvls/gvls-code-plugin.vala b/plugins/gvls/gvls-code-plugin.vala index 15114709d5..bdbc396b23 100644 --- a/plugins/gvls/gvls-code-plugin.vala +++ b/plugins/gvls/gvls-code-plugin.vala @@ -65,54 +65,83 @@ public class Scratch.Plugins.GVlsCompletion : Peas.ExtensionBase, Peas.Activatab if (cl == null) { return; } - var view = doc.source_view; var file = doc.file; if (file == null) { return; } if (!initiated) { - cl.initialize.begin (file.get_uri (), ()=>{ - initiated = true; + cl.initialize.begin (file.get_uri (), (obj, res)=>{ + try { + cl.initialize.end (res); + initiated = true; + init_doc (doc, cl); + } catch (GLib.Error e) { + warning ("Error setting completion provider: %s", e.message); + } }); + } else { + init_doc (doc, cl); } - var ptmp = view.get_data ("gvls-provider"); - if (ptmp != null) { - return; - } - var prov = new GVlsui.CompletionProvider (); - prov.client = client; - view.get_completion ().add_provider (prov); - view.set_data ("gvls-provider", prov); - view.set_data ("gvls-view-dirty", true); - GVls.Container changes = new GVls.GContainer.for_type (typeof (GTextDocumentContentChangeEvent)); - view.set_data ("gvls-changes", changes); - var buf = view.get_buffer (); - buf.delete_range.connect ((start, end)=>{ - var chgs = view.get_data ("gvls-changes"); - var pstart = new GPosition.from_values (start.get_line (), start.get_line_offset ()); - var pend = new GPosition.from_values (end.get_line (), end.get_line_offset ()); - var change = new GTextDocumentContentChangeEvent (); - change.range.start = pstart; - change.range.end = pend; - change.text = null; - chgs.add (change); - }); - buf.insert_text.connect ((ref pos, text)=>{ - var chgs = view.get_data ("gvls-changes"); - var pstart = new GPosition.from_values (pos.get_line (), pos.get_line_offset ()); - var pend = new GPosition.from_values (pos.get_line (), pos.get_line_offset ()); - var change = new GTextDocumentContentChangeEvent (); - change.range.start = pstart; - change.range.end = pend; - change.text = text; - chgs.add (change); - }); - cl.document_open.begin (file.get_uri (), buf.text); } catch (GLib.Error e) { warning ("Error setting completion provider: %s", e.message); } }); } + + private void init_doc (Scratch.Services.Document doc, + GVls.Client client) throws GLib.Error + { + var cl = plugins.get_data ("gvls-client"); + if (cl == null) { + return; + } + var view = doc.source_view; + var file = doc.file; + if (file == null) { + return; + } + var ptmp = view.get_data ("gvls-provider"); + if (ptmp != null) { + return; + } + var prov = new GVlsui.CompletionProvider (); + prov.client = client; + view.get_completion ().add_provider (prov); + view.set_data ("gvls-provider", prov); + view.set_data ("gvls-view-dirty", true); + GVls.Container changes = new GVls.GContainer.for_type (typeof (GTextDocumentContentChangeEvent)); + view.set_data ("gvls-changes", changes); + var buf = view.get_buffer (); + buf.delete_range.connect ((start, end)=>{ + var chgs = view.get_data ("gvls-changes"); + var pstart = new GPosition.from_values (start.get_line (), start.get_line_offset ()); + var pend = new GPosition.from_values (end.get_line (), end.get_line_offset ()); + var change = new GTextDocumentContentChangeEvent (); + change.range.start = pstart; + change.range.end = pend; + change.text = null; + chgs.add (change); + }); + buf.insert_text.connect ((ref pos, text)=>{ + var chgs = view.get_data ("gvls-changes"); + var pstart = new GPosition.from_values (pos.get_line (), pos.get_line_offset ()); + var pend = new GPosition.from_values (pos.get_line (), pos.get_line_offset ()); + var change = new GTextDocumentContentChangeEvent (); + change.range.start = pstart; + change.range.end = pend; + change.text = text; + chgs.add (change); + }); + client.document_open.begin (file.get_uri (), buf.text, (obj, res)=>{ + try { + client.document_open.end (res); + } catch (GLib.Error e) { + warning ("Error while send didOpen notification: %s", e.message); + } + }); + } + + public void deactivate () { plugins.disconnect (cn); if (main_window == null) { From 02d65aad2dac2327c1c32569946a95be66be0354 Mon Sep 17 00:00:00 2001 From: Daniel Espinosa Ortiz Date: Thu, 14 Nov 2019 11:50:57 -0600 Subject: [PATCH 08/23] GVls: updated to latest API changes for 0.12 release --- plugins/gvls/gvls-code-plugin.vala | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/plugins/gvls/gvls-code-plugin.vala b/plugins/gvls/gvls-code-plugin.vala index bdbc396b23..f7fb3a525a 100644 --- a/plugins/gvls/gvls-code-plugin.vala +++ b/plugins/gvls/gvls-code-plugin.vala @@ -109,14 +109,14 @@ public class Scratch.Plugins.GVlsCompletion : Peas.ExtensionBase, Peas.Activatab view.get_completion ().add_provider (prov); view.set_data ("gvls-provider", prov); view.set_data ("gvls-view-dirty", true); - GVls.Container changes = new GVls.GContainer.for_type (typeof (GTextDocumentContentChangeEvent)); + GVls.Container changes = new GVls.ContainerHashList.for_type (typeof (TextDocumentContentChangeEventInfo)); view.set_data ("gvls-changes", changes); var buf = view.get_buffer (); buf.delete_range.connect ((start, end)=>{ var chgs = view.get_data ("gvls-changes"); - var pstart = new GPosition.from_values (start.get_line (), start.get_line_offset ()); - var pend = new GPosition.from_values (end.get_line (), end.get_line_offset ()); - var change = new GTextDocumentContentChangeEvent (); + var pstart = new SourcePosition.from_values (start.get_line (), start.get_line_offset ()); + var pend = new SourcePosition.from_values (end.get_line (), end.get_line_offset ()); + var change = new TextDocumentContentChangeEventInfo (); change.range.start = pstart; change.range.end = pend; change.text = null; @@ -124,9 +124,9 @@ public class Scratch.Plugins.GVlsCompletion : Peas.ExtensionBase, Peas.Activatab }); buf.insert_text.connect ((ref pos, text)=>{ var chgs = view.get_data ("gvls-changes"); - var pstart = new GPosition.from_values (pos.get_line (), pos.get_line_offset ()); - var pend = new GPosition.from_values (pos.get_line (), pos.get_line_offset ()); - var change = new GTextDocumentContentChangeEvent (); + var pstart = new SourcePosition.from_values (pos.get_line (), pos.get_line_offset ()); + var pend = new SourcePosition.from_values (pos.get_line (), pos.get_line_offset ()); + var change = new TextDocumentContentChangeEventInfo (); change.range.start = pstart; change.range.end = pend; change.text = text; @@ -216,7 +216,7 @@ public class Scratch.Plugins.GVlsCompletion : Peas.ExtensionBase, Peas.Activatab if (chgs.get_n_items () != 0) { GVls.Container current_changes = chgs; - chgs = new GVls.GContainer.for_type (typeof (GTextDocumentContentChangeEvent)); + chgs = new GVls.ContainerHashList.for_type (typeof (TextDocumentContentChangeEventInfo)); view.set_data ("gvls-changes", chgs); lsp_sync_in_progress = true; var uri = file.get_uri (); From 7ef112312e16800ae22cc3928ad5fcf3cdec16e4 Mon Sep 17 00:00:00 2001 From: Daniel Espinosa Ortiz Date: Mon, 6 Jul 2020 19:56:00 -0500 Subject: [PATCH 09/23] GVls: Ported to 0.16.0 --- plugins/gvls/gvls-code-plugin.vala | 11 ++++++++++- plugins/gvls/gvls-code.plugin | 2 +- plugins/meson.build | 4 ++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/plugins/gvls/gvls-code-plugin.vala b/plugins/gvls/gvls-code-plugin.vala index f7fb3a525a..8bcd2edbde 100644 --- a/plugins/gvls/gvls-code-plugin.vala +++ b/plugins/gvls/gvls-code-plugin.vala @@ -37,6 +37,7 @@ public class Scratch.Plugins.GVlsCompletion : Peas.ExtensionBase, Peas.Activatab } } } + public void activate () { plugins = (Scratch.Services.Interface) object; @@ -44,7 +45,7 @@ public class Scratch.Plugins.GVlsCompletion : Peas.ExtensionBase, Peas.Activatab try { server.run (); - server.server.add_default_vapi_dirs (); + server.target_manager.add_default_vapi_dirs (); } catch (GLib.Error e) { warning ("Initialization Error: %s", e.message); } @@ -95,15 +96,18 @@ public class Scratch.Plugins.GVlsCompletion : Peas.ExtensionBase, Peas.Activatab if (cl == null) { return; } + var view = doc.source_view; var file = doc.file; if (file == null) { return; } + var ptmp = view.get_data ("gvls-provider"); if (ptmp != null) { return; } + var prov = new GVlsui.CompletionProvider (); prov.client = client; view.get_completion ().add_provider (prov); @@ -122,6 +126,7 @@ public class Scratch.Plugins.GVlsCompletion : Peas.ExtensionBase, Peas.Activatab change.text = null; chgs.add (change); }); + buf.insert_text.connect ((ref pos, text)=>{ var chgs = view.get_data ("gvls-changes"); var pstart = new SourcePosition.from_values (pos.get_line (), pos.get_line_offset ()); @@ -132,6 +137,7 @@ public class Scratch.Plugins.GVlsCompletion : Peas.ExtensionBase, Peas.Activatab change.text = text; chgs.add (change); }); + client.document_open.begin (file.get_uri (), buf.text, (obj, res)=>{ try { client.document_open.end (res); @@ -148,10 +154,12 @@ public class Scratch.Plugins.GVlsCompletion : Peas.ExtensionBase, Peas.Activatab message ("No MainWindow was set"); return; } + var docview = main_window.get_current_view (); if (!(docview is Scratch.Widgets.DocumentView)) { return; } + foreach (Services.Document doc in docview.docs) { var view = doc.source_view; var prov = view.get_data ("gvls-provider"); @@ -167,6 +175,7 @@ public class Scratch.Plugins.GVlsCompletion : Peas.ExtensionBase, Peas.Activatab if (client != null) { client.server_shutdown.begin (); } + if (timed_id != -1) { var source = MainContext.@default ().find_source_by_id (timed_id); if (source != null) { diff --git a/plugins/gvls/gvls-code.plugin b/plugins/gvls/gvls-code.plugin index 631b5dee9a..20407e5bde 100644 --- a/plugins/gvls/gvls-code.plugin +++ b/plugins/gvls/gvls-code.plugin @@ -4,5 +4,5 @@ IAge=0 Name=GVls Vala Completion Plugin Description= Provides completion for Vala sources Authors=Daniel Espinosa -Copyright=Copyright © 2018 Daniel Espinosa Ortiz +Copyright=Copyright © 2018-2020 Daniel Espinosa Ortiz Website=https://gitlab.gnome.org/esodan/gvls/wikis/home diff --git a/plugins/meson.build b/plugins/meson.build index f7d0213f3d..51b4fdc368 100644 --- a/plugins/meson.build +++ b/plugins/meson.build @@ -14,7 +14,7 @@ subdir('terminal') subdir('vim-emulation') subdir('word-completion') -gvls_dep = dependency ('gvlsui-0.12', required: false) +gvls_dep = dependency ('gvlsui-0.16', required: false) if gvls_dep.found() -subdir('gvls') + subdir('gvls') endif From dfaee0430a1ef3b3bd4636a3625d20ef403fffa9 Mon Sep 17 00:00:00 2001 From: Daniel Espinosa Ortiz Date: Mon, 6 Jul 2020 20:05:45 -0500 Subject: [PATCH 10/23] gvls: use doc to get current source view --- plugins/gvls/gvls-code-plugin.vala | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/plugins/gvls/gvls-code-plugin.vala b/plugins/gvls/gvls-code-plugin.vala index 8bcd2edbde..1dd18ded8b 100644 --- a/plugins/gvls/gvls-code-plugin.vala +++ b/plugins/gvls/gvls-code-plugin.vala @@ -43,12 +43,8 @@ public class Scratch.Plugins.GVlsCompletion : Peas.ExtensionBase, Peas.Activatab GVlsp.ServerInetLocal server = new GVlsp.ServerInetLocal (); - try { - server.run (); - server.target_manager.add_default_vapi_dirs (); - } catch (GLib.Error e) { - warning ("Initialization Error: %s", e.message); - } + server.run (); + server.target_manager.add_default_vapi_dirs (); plugins.set_data ("gvls-server", server); @@ -200,16 +196,17 @@ public class Scratch.Plugins.GVlsCompletion : Peas.ExtensionBase, Peas.Activatab return true; } - var view = main_window.get_current_view (); - if (view == null) { + var doc = main_window.get_current_document (); + if (doc == null) { return true; } - if (!(view is Scratch.Widgets.DocumentView)) { + + var view = doc.source_view; + if (view == null) { return true; } - var doc = main_window.get_current_document (); - if (doc == null) { + if (!(view is Scratch.Widgets.DocumentView)) { return true; } From 01de4ec4c3da771780e150fe6995e619d7848ee3 Mon Sep 17 00:00:00 2001 From: Daniel Espinosa Date: Mon, 6 Jul 2020 20:09:30 -0500 Subject: [PATCH 11/23] gvls: Change style for init_doc() Co-authored-by: Cassidy James Blaede --- plugins/gvls/gvls-code-plugin.vala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/gvls/gvls-code-plugin.vala b/plugins/gvls/gvls-code-plugin.vala index 1dd18ded8b..a8032bb90c 100644 --- a/plugins/gvls/gvls-code-plugin.vala +++ b/plugins/gvls/gvls-code-plugin.vala @@ -85,7 +85,8 @@ public class Scratch.Plugins.GVlsCompletion : Peas.ExtensionBase, Peas.Activatab }); } - private void init_doc (Scratch.Services.Document doc, + private void init_doc ( + Scratch.Services.Document doc, GVls.Client client) throws GLib.Error { var cl = plugins.get_data ("gvls-client"); @@ -246,4 +247,3 @@ public void peas_register_types (TypeModule module) { objmodule.register_extension_type (typeof (Peas.Activatable), typeof (Scratch.Plugins.GVlsCompletion)); } - From 76b9d94abf0ea714215b416b6223f5d8e9708bda Mon Sep 17 00:00:00 2001 From: Daniel Espinosa Date: Mon, 6 Jul 2020 20:10:37 -0500 Subject: [PATCH 12/23] gvls: more changes to code style for init_doc() Co-authored-by: Cassidy James Blaede --- plugins/gvls/gvls-code-plugin.vala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/gvls/gvls-code-plugin.vala b/plugins/gvls/gvls-code-plugin.vala index a8032bb90c..25b8ccd5d8 100644 --- a/plugins/gvls/gvls-code-plugin.vala +++ b/plugins/gvls/gvls-code-plugin.vala @@ -87,7 +87,8 @@ public class Scratch.Plugins.GVlsCompletion : Peas.ExtensionBase, Peas.Activatab private void init_doc ( Scratch.Services.Document doc, - GVls.Client client) throws GLib.Error + GVls.Client client + ) throws GLib.Error { { var cl = plugins.get_data ("gvls-client"); if (cl == null) { From a035faa601e5d128c3d70bf78f72c60a3585e8e1 Mon Sep 17 00:00:00 2001 From: Daniel Espinosa Date: Mon, 6 Jul 2020 20:12:03 -0500 Subject: [PATCH 13/23] gvls: Update init_doc() code style Co-authored-by: Cassidy James Blaede --- plugins/gvls/gvls-code-plugin.vala | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/gvls/gvls-code-plugin.vala b/plugins/gvls/gvls-code-plugin.vala index 25b8ccd5d8..9387ddabe6 100644 --- a/plugins/gvls/gvls-code-plugin.vala +++ b/plugins/gvls/gvls-code-plugin.vala @@ -89,7 +89,6 @@ public class Scratch.Plugins.GVlsCompletion : Peas.ExtensionBase, Peas.Activatab Scratch.Services.Document doc, GVls.Client client ) throws GLib.Error { - { var cl = plugins.get_data ("gvls-client"); if (cl == null) { return; From daf3fbbd68ebf7b47b992123bfc008ccdab16b69 Mon Sep 17 00:00:00 2001 From: Daniel Espinosa Ortiz Date: Mon, 6 Jul 2020 20:21:45 -0500 Subject: [PATCH 14/23] gvls: code style updates for lint --- plugins/gvls/gvls-code-plugin.vala | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/gvls/gvls-code-plugin.vala b/plugins/gvls/gvls-code-plugin.vala index 9387ddabe6..42287dbbd2 100644 --- a/plugins/gvls/gvls-code-plugin.vala +++ b/plugins/gvls/gvls-code-plugin.vala @@ -247,3 +247,4 @@ public void peas_register_types (TypeModule module) { objmodule.register_extension_type (typeof (Peas.Activatable), typeof (Scratch.Plugins.GVlsCompletion)); } + From 3a5e7f484119872c7adc308735e801b462157b7d Mon Sep 17 00:00:00 2001 From: Daniel Espinosa Ortiz Date: Mon, 6 Jul 2020 20:36:40 -0500 Subject: [PATCH 15/23] gvls: remove extra new lines at the end of file --- plugins/gvls/gvls-code-plugin.vala | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/gvls/gvls-code-plugin.vala b/plugins/gvls/gvls-code-plugin.vala index 42287dbbd2..9387ddabe6 100644 --- a/plugins/gvls/gvls-code-plugin.vala +++ b/plugins/gvls/gvls-code-plugin.vala @@ -247,4 +247,3 @@ public void peas_register_types (TypeModule module) { objmodule.register_extension_type (typeof (Peas.Activatable), typeof (Scratch.Plugins.GVlsCompletion)); } - From e77d508372a1839c28e2f9d10f70babf40ebaed4 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Tue, 8 Jun 2021 17:01:17 +0100 Subject: [PATCH 16/23] Fix code style and fix compilation for gvls-20 * Copyright * More descriptive names * Lose "using" - explicit namespacing * Remove some unneeded checks * Replace tabs with spaces * Add dependencies on gvlsp-20 and gvlsui-20 --- plugins/gvls/gvls-code-plugin.vala | 209 +++++++++++++---------------- plugins/gvls/meson.build | 24 ++-- plugins/meson.build | 6 +- 3 files changed, 110 insertions(+), 129 deletions(-) diff --git a/plugins/gvls/gvls-code-plugin.vala b/plugins/gvls/gvls-code-plugin.vala index 9387ddabe6..fb1af8ac6e 100644 --- a/plugins/gvls/gvls-code-plugin.vala +++ b/plugins/gvls/gvls-code-plugin.vala @@ -1,6 +1,6 @@ /* gvls-sourceview.vala * - * Copyright 2018 Daniel Espinosa + * Copyright 2021 Daniel Espinosa * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by @@ -14,15 +14,14 @@ * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . + * + * Author: Daniel Espinosa */ -using Gee; -using GVls; - public class Scratch.Plugins.GVlsCompletion : Peas.ExtensionBase, Peas.Activatable { private MainWindow main_window; - private ulong cn = 0; - private uint timed_id = -1; + private ulong hook_document_handle = 0; + private uint timed_id = 0; private bool lsp_sync_in_progress = false; private bool initiated = false; @@ -30,7 +29,7 @@ public class Scratch.Plugins.GVlsCompletion : Peas.ExtensionBase, Peas.Activatab Scratch.Services.Interface plugins; ~GVlsCompletion () { - if (timed_id != -1) { + if (timed_id != 0) { var source = MainContext.@default ().find_source_by_id (timed_id); if (source != null) { source.destroy (); @@ -56,10 +55,10 @@ public class Scratch.Plugins.GVlsCompletion : Peas.ExtensionBase, Peas.Activatab plugins.hook_window.connect ((w) => { this.main_window = w; }); - cn = plugins.hook_document.connect ((doc)=>{ + hook_document_handle = plugins.hook_document.connect ((doc)=>{ try { - var cl = plugins.get_data ("gvls-client"); - if (cl == null) { + var gvls_client = plugins.get_data ("gvls-client"); + if (gvls_client == null) { return; } var file = doc.file; @@ -67,17 +66,17 @@ public class Scratch.Plugins.GVlsCompletion : Peas.ExtensionBase, Peas.Activatab return; } if (!initiated) { - cl.initialize.begin (file.get_uri (), (obj, res)=>{ + gvls_client.initialize.begin (file.get_uri (), (obj, res)=>{ try { - cl.initialize.end (res); + gvls_client.initialize.end (res); initiated = true; - init_doc (doc, cl); + init_doc (doc, gvls_client); } catch (GLib.Error e) { warning ("Error setting completion provider: %s", e.message); } }); } else { - init_doc (doc, cl); + init_doc (doc, gvls_client); } } catch (GLib.Error e) { warning ("Error setting completion provider: %s", e.message); @@ -85,12 +84,9 @@ public class Scratch.Plugins.GVlsCompletion : Peas.ExtensionBase, Peas.Activatab }); } - private void init_doc ( - Scratch.Services.Document doc, - GVls.Client client - ) throws GLib.Error { - var cl = plugins.get_data ("gvls-client"); - if (cl == null) { + private void init_doc (Scratch.Services.Document doc, GVls.Client client) throws GLib.Error { + var gvls_client = plugins.get_data ("gvls-client"); + if (gvls_client == null) { return; } @@ -100,42 +96,43 @@ public class Scratch.Plugins.GVlsCompletion : Peas.ExtensionBase, Peas.Activatab return; } - var ptmp = view.get_data ("gvls-provider"); - if (ptmp != null) { + var gvls_provider = view.get_data ("gvls-provider"); + if (gvls_provider != null) { return; } - var prov = new GVlsui.CompletionProvider (); - prov.client = client; - view.get_completion ().add_provider (prov); - view.set_data ("gvls-provider", prov); + var completion_provider = new GVlsui.CompletionProvider (); + // completion_provider.client = client; GVlsui.CompletionProvider does not have property "client" in version 20 + + view.get_completion ().add_provider (completion_provider); + view.set_data ("gvls-provider", completion_provider); view.set_data ("gvls-view-dirty", true); - GVls.Container changes = new GVls.ContainerHashList.for_type (typeof (TextDocumentContentChangeEventInfo)); + GVls.Container changes = new GVls.ContainerHashList.for_type (typeof (GVls.TextDocumentContentChangeEventInfo)); view.set_data ("gvls-changes", changes); - var buf = view.get_buffer (); - buf.delete_range.connect ((start, end)=>{ - var chgs = view.get_data ("gvls-changes"); - var pstart = new SourcePosition.from_values (start.get_line (), start.get_line_offset ()); - var pend = new SourcePosition.from_values (end.get_line (), end.get_line_offset ()); - var change = new TextDocumentContentChangeEventInfo (); - change.range.start = pstart; - change.range.end = pend; - change.text = null; - chgs.add (change); + var buffer = view.get_buffer (); + buffer.delete_range.connect ((start, end)=>{ + var gvls_changes = view.get_data ("gvls-changes"); + var start_pos = new GVls.SourcePosition.from_values (start.get_line (), start.get_line_offset ()); + var end_pos = new GVls.SourcePosition.from_values (end.get_line (), end.get_line_offset ()); + var content_change = new GVls.TextDocumentContentChangeEventInfo (); + content_change.range.start = start_pos; + content_change.range.end = end_pos; + content_change.text = null; + gvls_changes.add (content_change); }); - buf.insert_text.connect ((ref pos, text)=>{ - var chgs = view.get_data ("gvls-changes"); - var pstart = new SourcePosition.from_values (pos.get_line (), pos.get_line_offset ()); - var pend = new SourcePosition.from_values (pos.get_line (), pos.get_line_offset ()); - var change = new TextDocumentContentChangeEventInfo (); - change.range.start = pstart; - change.range.end = pend; - change.text = text; - chgs.add (change); + buffer.insert_text.connect ((ref pos, _text)=>{ + var gvls_changes = view.get_data ("gvls-changes"); + var start_pos = new GVls.SourcePosition.from_values (pos.get_line (), pos.get_line_offset ()); + var end_pos = new GVls.SourcePosition.from_values (pos.get_line (), pos.get_line_offset ()); + var content_change = new GVls.TextDocumentContentChangeEventInfo (); + content_change.range.start = start_pos; + content_change.range.end = end_pos; + content_change.text = _text; + gvls_changes.add (content_change); }); - client.document_open.begin (file.get_uri (), buf.text, (obj, res)=>{ + client.document_open.begin (file.get_uri (), buffer.text, (obj, res)=>{ try { client.document_open.end (res); } catch (GLib.Error e) { @@ -144,9 +141,8 @@ public class Scratch.Plugins.GVlsCompletion : Peas.ExtensionBase, Peas.Activatab }); } - public void deactivate () { - plugins.disconnect (cn); + plugins.disconnect (hook_document_handle); if (main_window == null) { message ("No MainWindow was set"); return; @@ -159,85 +155,66 @@ public class Scratch.Plugins.GVlsCompletion : Peas.ExtensionBase, Peas.Activatab foreach (Services.Document doc in docview.docs) { var view = doc.source_view; - var prov = view.get_data ("gvls-provider"); - if (prov == null) return; + var gvls_provider = view.get_data ("gvls-provider"); + if (gvls_provider == null) { + return; + } + try { - view.get_completion ().remove_provider (prov); + view.get_completion ().remove_provider (gvls_provider); } catch (GLib.Error e) { warning (_("Error deactivating GVls Plugin: %s"), e.message); } } - var client = plugins.get_data ("gvls-client"); - if (client != null) { - client.server_shutdown.begin (); + var gvls_client = plugins.get_data ("gvls-client"); + if (gvls_client != null) { + gvls_client.server_shutdown.begin (); } - if (timed_id != -1) { - var source = MainContext.@default ().find_source_by_id (timed_id); - if (source != null) { - source.destroy (); - } + if (timed_id != 0) { + Source.remove (timed_id); } } - public void update_state () { - } - private bool push_document_changes () { - if (lsp_sync_in_progress) { - return true; - } - var client = plugins.get_data ("gvls-client"); - if (client == null) { - return true; - } - - if (main_window == null) { - message ("No MainWindow was set"); - return true; - } + public void update_state () {} - var doc = main_window.get_current_document (); - if (doc == null) { - return true; - } - - var view = doc.source_view; - if (view == null) { - return true; - } - - if (!(view is Scratch.Widgets.DocumentView)) { - return true; - } - - var file = doc.file; - if (file == null) { - return true; - } - - var chgs = view.get_data ("gvls-changes"); - if (chgs == null) { - return true; - } - - if (chgs.get_n_items () != 0) { - GVls.Container current_changes = chgs; - chgs = new GVls.ContainerHashList.for_type (typeof (TextDocumentContentChangeEventInfo)); - view.set_data ("gvls-changes", chgs); - lsp_sync_in_progress = true; - var uri = file.get_uri (); - client.document_change.begin (uri, current_changes, (obj, res)=>{ - try { - client.document_change.end (res); - lsp_sync_in_progress = false; - } catch (GLib.Error e) { - warning ("Error while pushing changes to the server: %s", e.message); - } - }); - } - - return true; + private bool push_document_changes () { + if (lsp_sync_in_progress) { + return true; + } + var gvls_client = plugins.get_data ("gvls-client"); + if (gvls_client == null) { + return true; + } + + var doc = main_window.get_current_document (); + if (doc == null) { + return Source.CONTINUE; + } + var view = doc.source_view; + var file = doc.file; + var gvls_changes = view.get_data ("gvls-changes"); + if (gvls_changes == null) { + return true; + } + + if (gvls_changes.get_n_items () != 0) { + GVls.Container current_changes = gvls_changes; + gvls_changes = new GVls.ContainerHashList.for_type (typeof (GVls.TextDocumentContentChangeEventInfo)); + view.set_data ("gvls-changes", gvls_changes); + lsp_sync_in_progress = true; + gvls_client.document_change.begin (file.get_uri (), current_changes, (obj, res)=>{ + try { + gvls_client.document_change.end (res); + lsp_sync_in_progress = false; + } catch (GLib.Error e) { + warning ("Error while pushing changes to the server: %s", e.message); + } + }); + } + + return Source.CONTINUE; } } diff --git a/plugins/gvls/meson.build b/plugins/gvls/meson.build index b384a6b622..5399e45403 100644 --- a/plugins/gvls/meson.build +++ b/plugins/gvls/meson.build @@ -1,25 +1,27 @@ module_name = 'gvls-code' gvls_plugin_sources = files([ - 'gvls-code-plugin.vala' - ]) + 'gvls-code-plugin.vala' + ]) gvls_install_dir=join_paths(pluginsdir, module_name) install_data('gvls-code.plugin', install_dir: gvls_install_dir) plugin_deps = [ - gvls_dep, - codecore_dep, - ] + gvls_dep, + gvlsp_dep, + gvlsui_dep, + codecore_dep, + ] shared_module(module_name, gvls_plugin_sources, - dependencies: plugin_deps, - install: true, - install_dir: gvls_install_dir, - vala_args: [ - '--target-glib=2.52', - ] + dependencies: plugin_deps, + install: true, + install_dir: gvls_install_dir, + vala_args: [ + '--target-glib=2.52', + ] ) custom_target(module_name + '.plugin_merge', diff --git a/plugins/meson.build b/plugins/meson.build index 51b4fdc368..51a2e904f2 100644 --- a/plugins/meson.build +++ b/plugins/meson.build @@ -14,7 +14,9 @@ subdir('terminal') subdir('vim-emulation') subdir('word-completion') -gvls_dep = dependency ('gvlsui-0.16', required: false) -if gvls_dep.found() +gvls_dep = dependency ('gvls-20', version: '>=20.0', required: false) +gvlsp_dep = dependency ('gvlsp-20', version: '>=19.0', required: false) +gvlsui_dep = dependency ('gvlsui-20', version: '>=20.0', required: false) +if gvls_dep.found() and gvlsp_dep.found() and gvlsui_dep.found() subdir('gvls') endif From 024c0c4c81ab5b38b661c99068845be5160a7e43 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Tue, 8 Jun 2021 17:49:38 +0100 Subject: [PATCH 17/23] Fix indentation and lint --- plugins/gvls/gvls-code-plugin.vala | 68 +++++++++++++++--------------- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/plugins/gvls/gvls-code-plugin.vala b/plugins/gvls/gvls-code-plugin.vala index fb1af8ac6e..e2040f9543 100644 --- a/plugins/gvls/gvls-code-plugin.vala +++ b/plugins/gvls/gvls-code-plugin.vala @@ -180,39 +180,41 @@ public class Scratch.Plugins.GVlsCompletion : Peas.ExtensionBase, Peas.Activatab public void update_state () {} private bool push_document_changes () { - if (lsp_sync_in_progress) { - return true; - } - var gvls_client = plugins.get_data ("gvls-client"); - if (gvls_client == null) { - return true; - } - - var doc = main_window.get_current_document (); - if (doc == null) { - return Source.CONTINUE; - } - var view = doc.source_view; - var file = doc.file; - var gvls_changes = view.get_data ("gvls-changes"); - if (gvls_changes == null) { - return true; - } - - if (gvls_changes.get_n_items () != 0) { - GVls.Container current_changes = gvls_changes; - gvls_changes = new GVls.ContainerHashList.for_type (typeof (GVls.TextDocumentContentChangeEventInfo)); - view.set_data ("gvls-changes", gvls_changes); - lsp_sync_in_progress = true; - gvls_client.document_change.begin (file.get_uri (), current_changes, (obj, res)=>{ - try { - gvls_client.document_change.end (res); - lsp_sync_in_progress = false; - } catch (GLib.Error e) { - warning ("Error while pushing changes to the server: %s", e.message); - } - }); - } + if (lsp_sync_in_progress) { + return true; + } + + var gvls_client = plugins.get_data ("gvls-client"); + if (gvls_client == null) { + return true; + } + + var doc = main_window.get_current_document (); + if (doc == null) { + return Source.CONTINUE; + } + + var view = doc.source_view; + var file = doc.file; + var gvls_changes = view.get_data ("gvls-changes"); + if (gvls_changes == null) { + return true; + } + + if (gvls_changes.get_n_items () != 0) { + GVls.Container current_changes = gvls_changes; + gvls_changes = new GVls.ContainerHashList.for_type (typeof (GVls.TextDocumentContentChangeEventInfo)); + view.set_data ("gvls-changes", gvls_changes); + lsp_sync_in_progress = true; + gvls_client.document_change.begin (file.get_uri (), current_changes, (obj, res) => { + try { + gvls_client.document_change.end (res); + lsp_sync_in_progress = false; + } catch (GLib.Error e) { + warning ("Error while pushing changes to the server: %s", e.message); + } + }); + } return Source.CONTINUE; } From 3447e766c597a0f6c56cca4ba5ae80a08ad26edf Mon Sep 17 00:00:00 2001 From: Daniel Espinosa Ortiz Date: Tue, 8 Jun 2021 22:53:50 -0500 Subject: [PATCH 18/23] GVls: Set to use 19 version for plugin --- plugins/gvls/gvls-code-plugin.vala | 10 +--------- plugins/meson.build | 6 +++--- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/plugins/gvls/gvls-code-plugin.vala b/plugins/gvls/gvls-code-plugin.vala index e2040f9543..135f12f835 100644 --- a/plugins/gvls/gvls-code-plugin.vala +++ b/plugins/gvls/gvls-code-plugin.vala @@ -40,15 +40,7 @@ public class Scratch.Plugins.GVlsCompletion : Peas.ExtensionBase, Peas.Activatab public void activate () { plugins = (Scratch.Services.Interface) object; - GVlsp.ServerInetLocal server = new GVlsp.ServerInetLocal (); - - server.run (); - server.target_manager.add_default_vapi_dirs (); - - plugins.set_data ("gvls-server", server); - - GVls.Client client = new GVlsp.ClientInetLocal (); - plugins.set_data ("gvls-client", client); + //plugins.set_data ("gvls-client", client); timed_id = Timeout.add (1000, push_document_changes); diff --git a/plugins/meson.build b/plugins/meson.build index 51a2e904f2..f8ca6eabd3 100644 --- a/plugins/meson.build +++ b/plugins/meson.build @@ -14,9 +14,9 @@ subdir('terminal') subdir('vim-emulation') subdir('word-completion') -gvls_dep = dependency ('gvls-20', version: '>=20.0', required: false) -gvlsp_dep = dependency ('gvlsp-20', version: '>=19.0', required: false) -gvlsui_dep = dependency ('gvlsui-20', version: '>=20.0', required: false) +gvls_dep = dependency ('gvls-19', version: '>=19.0', required: false) +gvlsp_dep = dependency ('gvlsp-19', version: '>=19.0', required: false) +gvlsui_dep = dependency ('gvlsui-19', version: '>=19.0', required: false) if gvls_dep.found() and gvlsp_dep.found() and gvlsui_dep.found() subdir('gvls') endif From 9511ab7e94881d4c0b6979272d43a27a1c401d73 Mon Sep 17 00:00:00 2001 From: Daniel Espinosa Ortiz Date: Thu, 10 Jun 2021 02:16:47 -0500 Subject: [PATCH 19/23] GVls: ported to new GVlsui.SourceViewInitialize Code simplification while using GVlsui.SourceViewInitialize to setup Code's SourceView to use LSP completion --- plugins/gvls/gvls-code-plugin.vala | 172 +++++------------------------ 1 file changed, 25 insertions(+), 147 deletions(-) diff --git a/plugins/gvls/gvls-code-plugin.vala b/plugins/gvls/gvls-code-plugin.vala index 135f12f835..b97eb47b2f 100644 --- a/plugins/gvls/gvls-code-plugin.vala +++ b/plugins/gvls/gvls-code-plugin.vala @@ -22,8 +22,6 @@ public class Scratch.Plugins.GVlsCompletion : Peas.ExtensionBase, Peas.Activatab private MainWindow main_window; private ulong hook_document_handle = 0; private uint timed_id = 0; - private bool lsp_sync_in_progress = false; - private bool initiated = false; public Object object { owned get; construct; } Scratch.Services.Interface plugins; @@ -40,99 +38,33 @@ public class Scratch.Plugins.GVlsCompletion : Peas.ExtensionBase, Peas.Activatab public void activate () { plugins = (Scratch.Services.Interface) object; - //plugins.set_data ("gvls-client", client); - - timed_id = Timeout.add (1000, push_document_changes); - plugins.hook_window.connect ((w) => { this.main_window = w; }); hook_document_handle = plugins.hook_document.connect ((doc)=>{ - try { - var gvls_client = plugins.get_data ("gvls-client"); - if (gvls_client == null) { - return; - } - var file = doc.file; - if (file == null) { - return; - } - if (!initiated) { - gvls_client.initialize.begin (file.get_uri (), (obj, res)=>{ - try { - gvls_client.initialize.end (res); - initiated = true; - init_doc (doc, gvls_client); - } catch (GLib.Error e) { - warning ("Error setting completion provider: %s", e.message); - } - }); - } else { - init_doc (doc, gvls_client); - } - } catch (GLib.Error e) { - warning ("Error setting completion provider: %s", e.message); + if (doc.source_view.project == null) { + return; } - }); - } - - private void init_doc (Scratch.Services.Document doc, GVls.Client client) throws GLib.Error { - var gvls_client = plugins.get_data ("gvls-client"); - if (gvls_client == null) { - return; - } - - var view = doc.source_view; - var file = doc.file; - if (file == null) { - return; - } - var gvls_provider = view.get_data ("gvls-provider"); - if (gvls_provider != null) { - return; - } - - var completion_provider = new GVlsui.CompletionProvider (); - // completion_provider.client = client; GVlsui.CompletionProvider does not have property "client" in version 20 - - view.get_completion ().add_provider (completion_provider); - view.set_data ("gvls-provider", completion_provider); - view.set_data ("gvls-view-dirty", true); - GVls.Container changes = new GVls.ContainerHashList.for_type (typeof (GVls.TextDocumentContentChangeEventInfo)); - view.set_data ("gvls-changes", changes); - var buffer = view.get_buffer (); - buffer.delete_range.connect ((start, end)=>{ - var gvls_changes = view.get_data ("gvls-changes"); - var start_pos = new GVls.SourcePosition.from_values (start.get_line (), start.get_line_offset ()); - var end_pos = new GVls.SourcePosition.from_values (end.get_line (), end.get_line_offset ()); - var content_change = new GVls.TextDocumentContentChangeEventInfo (); - content_change.range.start = start_pos; - content_change.range.end = end_pos; - content_change.text = null; - gvls_changes.add (content_change); - }); - - buffer.insert_text.connect ((ref pos, _text)=>{ - var gvls_changes = view.get_data ("gvls-changes"); - var start_pos = new GVls.SourcePosition.from_values (pos.get_line (), pos.get_line_offset ()); - var end_pos = new GVls.SourcePosition.from_values (pos.get_line (), pos.get_line_offset ()); - var content_change = new GVls.TextDocumentContentChangeEventInfo (); - content_change.range.start = start_pos; - content_change.range.end = end_pos; - content_change.text = _text; - gvls_changes.add (content_change); - }); - - client.document_open.begin (file.get_uri (), buffer.text, (obj, res)=>{ - try { - client.document_open.end (res); - } catch (GLib.Error e) { - warning ("Error while send didOpen notification: %s", e.message); + var gvls_manager = doc.source_view.project.get_data ("gvls-manager"); + if (gvls_manager == null) { + GLib.File f = GLib.File.new_for_path (doc.source_view.project.top_level_path); + gvls_manager = new GVlsui.ProjectManager.for_meson (f); + doc.source_view.project.set_data ("gvls-manager", gvls_manager); + gvls_manager.manager.initialize_stdio.begin ((obj, res)=>{ + try { + gvls_manager.manager.initialize_stdio.end (res); + } catch (GLib.Error e) { + warning ("Error Opening File: %s", e.message); + } + }); } + gvls_manager.set_completion_provider (doc.source_view, doc.file); + gvls_manager.open_document (doc.source_view); }); } + public void deactivate () { plugins.disconnect (hook_document_handle); if (main_window == null) { @@ -140,76 +72,22 @@ public class Scratch.Plugins.GVlsCompletion : Peas.ExtensionBase, Peas.Activatab return; } - var docview = main_window.get_current_view (); - if (!(docview is Scratch.Widgets.DocumentView)) { - return; - } - - foreach (Services.Document doc in docview.docs) { - var view = doc.source_view; - var gvls_provider = view.get_data ("gvls-provider"); - if (gvls_provider == null) { - return; + foreach (Services.Document doc in main_window.document_view.docs) { + var p = doc.source_view.project; + var gvls_manager = p.get_data ("gvls-manager"); + if (gvls_manager == null) { + continue; } - try { - view.get_completion ().remove_provider (gvls_provider); - } catch (GLib.Error e) { - warning (_("Error deactivating GVls Plugin: %s"), e.message); - } - } + gvls_manager.manager.client.server_exit.begin (()=>{ + p.set_data ("gvls-manager", null); + }); - var gvls_client = plugins.get_data ("gvls-client"); - if (gvls_client != null) { - gvls_client.server_shutdown.begin (); } - if (timed_id != 0) { - Source.remove (timed_id); - } } public void update_state () {} - - private bool push_document_changes () { - if (lsp_sync_in_progress) { - return true; - } - - var gvls_client = plugins.get_data ("gvls-client"); - if (gvls_client == null) { - return true; - } - - var doc = main_window.get_current_document (); - if (doc == null) { - return Source.CONTINUE; - } - - var view = doc.source_view; - var file = doc.file; - var gvls_changes = view.get_data ("gvls-changes"); - if (gvls_changes == null) { - return true; - } - - if (gvls_changes.get_n_items () != 0) { - GVls.Container current_changes = gvls_changes; - gvls_changes = new GVls.ContainerHashList.for_type (typeof (GVls.TextDocumentContentChangeEventInfo)); - view.set_data ("gvls-changes", gvls_changes); - lsp_sync_in_progress = true; - gvls_client.document_change.begin (file.get_uri (), current_changes, (obj, res) => { - try { - gvls_client.document_change.end (res); - lsp_sync_in_progress = false; - } catch (GLib.Error e) { - warning ("Error while pushing changes to the server: %s", e.message); - } - }); - } - - return Source.CONTINUE; - } } [ModuleInit] From 23cb64256851cecd51d12204798b0daf212c6e52 Mon Sep 17 00:00:00 2001 From: Daniel Espinosa Ortiz Date: Thu, 10 Jun 2021 21:13:30 -0500 Subject: [PATCH 20/23] GVls: shoutdown server on exit --- plugins/gvls/gvls-code-plugin.vala | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/gvls/gvls-code-plugin.vala b/plugins/gvls/gvls-code-plugin.vala index b97eb47b2f..b52fa4e8b6 100644 --- a/plugins/gvls/gvls-code-plugin.vala +++ b/plugins/gvls/gvls-code-plugin.vala @@ -48,7 +48,7 @@ public class Scratch.Plugins.GVlsCompletion : Peas.ExtensionBase, Peas.Activatab var gvls_manager = doc.source_view.project.get_data ("gvls-manager"); if (gvls_manager == null) { - GLib.File f = GLib.File.new_for_path (doc.source_view.project.top_level_path); + GLib.File f = doc.source_view.project.file.file; gvls_manager = new GVlsui.ProjectManager.for_meson (f); doc.source_view.project.set_data ("gvls-manager", gvls_manager); gvls_manager.manager.initialize_stdio.begin ((obj, res)=>{ @@ -61,6 +61,10 @@ public class Scratch.Plugins.GVlsCompletion : Peas.ExtensionBase, Peas.Activatab } gvls_manager.set_completion_provider (doc.source_view, doc.file); gvls_manager.open_document (doc.source_view); + main_window.destroy.connect (()=>{ + gvls_manager.manager.client.server_exit.begin (); + }); + }); } From 6e9963473e8d557f91bc2f89af26c8403a31dfde Mon Sep 17 00:00:00 2001 From: Daniel Espinosa Ortiz Date: Thu, 10 Jun 2021 21:28:13 -0500 Subject: [PATCH 21/23] GVls: fix race condition for server initialization --- plugins/gvls/gvls-code-plugin.vala | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/plugins/gvls/gvls-code-plugin.vala b/plugins/gvls/gvls-code-plugin.vala index b52fa4e8b6..fa4f06f31c 100644 --- a/plugins/gvls/gvls-code-plugin.vala +++ b/plugins/gvls/gvls-code-plugin.vala @@ -53,18 +53,25 @@ public class Scratch.Plugins.GVlsCompletion : Peas.ExtensionBase, Peas.Activatab doc.source_view.project.set_data ("gvls-manager", gvls_manager); gvls_manager.manager.initialize_stdio.begin ((obj, res)=>{ try { - gvls_manager.manager.initialize_stdio.end (res); + gvls_manager.manager.initialize_stdio.end (res); + gvls_manager.set_completion_provider (doc.source_view, doc.file); + gvls_manager.open_document (doc.source_view); + + main_window.destroy.connect (()=>{ + gvls_manager.manager.client.server_exit.begin (); + }); } catch (GLib.Error e) { warning ("Error Opening File: %s", e.message); } }); - } - gvls_manager.set_completion_provider (doc.source_view, doc.file); - gvls_manager.open_document (doc.source_view); - main_window.destroy.connect (()=>{ - gvls_manager.manager.client.server_exit.begin (); - }); + } else { + gvls_manager.set_completion_provider (doc.source_view, doc.file); + gvls_manager.open_document (doc.source_view); + main_window.destroy.connect (()=>{ + gvls_manager.manager.client.server_exit.begin (); + }); + } }); } From 2b550ad725eff37c86467146f4183ac3bcc4183e Mon Sep 17 00:00:00 2001 From: Daniel Espinosa Ortiz Date: Sun, 13 Jun 2021 15:48:00 -0500 Subject: [PATCH 22/23] GVls: Fix recurrent sourceview intialization Added signals on MainWindow for open folders and documents, to be used by GVls initialization and sourceview setup --- plugins/gvls/gvls-code-plugin.vala | 38 ++++++++++++++++++------------ src/FolderManager/FileView.vala | 15 +++++++----- src/MainWindow.vala | 7 +++++- 3 files changed, 38 insertions(+), 22 deletions(-) diff --git a/plugins/gvls/gvls-code-plugin.vala b/plugins/gvls/gvls-code-plugin.vala index fa4f06f31c..ed1de4cb65 100644 --- a/plugins/gvls/gvls-code-plugin.vala +++ b/plugins/gvls/gvls-code-plugin.vala @@ -20,28 +20,36 @@ public class Scratch.Plugins.GVlsCompletion : Peas.ExtensionBase, Peas.Activatable { private MainWindow main_window; - private ulong hook_document_handle = 0; - private uint timed_id = 0; public Object object { owned get; construct; } Scratch.Services.Interface plugins; - ~GVlsCompletion () { - if (timed_id != 0) { - var source = MainContext.@default ().find_source_by_id (timed_id); - if (source != null) { - source.destroy (); - } - } - } - public void activate () { plugins = (Scratch.Services.Interface) object; + this.main_window = plugins.manager.window; + + main_window.folder_opened.connect ((project)=>{ + var gvls_manager = project.get_data ("gvls-manager"); + if (gvls_manager == null) { + GLib.File f = project.file.file; + gvls_manager = new GVlsui.ProjectManager.for_meson (f); + project.set_data ("gvls-manager", gvls_manager); + gvls_manager.manager.initialize_stdio.begin ((obj, res)=>{ + try { + gvls_manager.manager.initialize_stdio.end (res); + debug ("gvls-plugin: Started GVls server"); - plugins.hook_window.connect ((w) => { - this.main_window = w; + main_window.destroy.connect (()=>{ + gvls_manager.manager.client.server_exit.begin (); + }); + } catch (GLib.Error e) { + warning ("Error Opening File: %s", e.message); + } + }); + } }); - hook_document_handle = plugins.hook_document.connect ((doc)=>{ + + main_window.document_opened.connect ((doc)=>{ if (doc.source_view.project == null) { return; } @@ -54,6 +62,7 @@ public class Scratch.Plugins.GVlsCompletion : Peas.ExtensionBase, Peas.Activatab gvls_manager.manager.initialize_stdio.begin ((obj, res)=>{ try { gvls_manager.manager.initialize_stdio.end (res); + debug ("gvls-plugin: Started GVls server"); gvls_manager.set_completion_provider (doc.source_view, doc.file); gvls_manager.open_document (doc.source_view); @@ -77,7 +86,6 @@ public class Scratch.Plugins.GVlsCompletion : Peas.ExtensionBase, Peas.Activatab public void deactivate () { - plugins.disconnect (hook_document_handle); if (main_window == null) { message ("No MainWindow was set"); return; diff --git a/src/FolderManager/FileView.vala b/src/FolderManager/FileView.vala index fd8fdcd809..2b116fd3b2 100644 --- a/src/FolderManager/FileView.vala +++ b/src/FolderManager/FileView.vala @@ -63,17 +63,18 @@ namespace Scratch.FolderManager { } } - public void open_folder (File folder) { + public ProjectFolderItem? open_folder (File folder) { if (is_open (folder)) { var existing = find_path (root, folder.path); if (existing is Granite.Widgets.SourceList.ExpandableItem) { ((Granite.Widgets.SourceList.ExpandableItem)existing).expanded = true; + return (Scratch.FolderManager.ProjectFolderItem) existing; } - return; + return null; } - add_folder (folder, true); + return add_folder (folder, true); } public void collapse_all () { @@ -196,13 +197,13 @@ namespace Scratch.FolderManager { } } - private void add_folder (File folder, bool expand) { + private ProjectFolderItem? add_folder (File folder, bool expand) { if (is_open (folder)) { warning ("Folder '%s' is already open.", folder.path); - return; + return null; } else if (!folder.is_valid_directory (true)) { // Allow hidden top-level folders warning ("Cannot open invalid directory."); - return; + return null; } var folder_root = new ProjectFolderItem (folder, this); // Constructor adds project to GitManager @@ -229,6 +230,8 @@ namespace Scratch.FolderManager { }); write_settings (); + + return folder_root; } private bool is_open (File folder) { diff --git a/src/MainWindow.vala b/src/MainWindow.vala index c04d14142c..48ce62e867 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -20,6 +20,9 @@ namespace Scratch { public class MainWindow : Hdy.Window { + + public signal void document_opened (Scratch.Services.Document doc); + public signal void folder_opened (Scratch.FolderManager.ProjectFolderItem? project); public const int FONT_SIZE_MAX = 72; public const int FONT_SIZE_MIN = 7; private const uint MAX_SEARCH_TEXT_LENGTH = 255; @@ -552,13 +555,15 @@ namespace Scratch { public void open_folder (File folder) { var foldermanager_file = new FolderManager.File (folder.get_path ()); - folder_manager_view.open_folder (foldermanager_file); + Scratch.FolderManager.ProjectFolderItem? project = folder_manager_view.open_folder (foldermanager_file); + folder_opened (project); } public void open_document (Scratch.Services.Document doc, bool focus = true, int cursor_position = 0) { FolderManager.ProjectFolderItem? project = folder_manager_view.get_project_for_file (doc.file); doc.source_view.project = project; document_view.open_document (doc, focus, cursor_position); + document_opened (doc); } // Close a document From f26f774a892508defd18e882f326c29494de5ce1 Mon Sep 17 00:00:00 2001 From: Daniel Espinosa Ortiz Date: Sat, 26 Jun 2021 23:31:35 -0500 Subject: [PATCH 23/23] GVls: Fix plugin deactivation --- plugins/gvls/gvls-code-plugin.vala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/gvls/gvls-code-plugin.vala b/plugins/gvls/gvls-code-plugin.vala index ed1de4cb65..eb01c02e4b 100644 --- a/plugins/gvls/gvls-code-plugin.vala +++ b/plugins/gvls/gvls-code-plugin.vala @@ -93,13 +93,13 @@ public class Scratch.Plugins.GVlsCompletion : Peas.ExtensionBase, Peas.Activatab foreach (Services.Document doc in main_window.document_view.docs) { var p = doc.source_view.project; - var gvls_manager = p.get_data ("gvls-manager"); + var gvls_manager = p.get_data ("gvls-manager"); if (gvls_manager == null) { continue; } gvls_manager.manager.client.server_exit.begin (()=>{ - p.set_data ("gvls-manager", null); + p.set_data ("gvls-manager", null); }); }