[gnome-builder/wip/chergert/completion] completion: dumb down completion API for Vala



commit bce4138a1bc808d3ac319e98c0f3b37db4a74378
Author: Christian Hergert <chergert redhat com>
Date:   Mon Jun 4 19:33:17 2018 -0700

    completion: dumb down completion API for Vala
    
    The vala compiler cannot generate correct code for async/finish pairs that
    have an out parameter in the async function. Furthermore, the error is
    generated silently and will cause us to attempt to thunk data rather than
    the callback function.
    
    For now, we can just dumb down the API to not give the results back
    immediately for cases where providers can incrementally update the result
    sets.
    
    Not ideal, but hey, at least things will work.
    
    See GNOME/vala#636 for the Vala bug.

 src/libide/completion/ide-completion-context.c     |  3 --
 src/libide/completion/ide-completion-provider.c    | 35 +++++++++++++---------
 src/libide/completion/ide-completion-provider.h    |  2 --
 .../langserv/ide-langserv-completion-provider.c    |  4 ---
 src/plugins/clang/ide-clang-completion-provider.c  |  3 --
 src/plugins/ctags/ide-ctags-completion-provider.c  |  6 ----
 .../python_gi_imports_completion.py                |  4 +--
 .../snippets/ide-snippet-completion-provider.c     |  3 --
 8 files changed, 22 insertions(+), 38 deletions(-)
