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

code-index: make code indexer iface use async/finish ops

We don't want "threaded plugin API". Instead, we want objects that live in
the main thread, and have async/finish API (for which plugins can choose to
use threads if they like).
parent b45526b7
......@@ -18,6 +18,7 @@
#define G_LOG_DOMAIN "ide-code-index-entries"
#include "application/ide-application.h"
#include "symbols/ide-code-index-entries.h"
G_DEFINE_INTERFACE (IdeCodeIndexEntries, ide_code_index_entries, G_TYPE_OBJECT)
......@@ -49,6 +50,7 @@ ide_code_index_entries_default_init (IdeCodeIndexEntriesInterface *iface)
IdeCodeIndexEntry *
ide_code_index_entries_get_next_entry (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_next_entry (self);
......
......@@ -19,22 +19,23 @@
#pragma once
#include "ide-object.h"
#include "symbols/ide-symbol.h"
#include "symbols/ide-code-index-entry.h"
#include "symbols/ide-symbol.h"
G_BEGIN_DECLS
#define IDE_TYPE_CODE_INDEX_ENTRIES (ide_code_index_entries_get_type ())
#define IDE_TYPE_CODE_INDEX_ENTRIES (ide_code_index_entries_get_type())
G_DECLARE_INTERFACE (IdeCodeIndexEntries, ide_code_index_entries, IDE, CODE_INDEX_ENTRIES, GObject)
struct _IdeCodeIndexEntriesInterface
{
GTypeInterface parent_iface;
GTypeInterface parent_iface;
IdeCodeIndexEntry *(*get_next_entry) (IdeCodeIndexEntries *self);
IdeCodeIndexEntry *(*get_next_entry) (IdeCodeIndexEntries *self);
};
IdeCodeIndexEntry *ide_code_index_entries_get_next_entry (IdeCodeIndexEntries *self);
IdeCodeIndexEntry *ide_code_index_entries_get_next_entry (IdeCodeIndexEntries *self);
G_END_DECLS
/* ide-code-indexer.c
*
* Copyright © 2017 Anoop Chandu <anoopchandu96@gmail.com>
* Copyright © 2018 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
......@@ -18,56 +19,91 @@
#define G_LOG_DOMAIN "ide-code-indexer"
#include "application/ide-application.h"
#include "symbols/ide-code-indexer.h"
/**
* SECTION:ide-code-indexer
* @title: IdeCodeIndexer
* @short_description: Interface for background indexing source code
*
* The #IdeCodeIndexer interface is used to index source code in the project.
* Plugins that want to provide global search features for source code should
* implement this interface and specify which languages they support in their
* .plugin definition, using "X-Code-Indexer-Languages". For example. to index
* Python source code, you might use:
*
* X-Code-Indexer-Languages=python,python3
*
* Since: 3.26
*/
G_DEFINE_INTERFACE (IdeCodeIndexer, ide_code_indexer, IDE_TYPE_OBJECT)
static void
ide_code_indexer_real_index_file_async (IdeCodeIndexer *self,
GFile *file,
const gchar * const *build_flags,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
g_assert (IDE_IS_CODE_INDEXER (self));
g_assert (G_IS_FILE (file));
g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
g_task_report_new_error (self, callback, user_data,
ide_code_indexer_real_index_file_async,
G_IO_ERROR,
G_IO_ERROR_NOT_SUPPORTED,
"Get key is not supported");
}
static IdeCodeIndexEntries *
ide_code_indexer_real_index_file (IdeCodeIndexer *self,
GFile *file,
const gchar * const *build_flags,
GCancellable *cancellable,
GError **error)
ide_code_indexer_real_index_file_finish (IdeCodeIndexer *self,
GAsyncResult *result,
GError **error)
{
g_set_error (error,
G_IO_ERROR,
G_IO_ERROR_NOT_SUPPORTED,
"Indexing is not supported");
return NULL;
g_assert (IDE_IS_CODE_INDEXER (self));
g_assert (G_IS_TASK (result));
return g_task_propagate_pointer (G_TASK (result), error);
}
void
ide_code_indexer_real_generate_key_async (IdeCodeIndexer *self,
IdeSourceLocation *location,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
static void
ide_code_indexer_real_generate_key_async (IdeCodeIndexer *self,
IdeSourceLocation *location,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
g_task_report_new_error (self,
callback,
user_data,
g_assert (IDE_IS_CODE_INDEXER (self));
g_assert (location != NULL);
g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
g_task_report_new_error (self, callback, user_data,
ide_code_indexer_real_generate_key_async,
G_IO_ERROR,
G_IO_ERROR_NOT_SUPPORTED,
"Get key is not supported");
}
gchar *
static gchar *
ide_code_indexer_real_generate_key_finish (IdeCodeIndexer *self,
GAsyncResult *result,
GError **error)
{
GTask *task = (GTask *)result;
g_assert (IDE_IS_CODE_INDEXER (self));
g_assert (G_IS_TASK (result));
return g_task_propagate_pointer (task, error);
return g_task_propagate_pointer (G_TASK (result), error);
}
static void
ide_code_indexer_default_init (IdeCodeIndexerInterface *iface)
{
iface->index_file = ide_code_indexer_real_index_file;
iface->index_file_async = ide_code_indexer_real_index_file_async;
iface->index_file_finish = ide_code_indexer_real_index_file_finish;
iface->generate_key_async = ide_code_indexer_real_generate_key_async;
iface->generate_key_finish = ide_code_indexer_real_generate_key_finish;
}
......@@ -78,32 +114,54 @@ ide_code_indexer_default_init (IdeCodeIndexerInterface *iface)
* @file: Source file to index.
* @build_flags: (nullable) (array zero-terminated=1): array of build flags to parse @file.
* @cancellable: (nullable): a #GCancellable.
* @error: a #GError.
* @callback: a #GAsyncReadyCallback
* @user_data: closure data for @callback
*
* This function will take index source file and create an array of symbols in
* @file. @callback is called upon completion and must call
* ide_code_indexer_index_file_finish() to complete the operation.
*
* Since: 3.28
*/
void
ide_code_indexer_index_file_async (IdeCodeIndexer *self,
GFile *file,
const gchar * const *build_flags,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
g_return_if_fail (IDE_IS_MAIN_THREAD ());
g_return_if_fail (IDE_IS_CODE_INDEXER (self));
g_return_if_fail (G_IS_FILE (file));
g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
return IDE_CODE_INDEXER_GET_IFACE (self)->index_file_async (self, file, build_flags, cancellable, callback, user_data);
}
/**
* ide_code_indexer_index_file_finish:
* @self: a #IdeCodeIndexer
* @result: a #GAsyncResult provided to callback
* @error: a location for a #GError, or %NULL
*
* This function will take index source file and create an array
* of symbols in @file.
* Completes an asynchronous request to ide_code_indexer_index_file_async().
*
* Returns: (transfer full): an #IdeCodeIndexEntries contains list
* of #IdeCodeIndexEntry.
* Returns: (transfer full): an #IdeCodeIndexEntries if successful; otherwise %NULL
* and @error is set.
*
* Since: 3.26
* Since: 3.28
*/
IdeCodeIndexEntries *
ide_code_indexer_index_file (IdeCodeIndexer *self,
GFile *file,
const gchar * const *build_flags,
GCancellable *cancellable,
GError **error)
ide_code_indexer_index_file_finish (IdeCodeIndexer *self,
GAsyncResult *result,
GError **error)
{
IdeCodeIndexerInterface *iface;
g_return_val_if_fail (IDE_IS_MAIN_THREAD (), NULL);
g_return_val_if_fail (IDE_IS_CODE_INDEXER (self), NULL);
g_return_val_if_fail (G_IS_FILE (file), NULL);
g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), NULL);
g_return_val_if_fail (G_IS_ASYNC_RESULT (result), NULL);
iface = IDE_CODE_INDEXER_GET_IFACE (self);
return iface->index_file (self, file, build_flags, cancellable, error);
return IDE_CODE_INDEXER_GET_IFACE (self)->index_file_finish (self, result, error);
}
/**
......@@ -119,21 +177,18 @@ ide_code_indexer_index_file (IdeCodeIndexer *self,
* Since: 3.26
*/
void
ide_code_indexer_generate_key_async (IdeCodeIndexer *self,
IdeSourceLocation *location,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
ide_code_indexer_generate_key_async (IdeCodeIndexer *self,
IdeSourceLocation *location,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
IdeCodeIndexerInterface *iface;
g_return_if_fail (IDE_IS_MAIN_THREAD ());
g_return_if_fail (IDE_IS_CODE_INDEXER (self));
g_return_if_fail (location != NULL);
g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
iface = IDE_CODE_INDEXER_GET_IFACE (self);
iface->generate_key_async (self, location, cancellable, callback, user_data);
IDE_CODE_INDEXER_GET_IFACE (self)->generate_key_async (self, location, cancellable, callback, user_data);
}
/**
......@@ -149,15 +204,13 @@ ide_code_indexer_generate_key_async (IdeCodeIndexer *self,
* Since: 3.26
*/
gchar *
ide_code_indexer_generate_key_finish (IdeCodeIndexer *self,
GAsyncResult *result,
GError **error)
ide_code_indexer_generate_key_finish (IdeCodeIndexer *self,
GAsyncResult *result,
GError **error)
{
IdeCodeIndexerInterface *iface;
g_return_val_if_fail (IDE_IS_MAIN_THREAD (), NULL);
g_return_val_if_fail (IDE_IS_CODE_INDEXER (self), NULL);
g_return_val_if_fail (G_IS_ASYNC_RESULT (result), NULL);
iface = IDE_CODE_INDEXER_GET_IFACE (self);
return iface->generate_key_finish (self, result, error);
return IDE_CODE_INDEXER_GET_IFACE (self)->generate_key_finish (self, result, error);
}
......@@ -18,9 +18,9 @@
#pragma once
#include "ide-object.h"
#include "ide-version-macros.h"
#include "ide-object.h"
#include "symbols/ide-code-index-entries.h"
G_BEGIN_DECLS
......@@ -31,13 +31,8 @@ G_DECLARE_INTERFACE (IdeCodeIndexer, ide_code_indexer, IDE, CODE_INDEXER, IdeObj
struct _IdeCodeIndexerInterface
{
GTypeInterface parent_iface;
GTypeInterface parent_iface;
IdeCodeIndexEntries *(*index_file) (IdeCodeIndexer *self,
GFile *file,
const gchar * const *build_flags,
GCancellable *cancellable,
GError **error);
void (*generate_key_async) (IdeCodeIndexer *self,
IdeSourceLocation *location,
GCancellable *cancellable,
......@@ -46,23 +41,37 @@ struct _IdeCodeIndexerInterface
gchar *(*generate_key_finish) (IdeCodeIndexer *self,
GAsyncResult *result,
GError **error);
void (*index_file_async) (IdeCodeIndexer *self,
GFile *file,
const gchar * const *build_flags,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
IdeCodeIndexEntries *(*index_file_finish) (IdeCodeIndexer *self,
GAsyncResult *result,
GError **error);
};
IDE_AVAILABLE_IN_3_28
void ide_code_indexer_index_file_async (IdeCodeIndexer *self,
GFile *file,
const gchar * const *build_flags,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
IDE_AVAILABLE_IN_3_28
IdeCodeIndexEntries *ide_code_indexer_index_file_finish (IdeCodeIndexer *self,
GAsyncResult *result,
GError **error);
IDE_AVAILABLE_IN_ALL
IdeCodeIndexEntries *ide_code_indexer_index_file (IdeCodeIndexer *self,
GFile *file,
const gchar * const *build_flags,
GCancellable *cancellable,
GError **error);
IDE_AVAILABLE_IN_ALL
void ide_code_indexer_generate_key_async (IdeCodeIndexer *self,
IdeSourceLocation *location,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
void ide_code_indexer_generate_key_async (IdeCodeIndexer *self,
IdeSourceLocation *location,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
IDE_AVAILABLE_IN_ALL
gchar *ide_code_indexer_generate_key_finish (IdeCodeIndexer *self,
GAsyncResult *result,
GError **error);
gchar *ide_code_indexer_generate_key_finish (IdeCodeIndexer *self,
GAsyncResult *result,
GError **error);
G_END_DECLS
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