[gnome-builder] code-index: use service for index access



commit 2aa6e23c505be21b079370b2d79f2bb5ac146b6e
Author: Christian Hergert <chergert redhat com>
Date:   Mon Feb 4 20:49:44 2019 -0800

    code-index: use service for index access

 src/plugins/code-index/gbp-code-index-service.c    | 31 +++++++++++++++-------
 src/plugins/code-index/gbp-code-index-service.h    |  3 +++
 .../code-index/gbp-code-index-workbench-addin.c    | 30 ++-------------------
 .../code-index/ide-code-index-search-provider.c    |  8 +++---
 .../code-index/ide-code-index-symbol-resolver.c    | 10 +++----
 5 files changed, 34 insertions(+), 48 deletions(-)
---
diff --git a/src/plugins/code-index/gbp-code-index-service.c b/src/plugins/code-index/gbp-code-index-service.c
index 532fbbe62..b1af24ec7 100644
--- a/src/plugins/code-index/gbp-code-index-service.c
+++ b/src/plugins/code-index/gbp-code-index-service.c
@@ -39,18 +39,19 @@
 
 struct _GbpCodeIndexService
 {
-  IdeObject         parent_instance;
+  IdeObject          parent_instance;
 
-  IdeNotification  *notif;
-  GCancellable     *cancellable;
+  IdeNotification   *notif;
+  IdeCodeIndexIndex *index;
+  GCancellable      *cancellable;
 
-  guint             queued_source;
+  guint              queued_source;
 
-  guint             build_inhibit : 1;
-  guint             needs_indexing : 1;
-  guint             indexing : 1;
-  guint             started : 1;
-  guint             paused : 1;
+  guint              build_inhibit : 1;
+  guint              needs_indexing : 1;
+  guint              indexing : 1;
+  guint              started : 1;
+  guint              paused : 1;
 };
 
 enum {
@@ -108,6 +109,8 @@ gbp_code_index_service_destroy (IdeObject *object)
   g_clear_object (&self->cancellable);
   g_clear_handle_id (&self->queued_source, g_source_remove);
 
+  ide_clear_and_destroy_object (&self->index);
+
   if (self->notif)
     {
       ide_notification_withdraw (self->notif);
@@ -191,6 +194,8 @@ gbp_code_index_service_init (GbpCodeIndexService *self)
   ide_notification_set_has_progress (self->notif, TRUE);
   ide_notification_set_progress (self->notif, 0);
   ide_notification_add_button (self->notif, NULL, icon, "code-index.paused");
+
+  self->index = ide_code_index_index_new (IDE_OBJECT (self));
 }
 
 static void
@@ -876,3 +881,11 @@ gbp_code_index_service_from_context (IdeContext *context)
 
   return ret;
 }
+
+IdeCodeIndexIndex *
+gbp_code_index_service_get_index (GbpCodeIndexService *self)
+{
+  g_return_val_if_fail (GBP_IS_CODE_INDEX_SERVICE (self), NULL);
+
+  return self->index;
+}
diff --git a/src/plugins/code-index/gbp-code-index-service.h b/src/plugins/code-index/gbp-code-index-service.h
index 89ce075d3..3170a50e7 100644
--- a/src/plugins/code-index/gbp-code-index-service.h
+++ b/src/plugins/code-index/gbp-code-index-service.h
@@ -23,6 +23,8 @@
 #include <libide-core.h>
 #include <libide-code.h>
 
+#include "ide-code-index-index.h"
+
 G_BEGIN_DECLS
 
 #define GBP_TYPE_CODE_INDEX_SERVICE (gbp_code_index_service_get_type())
