Commit d7cf8466 authored by Christian Hergert's avatar Christian Hergert
Browse files

code-index: require new get_file helper for entries

This is convenient for the code indexer, so lets require it of
the code entries to save us some pain.
parent d02342f1
......@@ -23,16 +23,9 @@
G_DEFINE_INTERFACE (IdeCodeIndexEntries, ide_code_index_entries, G_TYPE_OBJECT)
IdeCodeIndexEntry *
ide_code_index_entries_real_get_next_entry (IdeCodeIndexEntries *self)
{
return NULL;
}
static void
ide_code_index_entries_default_init (IdeCodeIndexEntriesInterface *iface)
{
iface->get_next_entry = ide_code_index_entries_real_get_next_entry;
}
/**
......@@ -55,3 +48,20 @@ ide_code_index_entries_get_next_entry (IdeCodeIndexEntries *self)
return IDE_CODE_INDEX_ENTRIES_GET_IFACE (self)->get_next_entry (self);
}
/**
* ide_code_index_entries_get_file:
* @self: a #IdeCodeIndexEntries
*
* The file that was indexed.
*
* Returns: (transfer full): a #GFile
*/
GFile *
ide_code_index_entries_get_file (IdeCodeIndexEntries *self)
{
g_return_val_if_fail (IDE_IS_MAIN_THREAD (), NULL);
g_return_val_if_fail (IDE_IS_CODE_INDEX_ENTRIES (self), NULL);
return IDE_CODE_INDEX_ENTRIES_GET_IFACE (self)->get_file (self);
}
......@@ -33,9 +33,11 @@ struct _IdeCodeIndexEntriesInterface
{
GTypeInterface parent_iface;
GFile *(*get_file) (IdeCodeIndexEntries *self);
IdeCodeIndexEntry *(*get_next_entry) (IdeCodeIndexEntries *self);
};
IdeCodeIndexEntry *ide_code_index_entries_get_next_entry (IdeCodeIndexEntries *self);
GFile *ide_code_index_entries_get_file (IdeCodeIndexEntries *self);
G_END_DECLS
......@@ -328,10 +328,21 @@ ide_clang_code_index_entries_get_next_entry (IdeCodeIndexEntries *entries)
return g_steal_pointer (&entry);
}
static GFile *
ide_clang_code_index_entries_get_file (IdeCodeIndexEntries *entries)
{
IdeClangCodeIndexEntries *self = (IdeClangCodeIndexEntries *)entries;
g_return_val_if_fail (IDE_IS_CLANG_CODE_INDEX_ENTRIES (self), NULL);
return g_file_new_for_path (self->path);
}
static void
index_entries_iface_init (IdeCodeIndexEntriesInterface *iface)
{
iface->get_next_entry = ide_clang_code_index_entries_get_next_entry;
iface->get_file = ide_clang_code_index_entries_get_file;
}
G_DEFINE_TYPE_WITH_CODE (IdeClangCodeIndexEntries, ide_clang_code_index_entries, G_TYPE_OBJECT,
......
......@@ -337,10 +337,11 @@ class GjsSymbolProvider(Ide.Object, Ide.SymbolResolver):
class JsCodeIndexEntries(GObject.Object, Ide.CodeIndexEntries):
def __init__(self, entries):
def __init__(self, file, entries):
super().__init__()
self.entries = entries
self.entry_iter = None
self.file = file
def do_get_next_entry(self):
if self.entry_iter is None:
......@@ -351,6 +352,9 @@ class JsCodeIndexEntries(GObject.Object, Ide.CodeIndexEntries):
self.entry_iter = None
return None
def do_get_file(self):
return self.file
class GjsCodeIndexer(Ide.Object, Ide.CodeIndexer):
def __init__(self):
......@@ -378,7 +382,7 @@ class GjsCodeIndexer(Ide.Object, Ide.CodeIndexer):
try:
_, stdout, stderr = subprocess.communicate_utf8_finish(result)
ide_file = Ide.File(file=file_, context=self.get_context())
ide_file = Ide.File(file=task.file_, context=self.get_context())
try:
root_node = JsSymbolTree._node_from_dict(json.loads(stdout), ide_file)
except (json.JSONDecodeError, UnicodeDecodeError) as e:
......@@ -399,7 +403,7 @@ class GjsCodeIndexer(Ide.Object, Ide.CodeIndexer):
)
entries.append(entry)
task.entries = JsCodeIndexEntries(entries)
task.entries = JsCodeIndexEntries(task.file_, entries)
task.return_boolean(True)
except Exception as ex:
......@@ -409,6 +413,7 @@ class GjsCodeIndexer(Ide.Object, Ide.CodeIndexer):
def do_index_file_async(self, file_, build_flags, cancellable, callback, data):
task = Gio.Task.new(self, cancellable, callback)
task.entries = None
task.file = file_
launcher = GjsSymbolProvider._get_launcher(self.get_context(), file_)
proc = launcher.spawn()
......
......@@ -38,7 +38,7 @@ namespace Ide
var index = service.index;
var tree = index.get_symbol_tree_sync (file, cancellable);
var ret = new Ide.ValaCodeIndexEntries (tree as Ide.ValaSymbolTree);
var ret = new Ide.ValaCodeIndexEntries (file, tree as Ide.ValaSymbolTree);
if (ret == null)
throw new GLib.IOError.FAILED ("failed to build entries");
......@@ -67,11 +67,18 @@ namespace Ide
public class ValaCodeIndexEntries : GLib.Object, Ide.CodeIndexEntries
{
GLib.GenericArray<Ide.CodeIndexEntry> entries;
GLib.File file;
uint pos;
public ValaCodeIndexEntries (Ide.ValaSymbolTree tree)
public GLib.File get_file ()
{
return this.file;
}
public ValaCodeIndexEntries (GLib.File file, Ide.ValaSymbolTree tree)
{
this.entries = new GLib.GenericArray<Ide.CodeIndexEntry> ();
this.file = file;
this.add_children (tree, null, "");
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment