[gnome-builder] vala-pack: stub out code indexer implementation



commit b30e7401b1e4f10d7f89903fc2286a7fd4a638b1
Author: Christian Hergert <chergert redhat com>
Date:   Fri Nov 10 17:41:53 2017 -0800

    vala-pack: stub out code indexer implementation
    
    We need to go through the discovered sources and access their
    ValaSourceFile AST to add index entries. This just stubs out the interface
    for the time being.

 src/plugins/vala-pack/ide-vala-code-indexer.vala |   52 ++++++++++++++++++++++
 src/plugins/vala-pack/meson.build                |    1 +
 src/plugins/vala-pack/vala-pack-plugin.vala      |    1 +
 src/plugins/vala-pack/vala-pack.plugin           |    2 +
 4 files changed, 56 insertions(+), 0 deletions(-)
---
diff --git a/src/plugins/vala-pack/ide-vala-code-indexer.vala 
b/src/plugins/vala-pack/ide-vala-code-indexer.vala
new file mode 100644
index 0000000..ea858a7
--- /dev/null
+++ b/src/plugins/vala-pack/ide-vala-code-indexer.vala
@@ -0,0 +1,52 @@
+/* ide-vala-indenter.vala
+ *
+ * Copyright © 2017 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+using GLib;
+using Ide;
+
+namespace Ide
+{
+       public class ValaCodeIndexer : Ide.Object, Ide.CodeIndexer
+       {
+               public Ide.CodeIndexEntries index_file (GLib.File file,
+                                                       string[]? build_flags,
+                                                       GLib.Cancellable? cancellable)
+                       throws GLib.Error
+               {
+                       throw new GLib.IOError.NOT_SUPPORTED ("indexing files is not yet supported");
+               }
+
+               public async string generate_key_async (Ide.SourceLocation location,
+                                                       GLib.Cancellable? cancellable)
+                       throws GLib.Error
+               {
+                       var context = this.get_context ();
+                       var service = (Ide.ValaService)context.get_service_typed (typeof (Ide.ValaService));
+                       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);
+
+                       if (symbol == null)
+                               throw new GLib.IOError.FAILED ("failed to locate symbol");
+
+                       return symbol.get_full_name ();
+               }
+       }
+}
diff --git a/src/plugins/vala-pack/meson.build b/src/plugins/vala-pack/meson.build
index 7c3b396..b13c908 100644
--- a/src/plugins/vala-pack/meson.build
+++ b/src/plugins/vala-pack/meson.build
@@ -33,6 +33,7 @@ endif
 vala_pack_sources = [
   'config.vapi',
   'ide-vala-service.vala',
+  'ide-vala-code-indexer.vala',
   'ide-vala-completion.vala',
   'ide-vala-completion-item.vala',
   'ide-vala-completion-provider.vala',
diff --git a/src/plugins/vala-pack/vala-pack-plugin.vala b/src/plugins/vala-pack/vala-pack-plugin.vala
index 18f912a..26b5a13 100644
--- a/src/plugins/vala-pack/vala-pack-plugin.vala
+++ b/src/plugins/vala-pack/vala-pack-plugin.vala
@@ -26,6 +26,7 @@ public void peas_register_types (GLib.TypeModule module)
        Peas.ObjectModule peas = (Peas.ObjectModule)module;
 
        peas.register_extension_type (typeof (Ide.BuildPipelineAddin), typeof (Ide.ValaPipelineAddin));
+       peas.register_extension_type (typeof (Ide.CodeIndexer), typeof (Ide.ValaCodeIndexer));
        peas.register_extension_type (typeof (Ide.CompletionProvider), typeof (Ide.ValaCompletionProvider));
        peas.register_extension_type (typeof (Ide.DiagnosticProvider), typeof (Ide.ValaDiagnosticProvider));
        peas.register_extension_type (typeof (Ide.Indenter), typeof (Ide.ValaIndenter));
diff --git a/src/plugins/vala-pack/vala-pack.plugin b/src/plugins/vala-pack/vala-pack.plugin
index b03ddfa..ee625b1 100644
--- a/src/plugins/vala-pack/vala-pack.plugin
+++ b/src/plugins/vala-pack/vala-pack.plugin
@@ -11,3 +11,5 @@ X-Indenter-Languages=vala
 X-Indenter-Languages-Priority=0
 X-Symbol-Resolver-Languages=vala
 X-Symbol-Resolver-Languages-Priority=100
+X-Code-Indexer-Languages=vala
+X-Code-Indexer-Languages-Priority=100


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