[gnome-builder] libide/search: track if search results were truncated



commit 8f00afbe7318e0d0a43493619a084989fa58bcbf
Author: Christian Hergert <chergert redhat com>
Date:   Tue Jul 19 19:12:16 2022 -0700

    libide/search: track if search results were truncated
    
    If the search results were truncated, we want to know so that we can
    ensure that we requery results in followup searches.
    
    We will need this to be able to fix #1716 so that we can force requery
    of search providers if we got a truncated search result.

 src/libide/lsp/ide-lsp-search-provider.c               |  1 +
 src/libide/search/ide-search-engine.c                  | 16 +++++++++++++++-
 src/libide/search/ide-search-provider.c                | 18 +++++++++++++++++-
 src/libide/search/ide-search-provider.h                |  2 ++
 src/plugins/code-index/ide-code-index-index.c          |  7 +++++++
 src/plugins/code-index/ide-code-index-index.h          |  1 +
 .../code-index/ide-code-index-search-provider.c        | 15 +++++++++++----
 src/plugins/file-search/gbp-file-search-provider.c     |  6 ++++++
 src/plugins/menu-search/gbp-menu-search-provider.c     |  1 +
 src/plugins/shellcmd/gbp-shellcmd-search-provider.c    |  1 +
 src/plugins/symbol-tree/gbp-symbol-search-provider.c   |  1 +
 11 files changed, 63 insertions(+), 6 deletions(-)