@@ -35,6 +37,7 @@ void                 gbp_code_index_service_stop         (GbpCodeIndexService *s
 gboolean             gbp_code_index_service_get_paused   (GbpCodeIndexService *self);
 void                 gbp_code_index_service_set_paused   (GbpCodeIndexService *self,
                                                           gboolean             paused);
+IdeCodeIndexIndex   *gbp_code_index_service_get_index    (GbpCodeIndexService *self);
 IdeCodeIndexer      *gbp_code_index_service_get_indexer  (GbpCodeIndexService *self,
                                                           const gchar         *lang_id,
                                                           const gchar         *path);
diff --git a/src/plugins/code-index/gbp-code-index-workbench-addin.c 
b/src/plugins/code-index/gbp-code-index-workbench-addin.c
index 1a421c5f1..1d657fa67 100644
--- a/src/plugins/code-index/gbp-code-index-workbench-addin.c
+++ b/src/plugins/code-index/gbp-code-index-workbench-addin.c
@@ -32,9 +32,8 @@
 
 struct _GbpCodeIndexWorkbenchAddin
 {
-  GObject            parent_instance;
-  IdeWorkbench      *workbench;
-  IdeCodeIndexIndex *index;
+  GObject       parent_instance;
+  IdeWorkbench *workbench;
 };
 
 static void gbp_code_index_workbench_addin_notify_paused (GbpCodeIndexWorkbenchAddin *self,
@@ -74,8 +73,6 @@ gbp_code_index_workbench_addin_unload (IdeWorkbenchAddin *addin,
       ide_object_destroy (IDE_OBJECT (service));
     }
 
-  ide_clear_and_destroy_object (&self->index);
-
   self->workbench = NULL;
 }
 
@@ -91,12 +88,7 @@ gbp_code_index_workbench_addin_project_loaded (IdeWorkbenchAddin *addin,
   g_assert (GBP_IS_CODE_INDEX_WORKBENCH_ADDIN (self));
   g_assert (IDE_IS_PROJECT_INFO (project_info));
 
-  /* TODO: We should clean this up a bit still */
-
   context = ide_workbench_get_context (self->workbench);
-
-  self->index = ide_code_index_index_new (IDE_OBJECT (context));
-
   service = gbp_code_index_service_from_context (context);
   g_signal_connect_object (service,
                            "notify::paused",
@@ -179,24 +171,6 @@ gbp_code_index_workbench_addin_init (GbpCodeIndexWorkbenchAddin *self)
 {
 }
 
-GbpCodeIndexWorkbenchAddin *
-gbp_code_index_workbench_addin_from_context (IdeContext *context)
-{
-  g_return_val_if_fail (IDE_IS_MAIN_THREAD (), NULL);
-  g_return_val_if_fail (IDE_IS_CONTEXT (context), NULL);
-
-  return ide_context_peek_child_typed (context, GBP_TYPE_CODE_INDEX_WORKBENCH_ADDIN);
-}
-
-IdeCodeIndexIndex *
-gbp_code_index_workbench_addin_get_index (GbpCodeIndexWorkbenchAddin *self)
-{
-  g_return_val_if_fail (IDE_IS_MAIN_THREAD (), NULL);
-  g_return_val_if_fail (GBP_IS_CODE_INDEX_WORKBENCH_ADDIN (self), NULL);
-
-  return self->index;
-}
-
 static void
 gbp_code_index_workbench_addin_notify_paused (GbpCodeIndexWorkbenchAddin *self,
                                               GParamSpec                 *pspec,
diff --git a/src/plugins/code-index/ide-code-index-search-provider.c 
b/src/plugins/code-index/ide-code-index-search-provider.c
index 5e127c4e3..68abbbadc 100644
--- a/src/plugins/code-index/ide-code-index-search-provider.c
+++ b/src/plugins/code-index/ide-code-index-search-provider.c
@@ -25,7 +25,7 @@
 
 #include "ide-code-index-search-provider.h"
 #include "ide-code-index-index.h"
-#include "gbp-code-index-workbench-addin.h"
+#include "gbp-code-index-service.h"
 
 static void
 populate_cb (GObject      *object,
@@ -60,7 +60,7 @@ ide_code_index_search_provider_search_async (IdeSearchProvider   *provider,
                                              gpointer             user_data)
 {
   IdeCodeIndexSearchProvider *self = (IdeCodeIndexSearchProvider *)provider;
-  GbpCodeIndexWorkbenchAddin *addin = NULL;
+  GbpCodeIndexService *service = NULL;
   g_autoptr(IdeTask) task = NULL;
   IdeCodeIndexIndex *index;
   IdeContext *context;
@@ -79,7 +79,7 @@ ide_code_index_search_provider_search_async (IdeSearchProvider   *provider,
   ide_task_set_source_tag (task, ide_code_index_search_provider_search_async);
 
   if (!ide_context_has_project (context) ||
-      !(addin = gbp_code_index_workbench_addin_from_context (context)))
+      !(service = gbp_code_index_service_from_context (context)))
     {
       ide_task_return_new_error (task,
                                  G_IO_ERROR,
@@ -88,7 +88,7 @@ ide_code_index_search_provider_search_async (IdeSearchProvider   *provider,
       IDE_EXIT;
     }
 
-  index = gbp_code_index_workbench_addin_get_index (addin);
+  index = gbp_code_index_service_get_index (service);
 
   if (index == NULL)
     ide_task_return_new_error (task,
diff --git a/src/plugins/code-index/ide-code-index-symbol-resolver.c 
b/src/plugins/code-index/ide-code-index-symbol-resolver.c
index 93cc75230..cbe53b84e 100644
--- a/src/plugins/code-index/ide-code-index-symbol-resolver.c
+++ b/src/plugins/code-index/ide-code-index-symbol-resolver.c
@@ -30,12 +30,12 @@ ide_code_index_symbol_resolver_lookup_cb (GObject      *object,
                                           gpointer      user_data)
 {
   IdeCodeIndexer *code_indexer = (IdeCodeIndexer *)object;
-  GbpCodeIndexWorkbenchAddin *addin = NULL;
   g_autoptr(IdeTask) task = user_data;
   g_autoptr(IdeSymbol) symbol = NULL;
   g_autoptr(GError) error = NULL;
   g_autofree gchar *key = NULL;
   IdeCodeIndexSymbolResolver *self;
+  GbpCodeIndexService *service;
   IdeCodeIndexIndex *index;
   IdeContext *context;
 
@@ -56,12 +56,8 @@ ide_code_index_symbol_resolver_lookup_cb (GObject      *object,
   context = ide_object_get_context (IDE_OBJECT (self));
   g_assert (IDE_IS_CONTEXT (context));
 
-  addin = gbp_code_index_workbench_addin_from_context (context);
-  g_assert (GBP_IS_CODE_INDEX_WORKBENCH_ADDIN (addin));
-
-  index = gbp_code_index_workbench_addin_get_index (addin);
-  g_assert (IDE_IS_CODE_INDEX_INDEX (index));
-
+  service = gbp_code_index_service_from_context (context);
+  index = gbp_code_index_service_get_index (service);
   symbol = ide_code_index_index_lookup_symbol (index, key);
 
   if (symbol != NULL)


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