[gnome-builder: 131/139] vala-pack: port to libide-foundry
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder: 131/139] vala-pack: port to libide-foundry
- Date: Thu, 10 Jan 2019 04:28:20 +0000 (UTC)
commit fa835df6cf1809c39c9326da8b86f90113d85356
Author: Christian Hergert <chergert redhat com>
Date: Wed Jan 9 17:43:30 2019 -0800
vala-pack: port to libide-foundry
This ports the vala plugin to the new code and foundry components. Now
that we only have a single executable, vala must stay a shared library
so that the gir->vapi generation can happen first.
src/plugins/vala-pack/ide-vala-code-indexer.vala | 8 +--
.../vala-pack/ide-vala-completion-provider.vala | 11 ++--
.../vala-pack/ide-vala-diagnostic-provider.vala | 15 +++---
src/plugins/vala-pack/ide-vala-index.vala | 25 ++-------
src/plugins/vala-pack/ide-vala-service.vala | 16 +++---
src/plugins/vala-pack/ide-vala-source-file.vala | 39 +++++++-------
.../vala-pack/ide-vala-symbol-resolver.vala | 34 ++++++------
src/plugins/vala-pack/ide-vala-symbol-tree.vala | 9 ++--
src/plugins/vala-pack/meson.build | 62 +++++++++++-----------
src/plugins/vala-pack/vala-pack-plugin.vala | 1 -
src/plugins/vala-pack/vala-pack.plugin | 17 +++---
11 files changed, 112 insertions(+), 125 deletions(-)
---
diff --git a/src/plugins/vala-pack/ide-vala-code-indexer.vala
b/src/plugins/vala-pack/ide-vala-code-indexer.vala
index ba24c64aa..0ad3ea95b 100644
--- a/src/plugins/vala-pack/ide-vala-code-indexer.vala
+++ b/src/plugins/vala-pack/ide-vala-code-indexer.vala
@@ -34,7 +34,7 @@ namespace Ide
throws GLib.Error
{
var context = this.get_context ();
- var service = (Ide.ValaService)context.get_service_typed (typeof (Ide.ValaService));
+ var service = Ide.ValaService.from_context (context);
var index = service.index;
var tree = index.get_symbol_tree_sync (file, cancellable);
@@ -55,18 +55,18 @@ namespace Ide
return ret;
}
- public async string generate_key_async (Ide.SourceLocation location,
+ public async string generate_key_async (Ide.Location location,
string[]? build_flags,
GLib.Cancellable? cancellable)
throws GLib.Error
{
var context = this.get_context ();
- var service = (Ide.ValaService)context.get_service_typed (typeof (Ide.ValaService));
+ var service = Ide.ValaService.from_context (context);
var index = service.index;
var file = location.get_file ();
var line = location.get_line () + 1;
var column = location.get_line_offset () + 1;
- Vala.Symbol? symbol = yield index.find_symbol_at (file.get_file (), (int)line,
(int)column);
+ Vala.Symbol? symbol = yield index.find_symbol_at (file, (int)line, (int)column);
if (symbol == null)
throw new GLib.IOError.FAILED ("failed to locate symbol");
diff --git a/src/plugins/vala-pack/ide-vala-completion-provider.vala
b/src/plugins/vala-pack/ide-vala-completion-provider.vala
index 2174f0306..510c81841 100644
--- a/src/plugins/vala-pack/ide-vala-completion-provider.vala
+++ b/src/plugins/vala-pack/ide-vala-completion-provider.vala
@@ -29,7 +29,7 @@ namespace Ide
public void load (Ide.Context context)
{
- this.service = context.get_service_typed (typeof (Ide.ValaService)) as
Ide.ValaService;
+ this.service = Ide.ValaService.from_context (context);
}
public bool is_trigger (Gtk.TextIter iter, unichar ch)
@@ -61,11 +61,12 @@ namespace Ide
var file = buffer.get_file ();
Gtk.TextIter iter, begin;
- if (file.is_temporary) {
+ if (buffer.is_temporary) {
throw new GLib.IOError.NOT_SUPPORTED ("Cannot complete on temporary files");
}
- buffer.sync_to_unsaved_files ();
+ /* force buffer sync */
+ buffer.dup_content ();
context.get_bounds (out iter, null);
@@ -77,7 +78,7 @@ namespace Ide
var line_offset = iter.get_line_offset ();
var index = this.service.index;
- var unsaved_files = this.get_context ().get_unsaved_files ();
+ var unsaved_files = Ide.UnsavedFiles.from_context (this.get_context ());
/* make a copy for threaded access */
var unsaved_files_copy = unsaved_files.to_array ();
@@ -85,7 +86,7 @@ namespace Ide
Ide.ThreadPool.push (Ide.ThreadPoolKind.COMPILER, () => {
int res_line = -1;
int res_column = -1;
- results = index.code_complete (file.file,
+ results = index.code_complete (file,
line + 1,
line_offset + 1,
line_text,
diff --git a/src/plugins/vala-pack/ide-vala-diagnostic-provider.vala
b/src/plugins/vala-pack/ide-vala-diagnostic-provider.vala
index de7f0bbbe..7771c34dd 100644
--- a/src/plugins/vala-pack/ide-vala-diagnostic-provider.vala
+++ b/src/plugins/vala-pack/ide-vala-diagnostic-provider.vala
@@ -24,17 +24,20 @@ namespace Ide
{
public class ValaDiagnosticProvider: Ide.Object, Ide.DiagnosticProvider
{
- public async Ide.Diagnostics? diagnose_async (Ide.File file,
- Ide.Buffer buffer,
- GLib.Cancellable? cancellable)
+ public async Ide.Diagnostics diagnose_async (GLib.File file,
+ GLib.Bytes? contents,
+ string? language_id,
+ GLib.Cancellable? cancellable)
throws GLib.Error
{
- var service = (Ide.ValaService)get_context ().get_service_typed (typeof
(Ide.ValaService));
- yield service.index.parse_file (file.file, get_context ().unsaved_files, cancellable);
- var results = yield service.index.get_diagnostics (file.file, cancellable);
+ var service = Ide.ValaService.from_context (this.get_context ());
+ var unsaved_files = Ide.UnsavedFiles.from_context (this.get_context ());
+ yield service.index.parse_file (file, unsaved_files, cancellable);
+ var results = yield service.index.get_diagnostics (file, cancellable);
return results;
}
public void load () {}
+ public void unload () {}
}
}
diff --git a/src/plugins/vala-pack/ide-vala-index.vala b/src/plugins/vala-pack/ide-vala-index.vala
index 14f5ec00f..f9b8bd82d 100644
--- a/src/plugins/vala-pack/ide-vala-index.vala
+++ b/src/plugins/vala-pack/ide-vala-index.vala
@@ -41,8 +41,7 @@ namespace Ide
public ValaIndex (Ide.Context context)
{
- var vcs = context.get_vcs();
- var workdir = vcs.get_working_directory();
+ var workdir = context.ref_workdir ();
this.source_files = new HashMap<GLib.File,Ide.ValaSourceFile> (GLib.File.hash,
(GLib.EqualFunc)GLib.File.equal);
@@ -83,20 +82,6 @@ namespace Ide
this.code_context.run_output = false;
- int minor = 36;
- var tokens = Config.VALA_VERSION.split(".", 2);
- if (tokens[1] != null) {
- minor = int.parse(tokens[1]);
- }
-
- for (var i = 2; i <= minor; i += 2) {
- this.code_context.add_define ("VALA_0_%d".printf (i));
- }
-
- for (var i = 16; i < GLib.Version.minor; i+= 2) {
- this.code_context.add_define ("GLIB_2_%d".printf (i));
- }
-
this.code_context.vapi_directories = {};
/* $prefix/share/vala-0.32/vapi */
@@ -246,8 +231,7 @@ namespace Ide
}
else if (param.has_suffix (".vapi")) {
if (!GLib.Path.is_absolute (param)) {
- var vcs = this.context.get_vcs ();
- var workdir = vcs.get_working_directory ();
+ var workdir = context.ref_workdir ();
var child = workdir.get_child (param);
this.add_file (child);
} else {
@@ -268,11 +252,10 @@ namespace Ide
async void update_build_flags (GLib.File file,
GLib.Cancellable? cancellable)
{
- var ifile = new Ide.File (this.context, file);
- var build_system = this.context.get_build_system ();
+ var build_system = Ide.BuildSystem.from_context (this.context);
try {
- var flags = yield build_system.get_build_flags_async (ifile, cancellable);
+ var flags = yield build_system.get_build_flags_async (file, cancellable);
load_build_flags (flags);
} catch (GLib.Error err) {
warning ("%s", err.message);
diff --git a/src/plugins/vala-pack/ide-vala-service.vala b/src/plugins/vala-pack/ide-vala-service.vala
index c0cb4ee05..1223abf6c 100644
--- a/src/plugins/vala-pack/ide-vala-service.vala
+++ b/src/plugins/vala-pack/ide-vala-service.vala
@@ -22,10 +22,14 @@ using Vala;
namespace Ide
{
- public class ValaService: Ide.Object, Ide.Service
+ public class ValaService: Ide.Object
{
Ide.ValaIndex _index;
+ public static Ide.ValaService from_context (Ide.Context context) {
+ return (Ide.ValaService)context.ensure_child_typed (typeof (ValaService));
+ }
+
public unowned string get_name () {
return typeof (Ide.ValaService).name ();
}
@@ -36,10 +40,10 @@ namespace Ide
this._index = new Ide.ValaIndex (this.get_context ());
Ide.ThreadPool.push (Ide.ThreadPoolKind.INDEXER, () => {
- Ide.Vcs vcs = this.get_context ().get_vcs ();
+ var workdir = this.ref_context ().ref_workdir ();
var files = new ArrayList<GLib.File> ();
- load_directory (vcs.get_working_directory (), null, files);
+ load_directory (workdir, null, files);
if (files.size > 0) {
this._index.add_files.begin (files, null, () => {
@@ -53,12 +57,6 @@ namespace Ide
}
}
- public void start () {
- }
-
- public void stop () {
- }
-
public void load_directory (GLib.File directory,
GLib.Cancellable? cancellable,
ArrayList<GLib.File> files)
diff --git a/src/plugins/vala-pack/ide-vala-source-file.vala b/src/plugins/vala-pack/ide-vala-source-file.vala
index 9572fb7ab..f82d580c5 100644
--- a/src/plugins/vala-pack/ide-vala-source-file.vala
+++ b/src/plugins/vala-pack/ide-vala-source-file.vala
@@ -45,7 +45,7 @@ namespace Ide
public class ValaSourceFile: Vala.SourceFile
{
ArrayList<Ide.Diagnostic> diagnostics;
- internal Ide.File file;
+ internal GLib.File file;
public ValaSourceFile (Vala.CodeContext context,
Vala.SourceFileType type,
@@ -55,7 +55,7 @@ namespace Ide
{
base (context, type, filename, content, cmdline);
- this.file = new Ide.File (null, GLib.File.new_for_path (filename));
+ this.file = GLib.File.new_for_path (filename);
this.diagnostics = new ArrayList<Ide.Diagnostic> ();
this.add_default_namespace ();
@@ -66,12 +66,18 @@ namespace Ide
public GLib.File get_file ()
{
- return this.file.file;
+ return this.file;
}
public void reset ()
{
- this.diagnostics.clear ();
+ /* clear diagnostics on main thread */
+ var old_diags = this.diagnostics;
+ this.diagnostics = new ArrayList<Ide.Diagnostic> ();
+ GLib.Idle.add(() => {
+ old_diags.clear ();
+ return false;
+ });
/* Copy the node list since we will be mutating while iterating */
var copy = new ArrayList<Vala.CodeNode> ();
@@ -101,9 +107,8 @@ namespace Ide
public void sync (GenericArray<Ide.UnsavedFile> unsaved_files)
{
- var gfile = this.file.file;
unsaved_files.foreach((unsaved_file) => {
- if (unsaved_file.get_file ().equal (gfile)) {
+ if (unsaved_file.get_file ().equal (this.file)) {
var bytes = unsaved_file.get_content ();
if (bytes.get_data () != (uint8[]) this.content) {
@@ -119,27 +124,25 @@ namespace Ide
string message,
Ide.DiagnosticSeverity severity)
{
- var begin = new Ide.SourceLocation (this.file,
- source_reference.begin.line - 1,
- source_reference.begin.column - 1,
- 0);
- var end = new Ide.SourceLocation (this.file,
- source_reference.end.line - 1,
- source_reference.end.column - 1,
- 0);
+ var begin = new Ide.Location (this.file,
+ source_reference.begin.line - 1,
+ source_reference.begin.column - 1);
+ var end = new Ide.Location (this.file,
+ source_reference.end.line - 1,
+ source_reference.end.column - 1);
var diag = new Ide.Diagnostic (severity, message, begin);
- diag.take_range (new Ide.SourceRange (begin, end));
+ diag.take_range (new Ide.Range (begin, end));
this.diagnostics.add (diag);
}
public Ide.Diagnostics? diagnose ()
{
- var ar = new GLib.GenericArray<Ide.Diagnostic> ();
+ var ret = new Ide.Diagnostics ();
foreach (var diag in this.diagnostics) {
- ar.add (diag);
+ ret.add (diag);
}
- return new Ide.Diagnostics (ar);
+ return ret;
}
void add_default_namespace ()
diff --git a/src/plugins/vala-pack/ide-vala-symbol-resolver.vala
b/src/plugins/vala-pack/ide-vala-symbol-resolver.vala
index 4d98a3b1c..2a8febfae 100644
--- a/src/plugins/vala-pack/ide-vala-symbol-resolver.vala
+++ b/src/plugins/vala-pack/ide-vala-symbol-resolver.vala
@@ -25,19 +25,19 @@ namespace Ide
public class ValaSymbolResolver: Ide.Object, Ide.SymbolResolver
{
public async Ide.SymbolTree? get_symbol_tree_async (GLib.File file,
- Ide.Buffer buffer,
+ GLib.Bytes? contents,
GLib.Cancellable? cancellable)
throws GLib.Error
{
var context = this.get_context ();
- var service = (Ide.ValaService)context.get_service_typed (typeof (Ide.ValaService));
+ var service = Ide.ValaService.from_context (context);
var index = service.index;
var symbol_tree = yield index.get_symbol_tree (file, cancellable);
return symbol_tree;
}
- Ide.Symbol? create_symbol (Ide.File file, Vala.Symbol symbol)
+ Ide.Symbol? create_symbol (GLib.File file, Vala.Symbol symbol)
{
var kind = Ide.SymbolKind.NONE;
if (symbol is Vala.Class)
@@ -69,28 +69,27 @@ namespace Ide
var source_reference = symbol.source_reference;
if (source_reference != null) {
- var loc = new Ide.SourceLocation (file,
-
source_reference.begin.line - 1,
-
source_reference.begin.column - 1,
- 0);
- return new Ide.Symbol (symbol.name, kind, flags, loc, loc, loc);
+ var loc = new Ide.Location (file,
+ source_reference.begin.line - 1,
+ source_reference.begin.column - 1);
+ return new Ide.Symbol (symbol.name, kind, flags, loc, loc);
}
return null;
}
- public async Ide.Symbol? lookup_symbol_async (Ide.SourceLocation location,
+ public async Ide.Symbol? lookup_symbol_async (Ide.Location location,
GLib.Cancellable? cancellable)
throws GLib.Error
{
var context = this.get_context ();
- var service = (Ide.ValaService)context.get_service_typed (typeof (Ide.ValaService));
+ var service = Ide.ValaService.from_context (context);
var index = service.index;
var file = location.get_file ();
var line = (int)location.get_line () + 1;
var column = (int)location.get_line_offset () + 1;
- Vala.Symbol? symbol = yield index.find_symbol_at (file.get_file (), line, column);
+ Vala.Symbol? symbol = yield index.find_symbol_at (file, line, column);
if (symbol != null)
return create_symbol (file, symbol);
@@ -117,25 +116,26 @@ namespace Ide
public void load () {}
public void unload () {}
- public async GLib.GenericArray<Ide.SourceRange> find_references_async (Ide.SourceLocation
location,
- GLib.Cancellable?
cancellable)
+ public async GLib.GenericArray<Ide.Range> find_references_async (Ide.Location location,
+ string? language_id,
+ GLib.Cancellable?
cancellable)
throws GLib.Error
{
- return new GLib.GenericArray<Ide.SourceRange> ();
+ return new GLib.GenericArray<Ide.Range> ();
}
- public async Ide.Symbol? find_nearest_scope_async (Ide.SourceLocation location,
+ public async Ide.Symbol? find_nearest_scope_async (Ide.Location location,
GLib.Cancellable? cancellable)
throws GLib.Error
{
var context = this.get_context ();
- var service = (Ide.ValaService)context.get_service_typed (typeof (Ide.ValaService));
+ var service = Ide.ValaService.from_context (context);
var index = service.index;
var file = location.get_file ();
var line = (int)location.get_line () + 1;
var column = (int)location.get_line_offset () + 1;
- var symbol = yield index.find_symbol_at (file.get_file (), line, column);
+ var symbol = yield index.find_symbol_at (file, line, column);
while (symbol != null) {
if (symbol is Vala.Class ||
diff --git a/src/plugins/vala-pack/ide-vala-symbol-tree.vala b/src/plugins/vala-pack/ide-vala-symbol-tree.vala
index d5140a11a..9edfde2ad 100644
--- a/src/plugins/vala-pack/ide-vala-symbol-tree.vala
+++ b/src/plugins/vala-pack/ide-vala-symbol-tree.vala
@@ -142,15 +142,14 @@ namespace Ide
this.kind = Ide.SymbolKind.FIELD;
}
- public override async Ide.SourceLocation? get_location_async (GLib.Cancellable? cancellable)
+ public override async Ide.Location? get_location_async (GLib.Cancellable? cancellable)
{
var source_reference = this.node.source_reference;
var file = (source_reference.file as Ide.ValaSourceFile).file;
- return new Ide.SourceLocation (file,
- source_reference.begin.line - 1,
- source_reference.begin.column - 1,
- 0);
+ return new Ide.Location (file,
+ source_reference.begin.line - 1,
+ source_reference.begin.column - 1);
}
}
}
diff --git a/src/plugins/vala-pack/meson.build b/src/plugins/vala-pack/meson.build
index a8c53c6e5..bc3be9d63 100644
--- a/src/plugins/vala-pack/meson.build
+++ b/src/plugins/vala-pack/meson.build
@@ -1,8 +1,4 @@
-if get_option('with_vala_pack')
-
-if not get_option('with_vapi')
-# error('You must enable VAPI generation to build the Vala pack')
-endif
+if get_option('plugin_vala')
add_languages('vala')
@@ -10,7 +6,7 @@ valac = meson.get_compiler('vala')
libvala_version = run_command(valac.cmd_array()[0], '--api-version').stdout().strip()
libvala = dependency('libvala-@0@'.format(libvala_version))
-vala_pack_sources = [
+vala_sources = [
'config.vapi',
'ide-vala-service.vala',
'ide-vala-code-indexer.vala',
@@ -30,41 +26,45 @@ vala_pack_sources = [
'vala-pack-plugin.vala',
]
-vala_pack_deps = [
+vala_deps = [
libvala,
- libide_vapi,
libpeas_dep,
- libide_plugin_dep,
+ libide_vapi,
+ libgtksource_dep,
+ libvte_dep,
+ libdazzle_dep,
+ libtemplate_glib_dep,
]
-shared_module('vala-pack-plugin', vala_pack_sources,
- link_args: gnome_builder_plugins_link_args,
- link_depends: gnome_builder_plugins_link_deps,
- dependencies: vala_pack_deps,
- install: true,
- install_dir: plugindir,
- install_rpath: pkglibdir_abs,
+shared_module('plugin-vala-pack', vala_sources,
+ dependencies: vala_deps,
+ install: true,
+ install_dir: plugindir,
+ install_rpath: pkglibdir_abs,
+ include_directories: [include_directories('.')] + libide_include_directories,
- vala_args: [ '--target-glib=2.52',
- '--pkg=posix',
- '--pkg=libpeas-1.0',
- '--pkg=gtksourceview-4',
- '--pkg=gio-2.0',
- '--pkg=libvala-' + libvala_version,
- '--pkg=libdazzle-1.0',
- ],
- c_args: [ '-DVALA_VERSION="@0@"'.format(libvala_version),
- '-DLOG_DOMAIN="vala-pack-plugin"',
- '-DGETTEXT_PACKAGE="gnome-builder"',
- '-DPACKAGE_DATADIR="@0@"'.format(join_paths(get_option('prefix'), get_option('datadir'),
'gnome-builder')),
- '-Wno-incompatible-pointer-types',
- ],
+ vala_args: [ '--target-glib=2.52',
+ '--pkg=posix',
+ '--pkg=libpeas-1.0',
+ '--pkg=gtksourceview-4',
+ '--pkg=gio-2.0',
+ '--pkg=libvala-' + libvala_version,
+ '--pkg=libdazzle-1.0',
+ '--pkg=template-glib-1.0',
+ '--pkg=vte-2.91',
+ ],
+ c_args: [ '-DVALA_VERSION="@0@"'.format(libvala_version),
+ '-DLOG_DOMAIN="vala-pack"',
+ '-DGETTEXT_PACKAGE="gnome-builder"',
+ '-DPACKAGE_DATADIR="@0@"'.format(join_paths(get_option('prefix'),
get_option('datadir'), 'gnome-builder')),
+ '-Wno-incompatible-pointer-types',
+ ],
)
configure_file(
input: 'vala-pack.plugin',
output: 'vala-pack.plugin',
- copy: true,
+ configuration: config_h,
install: true,
install_dir: plugindir,
)
diff --git a/src/plugins/vala-pack/vala-pack-plugin.vala b/src/plugins/vala-pack/vala-pack-plugin.vala
index df206e6bb..5a1b78e21 100644
--- a/src/plugins/vala-pack/vala-pack-plugin.vala
+++ b/src/plugins/vala-pack/vala-pack-plugin.vala
@@ -31,6 +31,5 @@ public void peas_register_types (GLib.TypeModule module)
peas.register_extension_type (typeof (Ide.DiagnosticProvider), typeof (Ide.ValaDiagnosticProvider));
peas.register_extension_type (typeof (Ide.Indenter), typeof (Ide.ValaIndenter));
peas.register_extension_type (typeof (Ide.PreferencesAddin), typeof (Ide.ValaPreferencesAddin));
- peas.register_extension_type (typeof (Ide.Service), typeof (Ide.ValaService));
peas.register_extension_type (typeof (Ide.SymbolResolver), typeof (Ide.ValaSymbolResolver));
}
diff --git a/src/plugins/vala-pack/vala-pack.plugin b/src/plugins/vala-pack/vala-pack.plugin
index ee625b166..42eb787ea 100644
--- a/src/plugins/vala-pack/vala-pack.plugin
+++ b/src/plugins/vala-pack/vala-pack.plugin
@@ -1,15 +1,16 @@
[Plugin]
-Module=vala-pack-plugin
-Name=Vala Language Pack
-Description=Provides an auto-indenter, auto-completion, diagnostics, and symbol resolver for Vala
Authors=Christian Hergert <christian hergert me>
-Copyright=Copyright © 2015 Christian Hergert
Builtin=true
+Copyright=Copyright © 2015 Christian Hergert
+Description=Provides an auto-indenter, auto-completion, diagnostics, and symbol resolver for Vala
+Module=plugin-vala-pack
+Name=Vala Language Pack
+X-Builder-ABI=@PACKAGE_ABI@
+X-Code-Indexer-Languages-Priority=100
+X-Code-Indexer-Languages=vala
X-Completion-Provider-Languages=vala
X-Diagnostic-Provider-Languages=vala
-X-Indenter-Languages=vala
X-Indenter-Languages-Priority=0
-X-Symbol-Resolver-Languages=vala
+X-Indenter-Languages=vala
X-Symbol-Resolver-Languages-Priority=100
-X-Code-Indexer-Languages=vala
-X-Code-Indexer-Languages-Priority=100
+X-Symbol-Resolver-Languages=vala
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]