---
diff --git a/src/libide/lsp/ide-lsp-search-provider.c b/src/libide/lsp/ide-lsp-search-provider.c
index 18b50e65d..2fb8f494f 100644
--- a/src/libide/lsp/ide-lsp-search-provider.c
+++ b/src/libide/lsp/ide-lsp-search-provider.c
@@ -273,6 +273,7 @@ ide_lsp_search_provider_search_async (IdeSearchProvider   *provider,
 static GListModel *
 ide_lsp_search_provider_search_finish (IdeSearchProvider  *provider,
                                        GAsyncResult       *result,
+                                       gboolean           *truncated,
                                        GError            **error)
 {
   GListModel *ret;
diff --git a/src/libide/search/ide-search-engine.c b/src/libide/search/ide-search-engine.c
index cb473bb96..94bcc4ef5 100644
--- a/src/libide/search/ide-search-engine.c
+++ b/src/libide/search/ide-search-engine.c
@@ -46,6 +46,7 @@ typedef struct
 {
   IdeSearchProvider *provider;
   GListModel        *results;
+  guint              truncated : 1;
 } SortInfo;
 
 typedef struct
@@ -264,18 +265,31 @@ ide_search_engine_search_cb (GObject      *object,
   for (guint i = 0; i < r->sorted->len; i++)
     {
       SortInfo *info = &g_array_index (r->sorted, SortInfo, i);
+      gboolean truncated = FALSE;
 
       if (info->provider != provider)
         continue;
 
       g_assert (info->results == NULL);
 
-      if (!(info->results = ide_search_provider_search_finish (provider, result, &error)))
+      if (!(info->results = ide_search_provider_search_finish (provider, result, &truncated, &error)))
         {
+          IDE_TRACE_MSG ("%s: %s", G_OBJECT_TYPE_NAME (provider), error->message);
+
           if (!ide_error_ignore (error))
             g_warning ("%s", error->message);
         }
 
+      info->truncated = info->results != NULL && truncated;
+
+#ifdef IDE_ENABLE_TRACE
+      if (info->results != NULL)
+        IDE_TRACE_MSG ("%s: %d results%s",
+                       G_OBJECT_TYPE_NAME (provider),
+                       g_list_model_get_n_items (info->results),
+                       info->truncated ? " [truncated]" : "");
+#endif
+
       break;
     }
 
diff --git a/src/libide/search/ide-search-provider.c b/src/libide/search/ide-search-provider.c
index 62aaf6653..6cd21b191 100644
--- a/src/libide/search/ide-search-provider.c
+++ b/src/libide/search/ide-search-provider.c
@@ -51,10 +51,14 @@ ide_search_provider_real_search_async (IdeSearchProvider   *self,
 static GListModel *
 ide_search_provider_real_search_finish (IdeSearchProvider  *self,
                                         GAsyncResult       *result,
+                                        gboolean           *truncated,
                                         GError            **error)
 {
   g_assert (IDE_IS_SEARCH_PROVIDER (self));
   g_assert (IDE_IS_TASK (result));
+  g_assert (truncated != NULL);
+
+  *truncated = FALSE;
 
   return ide_task_propagate_pointer (IDE_TASK (result), error);
 }
@@ -110,18 +114,24 @@ ide_search_provider_search_async (IdeSearchProvider   *self,
  * ide_search_provider_search_finish:
  * @self: a #IdeSearchProvider
  * @result: a #GAsyncResult
+ * @truncated: (nullable) (out): if the result was truncated
  * @error: a location for a #GError, or %NULL
  *
  * Completes a request to a search provider.
  *
+ * If the result was truncated because of too many search results, then
+ * @truncated is set to %TRUE.
+ *
  * Returns: (transfer full): a #GListModel of #IdeSearchResult
  */
 GListModel *
 ide_search_provider_search_finish (IdeSearchProvider  *self,
                                    GAsyncResult       *result,
+                                   gboolean           *truncated,
                                    GError            **error)
 {
   GListModel *ret;
+  gboolean empty_trunicated;
 
   IDE_ENTRY;
 
@@ -129,9 +139,15 @@ ide_search_provider_search_finish (IdeSearchProvider  *self,
   g_return_val_if_fail (IDE_IS_SEARCH_PROVIDER (self), NULL);
   g_return_val_if_fail (G_IS_ASYNC_RESULT (result), NULL);
 
-  ret = IDE_SEARCH_PROVIDER_GET_IFACE (self)->search_finish (self, result, error);
+  if (truncated == NULL)
+    truncated = &empty_trunicated;
+
+  *truncated = FALSE;
+
+  ret = IDE_SEARCH_PROVIDER_GET_IFACE (self)->search_finish (self, result, truncated, error);
 
   g_return_val_if_fail (!ret || G_IS_LIST_MODEL (ret), NULL);
+  g_return_val_if_fail (*truncated == TRUE || *truncated == FALSE, NULL);
 
   IDE_RETURN (ret);
 }
diff --git a/src/libide/search/ide-search-provider.h b/src/libide/search/ide-search-provider.h
index c824a2618..3fe3cf252 100644
--- a/src/libide/search/ide-search-provider.h
+++ b/src/libide/search/ide-search-provider.h
@@ -47,6 +47,7 @@ struct _IdeSearchProviderInterface
                                 gpointer              user_data);
   GListModel *(*search_finish) (IdeSearchProvider    *self,
                                 GAsyncResult         *result,
+                                gboolean             *truncated,
                                 GError              **error);
 };
 
@@ -64,6 +65,7 @@ void       ide_search_provider_search_async   (IdeSearchProvider    *self,
 IDE_AVAILABLE_IN_ALL
 GListModel *ide_search_provider_search_finish (IdeSearchProvider    *self,
                                                GAsyncResult         *result,
+                                               gboolean             *truncated,
                                                GError              **error);
 
 G_END_DECLS
diff --git a/src/plugins/code-index/ide-code-index-index.c b/src/plugins/code-index/ide-code-index-index.c
index 2358eac8a..badadab77 100644
--- a/src/plugins/code-index/ide-code-index-index.c
+++ b/src/plugins/code-index/ide-code-index-index.c
@@ -443,6 +443,9 @@ ide_code_index_index_query_cb (GObject      *object,
             }
         }
 
+      if (data->max_results == 0 && data->fuzzy_matches->len > 0)
+        g_object_set_data (G_OBJECT (task), "TRUNCATED", GINT_TO_POINTER (TRUE));
+
       ide_task_return_pointer (task,
                                g_steal_pointer (&results),
                                g_ptr_array_unref);
@@ -535,12 +538,16 @@ ide_code_index_index_populate_async (IdeCodeIndexIndex   *self,
 GPtrArray *
 ide_code_index_index_populate_finish (IdeCodeIndexIndex *self,
                                       GAsyncResult      *result,
+                                      gboolean          *truncated,
                                       GError           **error)
 {
   g_return_val_if_fail (IDE_IS_MAIN_THREAD (), NULL);
   g_return_val_if_fail (IDE_IS_CODE_INDEX_INDEX (self), NULL);
   g_return_val_if_fail (IDE_IS_TASK (result), NULL);
 
+  if (truncated)
+    *truncated = !!g_object_get_data (G_OBJECT (result), "TRUNCATED");
+
   return ide_task_propagate_pointer (IDE_TASK (result), error);
 }
 
diff --git a/src/plugins/code-index/ide-code-index-index.h b/src/plugins/code-index/ide-code-index-index.h
index 27681a3df..ac9794839 100644
--- a/src/plugins/code-index/ide-code-index-index.h
+++ b/src/plugins/code-index/ide-code-index-index.h
@@ -44,6 +44,7 @@ void               ide_code_index_index_populate_async  (IdeCodeIndexIndex    *s
                                                          gpointer              user_data);
 GPtrArray         *ide_code_index_index_populate_finish (IdeCodeIndexIndex    *self,
                                                          GAsyncResult         *result,
+                                                         gboolean             *truncated,
                                                          GError              **error);
 
 G_END_DECLS
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 b548af82f..0e3e987d7 100644
--- a/src/plugins/code-index/ide-code-index-search-provider.c
+++ b/src/plugins/code-index/ide-code-index-search-provider.c
@@ -37,6 +37,7 @@ populate_cb (GObject      *object,
   g_autoptr(GPtrArray) results = NULL;
   g_autoptr(GListStore) store = NULL;
   g_autoptr(GError) error = NULL;
+  gboolean truncated = FALSE;
 
   IDE_ENTRY;
 
@@ -45,12 +46,15 @@ populate_cb (GObject      *object,
   g_assert (G_IS_ASYNC_RESULT (result));
   g_assert (IDE_IS_TASK (task));
 
-  if (!(results = ide_code_index_index_populate_finish (index, result, &error)))
+  if (!(results = ide_code_index_index_populate_finish (index, result, &truncated, &error)))
     {
       ide_task_return_error (task, g_steal_pointer (&error));
       IDE_EXIT;
     }
 
+  if (truncated)
+    g_object_set_data (G_OBJECT (task), "TRUNCATED", GINT_TO_POINTER (truncated));
+
   store = g_list_store_new (IDE_TYPE_SEARCH_RESULT);
   g_list_store_splice (store, 0, 0, results->pdata, results->len);
   ide_task_return_pointer (task, g_steal_pointer (&store), g_object_unref);
@@ -114,9 +118,10 @@ ide_code_index_search_provider_search_async (IdeSearchProvider   *provider,
 }
 
 static GListModel *
-ide_code_index_search_provider_search_finish (IdeSearchProvider *provider,
-                                              GAsyncResult      *result,
-                                              GError           **error)
+ide_code_index_search_provider_search_finish (IdeSearchProvider  *provider,
+                                              GAsyncResult       *result,
+                                              gboolean           *truncated,
+                                              GError            **error)
 {
   GListModel *ret;
 
@@ -126,6 +131,8 @@ ide_code_index_search_provider_search_finish (IdeSearchProvider *provider,
   g_return_val_if_fail (IDE_IS_CODE_INDEX_SEARCH_PROVIDER (provider), NULL);
   g_return_val_if_fail (IDE_IS_TASK (result), NULL);
 
+  *truncated = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (result), "TRUNCATED"));
+
   ret = ide_task_propagate_pointer (IDE_TASK (result), error);
 
   g_return_val_if_fail (!ret || G_IS_LIST_MODEL (ret), NULL);
diff --git a/src/plugins/file-search/gbp-file-search-provider.c 
b/src/plugins/file-search/gbp-file-search-provider.c
index 5d7e7df12..3341e7eed 100644
--- a/src/plugins/file-search/gbp-file-search-provider.c
+++ b/src/plugins/file-search/gbp-file-search-provider.c
@@ -76,6 +76,9 @@ gbp_file_search_provider_search_async (IdeSearchProvider   *provider,
       IDE_EXIT;
     }
 
+  if (results->len >= max_results)
+    g_object_set_data (G_OBJECT (task), "TRUNCATED", GINT_TO_POINTER (TRUE));
+
   store = g_list_store_new (IDE_TYPE_SEARCH_RESULT);
   g_list_store_splice (store, 0, 0, results->pdata, results->len);
   ide_task_return_pointer (task, g_steal_pointer (&store), g_object_unref);
@@ -86,6 +89,7 @@ gbp_file_search_provider_search_async (IdeSearchProvider   *provider,
 static GListModel *
 gbp_file_search_provider_search_finish (IdeSearchProvider  *provider,
                                         GAsyncResult       *result,
+                                        gboolean           *truncated,
                                         GError            **error)
 {
   GListModel *ret;
@@ -98,6 +102,8 @@ gbp_file_search_provider_search_finish (IdeSearchProvider  *provider,
 
   ret = ide_task_propagate_pointer (IDE_TASK (result), error);
 
+  *truncated = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (result), "TRUNCATED"));
+
   IDE_RETURN (ret);
 }
 
diff --git a/src/plugins/menu-search/gbp-menu-search-provider.c 
b/src/plugins/menu-search/gbp-menu-search-provider.c
index c0ef1b649..c08478010 100644
--- a/src/plugins/menu-search/gbp-menu-search-provider.c
+++ b/src/plugins/menu-search/gbp-menu-search-provider.c
@@ -132,6 +132,7 @@ gbp_menu_search_provider_search_async (IdeSearchProvider   *provider,
 static GListModel *
 gbp_menu_search_provider_search_finish (IdeSearchProvider  *provider,
                                         GAsyncResult       *result,
+                                        gboolean           *truncated,
                                         GError            **error)
 {
   GListModel *ret;
diff --git a/src/plugins/shellcmd/gbp-shellcmd-search-provider.c 
b/src/plugins/shellcmd/gbp-shellcmd-search-provider.c
index 0e6950f55..7eef41256 100644
--- a/src/plugins/shellcmd/gbp-shellcmd-search-provider.c
+++ b/src/plugins/shellcmd/gbp-shellcmd-search-provider.c
@@ -112,6 +112,7 @@ gbp_shellcmd_search_provider_search_async (IdeSearchProvider   *provider,
 static GListModel *
 gbp_shellcmd_search_provider_search_finish (IdeSearchProvider  *provider,
                                             GAsyncResult       *result,
+                                            gboolean           *truncated,
                                             GError            **error)
 {
   GListModel *ret;
diff --git a/src/plugins/symbol-tree/gbp-symbol-search-provider.c 
b/src/plugins/symbol-tree/gbp-symbol-search-provider.c
index 8dadcfb6a..8ee8fc939 100644
--- a/src/plugins/symbol-tree/gbp-symbol-search-provider.c
+++ b/src/plugins/symbol-tree/gbp-symbol-search-provider.c
@@ -123,6 +123,7 @@ gbp_symbol_search_provider_search_async (IdeSearchProvider   *provider,
 static GListModel *
 gbp_symbol_search_provider_search_finish (IdeSearchProvider  *provider,
                                           GAsyncResult       *result,
+                                          gboolean           *truncated,
                                           GError            **error)
 {
   g_assert (IDE_IS_MAIN_THREAD ());


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