[gnome-builder] code-index: Implmenting search provider



commit ac3eb3e0d12cbaf709f75a37183f91c8914407f5
Author: Anoop Chandu <anoopchandu96 gmail com>
Date:   Sat Aug 26 20:09:04 2017 +0530

    code-index: Implmenting search provider
    
    IdeCodeIndexSearchProvider implements search provider. This
    provider will search the index for symbols which matches fuzzily
    to search query and return search results.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=786700

 .../code-index/ide-code-index-search-provider.c    |  106 ++++++++++++++++++++
 .../code-index/ide-code-index-search-provider.h    |   33 ++++++
 2 files changed, 139 insertions(+), 0 deletions(-)
---
diff --git a/plugins/code-index/ide-code-index-search-provider.c 
b/plugins/code-index/ide-code-index-search-provider.c
new file mode 100644
index 0000000..a2da4c2
--- /dev/null
+++ b/plugins/code-index/ide-code-index-search-provider.c
@@ -0,0 +1,106 @@
+/* ide-code-index-search-provider.c
+ *
+ * Copyright (C) 2017 Anoop Chandu <anoopchandu96 gmail 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/>.
+ */
+
+#define G_LOG_DOMAIN "ide-code-index-search-provider"
+
+#include "ide-code-index-search-provider.h"
+#include "ide-code-index-service.h"
+#include "ide-code-index-index.h"
+
+struct _IdeCodeIndexSearchProvider
+{
+  IdeObject parent;
+};
+
+static void search_provider_iface_init (IdeSearchProviderInterface *iface);
+
+G_DEFINE_TYPE_EXTENDED (IdeCodeIndexSearchProvider, ide_code_index_search_provider, IDE_TYPE_OBJECT,
+                        0, G_IMPLEMENT_INTERFACE (IDE_TYPE_SEARCH_PROVIDER, search_provider_iface_init))
+
+static void
+populate_cb (GObject           *object,
+             GAsyncResult      *result,
+             gpointer           user_data)
+{
+  IdeCodeIndexIndex *index = (IdeCodeIndexIndex *)object;
+  g_autoptr(GTask) task = user_data;
+  GPtrArray *results;
+  g_autoptr(GError) error = NULL;
+
+  g_assert (IDE_IS_CODE_INDEX_INDEX (index));
+  g_assert (G_IS_TASK (task));
+
+  if (NULL != (results = ide_code_index_index_populate_finish (index, result, &error)))
+    g_task_return_pointer (task, results, (GDestroyNotify)g_ptr_array_unref);
+  else
+    g_task_return_error (task, g_steal_pointer (&error));
+}
+
+static void
+ide_code_index_search_provider_search_async (IdeSearchProvider   *provider,
+                                             const gchar         *search_terms,
+                                             guint                max_results,
+                                             GCancellable        *cancellable,
+                                             GAsyncReadyCallback  callback,
+                                             gpointer             user_data)
+{
+  IdeCodeIndexSearchProvider *self = (IdeCodeIndexSearchProvider *)provider;
+  IdeCodeIndexService *service;
+  IdeCodeIndexIndex *index;
+  g_autoptr(GTask) task = NULL;
+
+  g_return_if_fail (IDE_IS_CODE_INDEX_SEARCH_PROVIDER (self));
+
+  service = ide_context_get_service_typed (ide_object_get_context (IDE_OBJECT (self)),
+                                           IDE_TYPE_CODE_INDEX_SERVICE);
+  index = ide_code_index_service_get_index (service);
+
+  task = g_task_new (self, cancellable, callback, user_data);
+
+  ide_code_index_index_populate_async (index, search_terms, max_results, cancellable,
+                                       populate_cb, g_steal_pointer (&task));
+}
+
+static GPtrArray*
+ide_code_index_search_provider_search_finish (IdeSearchProvider *provider,
+                                              GAsyncResult      *result,
+                                              GError           **error)
+{
+  GTask *task = (GTask *)result;
+
+  g_return_val_if_fail (G_IS_TASK(task), NULL);
+
+  return g_task_propagate_pointer (task, error);
+}
+
+static void
+search_provider_iface_init (IdeSearchProviderInterface *iface)
+{
+  iface->search_async = ide_code_index_search_provider_search_async;
+  iface->search_finish = ide_code_index_search_provider_search_finish;
+}
+
+static void
+ide_code_index_search_provider_init (IdeCodeIndexSearchProvider *self)
+{
+}
+
+static void
+ide_code_index_search_provider_class_init (IdeCodeIndexSearchProviderClass *klass)
+{
+}
\ No newline at end of file
diff --git a/plugins/code-index/ide-code-index-search-provider.h 
b/plugins/code-index/ide-code-index-search-provider.h
new file mode 100644
index 0000000..630962b
--- /dev/null
+++ b/plugins/code-index/ide-code-index-search-provider.h
@@ -0,0 +1,33 @@
+/* ide-code-index-search-provider.h
+ *
+ * Copyright (C) 2017 Anoop Chandu <anoopchandu96 gmail 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/>.
+ */
+
+#ifndef IDE_CODE_INDEX_SEARCH_PROVIDER_H
+#define IDE_CODE_INDEX_SEARCH_PROVIDER_H
+
+#include <ide.h>
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_CODE_INDEX_SEARCH_PROVIDER (ide_code_index_search_provider_get_type ())
+
+G_DECLARE_FINAL_TYPE (IdeCodeIndexSearchProvider, ide_code_index_search_provider,
+                      IDE, CODE_INDEX_SEARCH_PROVIDER, IdeObject)
+
+G_END_DECLS
+
+#endif /* IDE_CODE_INDEX_SEARCH_PROVIDER_H */
\ No newline at end of file


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