---
diff --git a/src/libide/completion/ide-completion-context.c b/src/libide/completion/ide-completion-context.c
index 0ceeaf009..eb18c1258 100644
--- a/src/libide/completion/ide-completion-context.c
+++ b/src/libide/completion/ide-completion-context.c
@@ -546,16 +546,13 @@ _ide_completion_context_complete_async (IdeCompletionContext *self,
   for (guint i = 0; i < self->providers->len; i++)
     {
       const ProviderInfo *info = &g_array_index (self->providers, ProviderInfo, i);
-      g_autoptr(GListModel) results = NULL;
 
       dzl_cancellable_chain (info->cancellable, cancellable);
       ide_completion_provider_populate_async (info->provider,
                                               self,
                                               info->cancellable,
-                                              &results,
                                               ide_completion_context_populate_cb,
                                               g_object_ref (task));
-      ide_completion_context_set_results_for_provider (self, info->provider, results);
     }
 
   if (task_data->n_active == 0)
diff --git a/src/libide/completion/ide-completion-provider.c b/src/libide/completion/ide-completion-provider.c
index f270ebf12..fe96368e6 100644
--- a/src/libide/completion/ide-completion-provider.c
+++ b/src/libide/completion/ide-completion-provider.c
@@ -102,26 +102,18 @@ ide_completion_provider_get_title (IdeCompletionProvider *self)
  * @self: an #IdeCompletionProvider
  * @context: the completion context
  * @cancellable: (nullable): a #GCancellable, or %NULL
- * @proposals: (out) (optional): Optional location for a #GListModel that
- *   will be populated interactively.
  * @callback: (nullable) (scope async) (closure user_data): a #GAsyncReadyCallback
  *   or %NULL. Called when the provider has completed loading proposals.
  * @user_data: closure data for @callback
  *
  * Asynchronously requests the provider populate the contents.
  *
- * This operation should not complete until it has finished loading proposals.
- * If the provider can incrementally update the result set, it should set
- * @proposals and insert items before it completes the asynchronous operation.
- * That allows the UI to backfill the result list.
- *
  * Since: 3.28
  */
 void
 ide_completion_provider_populate_async (IdeCompletionProvider  *self,
                                         IdeCompletionContext   *context,
                                         GCancellable           *cancellable,
-                                        GListModel            **proposals,
                                         GAsyncReadyCallback     callback,
                                         gpointer                user_data)
 {
@@ -131,12 +123,7 @@ ide_completion_provider_populate_async (IdeCompletionProvider  *self,
   g_return_if_fail (IDE_IS_COMPLETION_CONTEXT (context));
   g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
 
-  IDE_COMPLETION_PROVIDER_GET_IFACE (self)->populate_async (self, context, cancellable, &results, callback, 
user_data);
-
-  if (proposals != NULL)
-    *proposals = g_steal_pointer (&results);
-  else
-    *proposals = NULL;
+  IDE_COMPLETION_PROVIDER_GET_IFACE (self)->populate_async (self, context, cancellable, callback, user_data);
 }
 
 /**
@@ -282,6 +269,23 @@ _ide_completion_provider_load (IdeCompletionProvider *self,
     IDE_COMPLETION_PROVIDER_GET_IFACE (self)->load (self, context);
 }
 
+/**
+ * ide_completion_provider_display_proposal:
+ * @self: a #IdeCompletionProvider
+ * @row: an #IdeCompletionListBoxRow
+ * @context: an #IdeCompletionContext
+ * @typed_text: (nullable): the typed text for the proposal
+ * @proposal: an #IdeCompletionProposal
+ *
+ * Requests that the provider update @row with values from @proposal.
+ *
+ * The design rational about having this operation part of the
+ * #IdeCompletionProvider interface (as opposed to the #IdeCompletionProposal
+ * interface) is that it allows for some optimizations and code simplification
+ * on behalf of completion providers.
+ *
+ * Since: 3.30
+ */
 void
 ide_completion_provider_display_proposal (IdeCompletionProvider   *self,
                                           IdeCompletionListBoxRow *row,
@@ -294,6 +298,9 @@ ide_completion_provider_display_proposal (IdeCompletionProvider   *self,
   g_return_if_fail (IDE_IS_COMPLETION_CONTEXT (context));
   g_return_if_fail (IDE_IS_COMPLETION_PROPOSAL (proposal));
 
+  if (typed_text == NULL)
+    typed_text = "";
+
   if (IDE_COMPLETION_PROVIDER_GET_IFACE (self)->display_proposal)
     IDE_COMPLETION_PROVIDER_GET_IFACE (self)->display_proposal (self, row, context, typed_text, proposal);
 }
diff --git a/src/libide/completion/ide-completion-provider.h b/src/libide/completion/ide-completion-provider.h
index 96b333410..94a9b8f33 100644
--- a/src/libide/completion/ide-completion-provider.h
+++ b/src/libide/completion/ide-completion-provider.h
@@ -44,7 +44,6 @@ struct _IdeCompletionProviderInterface
   void        (*populate_async)    (IdeCompletionProvider    *self,
                                     IdeCompletionContext     *context,
                                     GCancellable             *cancellable,
-                                    GListModel              **proposals,
                                     GAsyncReadyCallback       callback,
                                     gpointer                  user_data);
   GListModel *(*populate_finish)   (IdeCompletionProvider    *self,
@@ -82,7 +81,6 @@ IDE_AVAILABLE_IN_3_30
 void        ide_completion_provider_populate_async   (IdeCompletionProvider    *self,
                                                       IdeCompletionContext     *context,
                                                       GCancellable             *cancellable,
-                                                      GListModel              **proposals,
                                                       GAsyncReadyCallback       callback,
                                                       gpointer                  user_data);
 IDE_AVAILABLE_IN_3_30
diff --git a/src/libide/langserv/ide-langserv-completion-provider.c 
b/src/libide/langserv/ide-langserv-completion-provider.c
index 87b541aef..5f29cd66b 100644
--- a/src/libide/langserv/ide-langserv-completion-provider.c
+++ b/src/libide/langserv/ide-langserv-completion-provider.c
@@ -208,7 +208,6 @@ static void
 ide_langserv_completion_provider_populate_async (IdeCompletionProvider  *provider,
                                                  IdeCompletionContext   *context,
                                                  GCancellable           *cancellable,
-                                                 GListModel            **proposals,
                                                  GAsyncReadyCallback     callback,
                                                  gpointer                user_data)
 {
@@ -226,9 +225,6 @@ ide_langserv_completion_provider_populate_async (IdeCompletionProvider  *provide
 
   g_assert (IDE_IS_LANGSERV_COMPLETION_PROVIDER (self));
   g_assert (IDE_IS_COMPLETION_CONTEXT (context));
-  g_assert (proposals != NULL);
-
-  *proposals = NULL;
 
   task = ide_task_new (self, cancellable, callback, user_data);
   ide_task_set_source_tag (task, ide_langserv_completion_provider_populate_async);
diff --git a/src/plugins/clang/ide-clang-completion-provider.c 
b/src/plugins/clang/ide-clang-completion-provider.c
index e4bab4a8d..ebd6d24c4 100644
--- a/src/plugins/clang/ide-clang-completion-provider.c
+++ b/src/plugins/clang/ide-clang-completion-provider.c
@@ -211,7 +211,6 @@ static void
 ide_clang_completion_provider_populate_async (IdeCompletionProvider  *provider,
                                               IdeCompletionContext   *context,
                                               GCancellable           *cancellable,
-                                              GListModel            **proposals,
                                               GAsyncReadyCallback     callback,
                                               gpointer                user_data)
 {
@@ -232,8 +231,6 @@ ide_clang_completion_provider_populate_async (IdeCompletionProvider  *provider,
   if (self->proposals == NULL)
     self->proposals = ide_clang_proposals_new (self->client);
 
-  *proposals = g_object_ref (G_LIST_MODEL (self->proposals));
-
   ide_clang_proposals_populate_async (self->proposals,
                                       &begin,
                                       word,
diff --git a/src/plugins/ctags/ide-ctags-completion-provider.c 
b/src/plugins/ctags/ide-ctags-completion-provider.c
index 4390701b2..71c745698 100644
--- a/src/plugins/ctags/ide-ctags-completion-provider.c
+++ b/src/plugins/ctags/ide-ctags-completion-provider.c
@@ -271,7 +271,6 @@ static void
 ide_ctags_completion_provider_populate_async (IdeCompletionProvider  *provider,
                                               IdeCompletionContext   *context,
                                               GCancellable           *cancellable,
-                                              GListModel            **results,
                                               GAsyncReadyCallback     callback,
                                               gpointer                user_data)
 {
@@ -284,9 +283,6 @@ ide_ctags_completion_provider_populate_async (IdeCompletionProvider  *provider,
   g_assert (IDE_IS_CTAGS_COMPLETION_PROVIDER (self));
   g_assert (IDE_IS_COMPLETION_CONTEXT (context));
   g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
-  g_assert (results != NULL);
-
-  *results = NULL;
 
   task = ide_task_new (self, cancellable, callback, user_data);
   ide_task_set_source_tag (task, ide_ctags_completion_provider_populate_async);
@@ -313,8 +309,6 @@ ide_ctags_completion_provider_populate_async (IdeCompletionProvider  *provider,
                                     cancellable,
                                     ide_ctags_completion_provider_populate_cb,
                                     g_steal_pointer (&task));
-
-  *results = G_LIST_MODEL (g_steal_pointer (&model));
 }
 
 static GListModel *
diff --git a/src/plugins/python-gi-imports-completion/python_gi_imports_completion.py 
b/src/plugins/python-gi-imports-completion/python_gi_imports_completion.py
index 72b827bec..16f2e5b7d 100644
--- a/src/plugins/python-gi-imports-completion/python_gi_imports_completion.py
+++ b/src/plugins/python-gi-imports-completion/python_gi_imports_completion.py
@@ -53,7 +53,7 @@ class CompletionProvider(Ide.Object, Ide.CompletionProvider):
         text = context.get_line_text()
         if not text.startswith('from gi.repository import'):
             task.return_error(Ide.NotSupportedError())
-            return None,
+            return
 
         text = text.replace('from gi.repository import', '').strip().lower()
 
@@ -64,8 +64,6 @@ class CompletionProvider(Ide.Object, Ide.CompletionProvider):
 
         task.return_object(proposals)
 
-        return None,
-
     def do_populate_finish(self, task):
         return task.propagate_object()
 
diff --git a/src/plugins/snippets/ide-snippet-completion-provider.c 
b/src/plugins/snippets/ide-snippet-completion-provider.c
index f9dabcb60..708d41c05 100644
--- a/src/plugins/snippets/ide-snippet-completion-provider.c
+++ b/src/plugins/snippets/ide-snippet-completion-provider.c
@@ -90,7 +90,6 @@ static void
 ide_snippet_completion_provider_populate_async (IdeCompletionProvider  *provider,
                                                 IdeCompletionContext   *context,
                                                 GCancellable           *cancellable,
-                                                GListModel            **proposals,
                                                 GAsyncReadyCallback     callback,
                                                 gpointer                user_data)
 {
@@ -109,8 +108,6 @@ ide_snippet_completion_provider_populate_async (IdeCompletionProvider  *provider
   task = ide_task_new (self, cancellable, callback, user_data);
   ide_task_set_source_tag (task, ide_snippet_completion_provider_populate_async);
 
-  *proposals = g_object_ref (G_LIST_MODEL (self->model));
-
   if (ide_completion_context_get_bounds (context, &begin, &end))
     prefix = gtk_text_iter_get_slice (&begin, &end);
 


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