[gnome-builder/wip/gtk4-port: 637/1774] plugins/pygi: port python GI imports to C




commit c9f331b8279c9d27582faa65aa19bf1abfc52dcb
Author: Christian Hergert <chergert redhat com>
Date:   Tue Apr 19 16:31:39 2022 -0700

    plugins/pygi: port python GI imports to C
    
    Honestly this could have been fine in Python, but I have a distaste for
    async Gio-based Python code, even though I want async everywhere.

 meson_options.txt                                  |   1 +
 src/plugins/meson.build                            |   1 +
 .../gbp-pygi-completion-provider.c                 | 151 ++++++++++++++++
 .../gbp-pygi-completion-provider.h                 |  31 ++++
 .../gbp-pygi-proposal.c                            |  84 +++++++++
 .../gbp-pygi-proposal.h                            |  36 ++++
 .../gbp-pygi-proposals.c                           | 197 +++++++++++++++++++++
 .../gbp-pygi-proposals.h                           |  35 ++++
 .../python-gi-imports-completion/meson.build       |  25 ++-
 .../python-gi-imports-completion/pygi-plugin.c     |  37 ++++
 .../pygi.gresource.xml                             |   6 +
 ...on-gi-imports-completion.plugin => pygi.plugin} |   7 +-
 .../python_gi_imports_completion.py                | 127 -------------
 13 files changed, 599 insertions(+), 139 deletions(-)
---
diff --git a/meson_options.txt b/meson_options.txt
index 58caa71c9..540e980e7 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -67,6 +67,7 @@ option('plugin_notification', type: 'boolean')
 option('plugin_npm', type: 'boolean')
 option('plugin_phpize', type: 'boolean')
 option('plugin_podman', type: 'boolean')
+option('plugin_pygi', type: 'boolean')
 option('plugin_python_pack', type: 'boolean')
 option('plugin_qemu', type: 'boolean')
 option('plugin_quick_highlight', type: 'boolean')
diff --git a/src/plugins/meson.build b/src/plugins/meson.build
index 52118b51c..a3c8b2026 100644
--- a/src/plugins/meson.build
+++ b/src/plugins/meson.build
@@ -190,6 +190,7 @@ status += [
   'Npm .................................. : @0@'.format(get_option('plugin_npm')),
   'PHPize ............................... : @0@'.format(get_option('plugin_phpize')),
   'Podman ............................... : @0@'.format(get_option('plugin_podman')),
+  'PyGObject Imports .................... : @0@'.format(get_option('plugin_pygi')),
   'Python Pack .......................... : @0@'.format(get_option('plugin_python_pack')),
   'Qemu ................................. : @0@'.format(get_option('plugin_qemu')),
   'Quick Highlight ...................... : @0@'.format(get_option('plugin_quick_highlight')),
diff --git a/src/plugins/python-gi-imports-completion/gbp-pygi-completion-provider.c 
b/src/plugins/python-gi-imports-completion/gbp-pygi-completion-provider.c
new file mode 100644
index 000000000..abdf5a987
--- /dev/null
+++ b/src/plugins/python-gi-imports-completion/gbp-pygi-completion-provider.c
@@ -0,0 +1,151 @@
+/* gbp-pygi-completion-provider.c
+ *
+ * Copyright 2015 Elad Alfassa <elad fedoraproject org>
+ * Copyright 2015-2022 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
+ * 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/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "gbp-pygi-completion-provider"
+
+#include "config.h"
+
+#include <gtksourceview/gtksource.h>
+
+#include <libide-threading.h>
+
+#include "gbp-pygi-completion-provider.h"
+#include "gbp-pygi-proposal.h"
+#include "gbp-pygi-proposals.h"
+
+struct _GbpPygiCompletionProvider
+{
+  GObject parent_instance;
+};
+
+static void
+gbp_pygi_completion_provider_populate_async (GtkSourceCompletionProvider *provider,
+                                             GtkSourceCompletionContext  *context,
+                                             GCancellable                *cancellable,
+                                             GAsyncReadyCallback          callback,
+                                             gpointer                     user_data)
+{
+  g_autoptr(IdeTask) task = NULL;
+  g_autoptr(GbpPygiProposals) results = NULL;
+  g_autofree char *line_text = NULL;
+  g_autofree char *word = NULL;
+  GtkTextIter begin, end;
+
+  g_assert (GBP_IS_PYGI_COMPLETION_PROVIDER (provider));
+  g_assert (GTK_SOURCE_IS_COMPLETION_CONTEXT (context));
+  g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+  task = ide_task_new (provider, cancellable, callback, user_data);
+  ide_task_set_source_tag (task, gbp_pygi_completion_provider_populate_async);
+
+  gtk_source_completion_context_get_bounds (context, &begin, &end);
+  gtk_text_iter_set_line_offset (&begin, 0);
+  line_text = g_strstrip (gtk_text_iter_get_slice (&begin, &end));
+
+  if (!g_str_has_prefix (line_text, "from gi.repository import"))
+    {
+      ide_task_return_new_error (task,
+                                 G_IO_ERROR,
+                                 G_IO_ERROR_NOT_SUPPORTED,
+                                 "Not supported");
+      return;
+    }
+
+  word = gtk_source_completion_context_get_word (context);
+  results = gbp_pygi_proposals_new ();
+  gbp_pygi_proposals_filter (results, word);
+
+  ide_task_return_object (task, g_steal_pointer (&results));
+}
+
+static GListModel *
+gbp_pygi_completion_provider_populate_finish (GtkSourceCompletionProvider  *provider,
+                                              GAsyncResult                 *result,
+                                              GError                      **error)
+{
+  g_assert (GBP_IS_PYGI_COMPLETION_PROVIDER (provider));
+  g_assert (IDE_IS_TASK (result));
+
+  return ide_task_propagate_object (IDE_TASK (result), error);
+}
+
+static void
+gbp_pygi_completion_provider_display (GtkSourceCompletionProvider *provider,
+                                      GtkSourceCompletionContext  *context,
+                                      GtkSourceCompletionProposal *proposal,
+                                      GtkSourceCompletionCell     *cell)
+{
+  g_assert (GBP_IS_PYGI_COMPLETION_PROVIDER (provider));
+  g_assert (GTK_SOURCE_IS_COMPLETION_CONTEXT (context));
+  g_assert (GBP_IS_PYGI_PROPOSAL (proposal));
+  g_assert (GTK_SOURCE_IS_COMPLETION_CELL (cell));
+
+  gbp_pygi_proposal_display (GBP_PYGI_PROPOSAL (proposal), context, cell);
+}
+
+static void
+gbp_pygi_completion_provider_activate (GtkSourceCompletionProvider *provider,
+                                       GtkSourceCompletionContext  *context,
+                                       GtkSourceCompletionProposal *proposal)
+{
+  g_assert (GBP_IS_PYGI_COMPLETION_PROVIDER (provider));
+  g_assert (GTK_SOURCE_IS_COMPLETION_CONTEXT (context));
+  g_assert (GBP_IS_PYGI_PROPOSAL (proposal));
+
+}
+
+static void
+gbp_pygi_completion_provider_refilter (GtkSourceCompletionProvider *provider,
+                                       GtkSourceCompletionContext  *context,
+                                       GListModel                  *model)
+{
+  g_autofree char *word = NULL;
+
+  g_assert (GBP_IS_PYGI_COMPLETION_PROVIDER (provider));
+  g_assert (GTK_SOURCE_IS_COMPLETION_CONTEXT (context));
+  g_assert (GBP_IS_PYGI_PROPOSALS (model));
+
+  word = gtk_source_completion_context_get_word (context);
+  gbp_pygi_proposals_filter (GBP_PYGI_PROPOSALS (model), word);
+}
+
+static void
+completion_provider_iface_init (GtkSourceCompletionProviderInterface *iface)
+{
+  iface->populate_async = gbp_pygi_completion_provider_populate_async;
+  iface->populate_finish = gbp_pygi_completion_provider_populate_finish;
+  iface->display = gbp_pygi_completion_provider_display;
+  iface->activate = gbp_pygi_completion_provider_activate;
+  iface->refilter = gbp_pygi_completion_provider_refilter;
+}
+
+G_DEFINE_FINAL_TYPE_WITH_CODE (GbpPygiCompletionProvider, gbp_pygi_completion_provider, G_TYPE_OBJECT,
+                               G_IMPLEMENT_INTERFACE (GTK_SOURCE_TYPE_COMPLETION_PROVIDER, 
completion_provider_iface_init))
+
+static void
+gbp_pygi_completion_provider_class_init (GbpPygiCompletionProviderClass *klass)
+{
+}
+
+static void
+gbp_pygi_completion_provider_init (GbpPygiCompletionProvider *self)
+{
+}
diff --git a/src/plugins/python-gi-imports-completion/gbp-pygi-completion-provider.h 
b/src/plugins/python-gi-imports-completion/gbp-pygi-completion-provider.h
new file mode 100644
index 000000000..e5cfff6b2
--- /dev/null
+++ b/src/plugins/python-gi-imports-completion/gbp-pygi-completion-provider.h
@@ -0,0 +1,31 @@
+/* gbp-pygi-completion-provider.h
+ *
+ * Copyright 2022 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
+ * 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/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_PYGI_COMPLETION_PROVIDER (gbp_pygi_completion_provider_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpPygiCompletionProvider, gbp_pygi_completion_provider, GBP, 
PYGI_COMPLETION_PROVIDER, GObject)
+
+G_END_DECLS
diff --git a/src/plugins/python-gi-imports-completion/gbp-pygi-proposal.c 
b/src/plugins/python-gi-imports-completion/gbp-pygi-proposal.c
new file mode 100644
index 000000000..b9a090f45
--- /dev/null
+++ b/src/plugins/python-gi-imports-completion/gbp-pygi-proposal.c
@@ -0,0 +1,84 @@
+/* gbp-pygi-proposal.c
+ *
+ * Copyright 2022 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
+ * 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/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "gbp-pygi-proposal"
+
+#include "config.h"
+
+#include "gbp-pygi-proposal.h"
+
+struct _GbpPygiProposal
+{
+  GObject parent_instance;
+  const char *name;
+};
+
+G_DEFINE_FINAL_TYPE_WITH_CODE (GbpPygiProposal, gbp_pygi_proposal, G_TYPE_OBJECT,
+                               G_IMPLEMENT_INTERFACE (GTK_SOURCE_TYPE_COMPLETION_PROPOSAL, NULL))
+
+static void
+gbp_pygi_proposal_class_init (GbpPygiProposalClass *klass)
+{
+}
+
+static void
+gbp_pygi_proposal_init (GbpPygiProposal *self)
+{
+}
+
+GbpPygiProposal *
+gbp_pygi_proposal_new (const char *name)
+{
+  GbpPygiProposal *self;
+
+  self = g_object_new (GBP_TYPE_PYGI_PROPOSAL, NULL);
+  self->name = g_intern_string (name);
+
+  return self;
+}
+
+void
+gbp_pygi_proposal_display (GbpPygiProposal            *self,
+                           GtkSourceCompletionContext *context,
+                           GtkSourceCompletionCell    *cell)
+{
+  GtkSourceCompletionColumn column;
+
+  g_assert (GBP_IS_PYGI_PROPOSAL (self));
+  g_assert (GTK_SOURCE_IS_COMPLETION_CELL (cell));
+
+  column = gtk_source_completion_cell_get_column (cell);
+
+  if (column == GTK_SOURCE_COMPLETION_COLUMN_ICON)
+    {
+      gtk_source_completion_cell_set_icon_name (cell, "lang-namespace-symbolic");
+    }
+  else if (column == GTK_SOURCE_COMPLETION_COLUMN_TYPED_TEXT)
+    {
+      g_autofree char *typed_text = gtk_source_completion_context_get_word (context);
+      g_autoptr(PangoAttrList) attrs = gtk_source_completion_fuzzy_highlight (self->name, typed_text);
+
+      gtk_source_completion_cell_set_text_with_attributes (cell, self->name, attrs);
+    }
+  else
+    {
+      gtk_source_completion_cell_set_text (cell, NULL);
+    }
+}
diff --git a/src/plugins/python-gi-imports-completion/gbp-pygi-proposal.h 
b/src/plugins/python-gi-imports-completion/gbp-pygi-proposal.h
new file mode 100644
index 000000000..c34320035
--- /dev/null
+++ b/src/plugins/python-gi-imports-completion/gbp-pygi-proposal.h
@@ -0,0 +1,36 @@
+/* gbp-pygi-proposal.h
+ *
+ * Copyright 2022 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
+ * 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/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <gtksourceview/gtksource.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_PYGI_PROPOSAL (gbp_pygi_proposal_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpPygiProposal, gbp_pygi_proposal, GBP, PYGI_PROPOSAL, GObject)
+
+GbpPygiProposal *gbp_pygi_proposal_new     (const char                 *name);
+void             gbp_pygi_proposal_display (GbpPygiProposal            *self,
+                                            GtkSourceCompletionContext *context,
+                                            GtkSourceCompletionCell    *cell);
+
+G_END_DECLS
diff --git a/src/plugins/python-gi-imports-completion/gbp-pygi-proposals.c 
b/src/plugins/python-gi-imports-completion/gbp-pygi-proposals.c
new file mode 100644
index 000000000..861734e0f
--- /dev/null
+++ b/src/plugins/python-gi-imports-completion/gbp-pygi-proposals.c
@@ -0,0 +1,197 @@
+/* gbp-pygi-proposals.c
+ *
+ * Copyright 2022 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
+ * 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/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "gbp-pygi-proposals"
+
+#include "config.h"
+
+#include <girepository.h>
+
+#include "gbp-pygi-proposal.h"
+#include "gbp-pygi-proposals.h"
+
+struct _GbpPygiProposals
+{
+  GObject parent_instance;
+  GPtrArray *items;
+};
+
+static int
+sort_by_name (gconstpointer a,
+              gconstpointer b)
+{
+  const char * const *astr = a;
+  const char * const *bstr = b;
+
+  return g_strcmp0 (*astr, *bstr);
+}
+
+static GPtrArray *
+get_libraries (void)
+{
+  static GPtrArray *items;
+  static gint64 expire_at;
+  gint64 now;
+
+  now = g_get_monotonic_time ();
+  if (now > expire_at)
+    g_clear_pointer (&items, g_ptr_array_unref);
+
+  if (items == NULL)
+    {
+      g_autoptr(GHashTable) found = g_hash_table_new (NULL, NULL);
+      const GSList *search_path = g_irepository_get_search_path ();
+
+      items = g_ptr_array_new ();
+
+      for (const GSList *iter = search_path; iter; iter = iter->next)
+        {
+          const char *path = iter->data;
+          const char *name;
+          GDir *dir;
+
+          if (!g_file_test (path, G_FILE_TEST_IS_DIR))
+            continue;
+
+          if (!(dir = g_dir_open (path, 0, NULL)))
+            continue;
+
+          while ((name = g_dir_read_name (dir)))
+            {
+              const char *dash = strchr (name, '-');
+              g_autofree char *ns = NULL;
+              const char *intern;
+
+              if (dash == NULL || !g_str_has_suffix (name, ".typelib"))
+                continue;
+
+              ns = g_strndup (name, dash - name);
+              intern = g_intern_string (ns);
+              if (g_hash_table_contains (found, (char *)intern))
+                continue;
+
+              g_hash_table_add (found, (char *)intern);
+              g_ptr_array_add (items, (char *)intern);
+            }
+
+          g_dir_close (dir);
+        }
+
+      g_ptr_array_sort (items, sort_by_name);
+      expire_at = now + (G_USEC_PER_SEC * 5);
+    }
+
+  return items;
+}
+
+static guint
+gbp_pygi_proposals_get_n_items (GListModel *model)
+{
+  GbpPygiProposals *self = (GbpPygiProposals *)model;
+  return self->items ? self->items->len : 0;
+}
+
+static GType
+gbp_pygi_proposals_get_item_type (GListModel *model)
+{
+  return GBP_TYPE_PYGI_PROPOSAL;
+}
+
+static gpointer
+gbp_pygi_proposals_get_item (GListModel *model,
+                             guint       position)
+{
+  GbpPygiProposals *self = (GbpPygiProposals *)model;
+
+  if (self->items == NULL)
+    return NULL;
+
+  if (position >= self->items->len)
+    return NULL;
+
+  return gbp_pygi_proposal_new (g_ptr_array_index (self->items, position));
+}
+
+static void
+list_model_iface_init (GListModelInterface *iface)
+{
+  iface->get_n_items = gbp_pygi_proposals_get_n_items;
+  iface->get_item_type = gbp_pygi_proposals_get_item_type;
+  iface->get_item = gbp_pygi_proposals_get_item;
+}
+
+G_DEFINE_FINAL_TYPE_WITH_CODE (GbpPygiProposals, gbp_pygi_proposals, G_TYPE_OBJECT,
+                               G_IMPLEMENT_INTERFACE (G_TYPE_LIST_MODEL, list_model_iface_init))
+
+static void
+gbp_pygi_proposals_dispose (GObject *object)
+{
+  GbpPygiProposals *self = (GbpPygiProposals *)object;
+
+  g_clear_pointer (&self->items, g_ptr_array_unref);
+
+  G_OBJECT_CLASS (gbp_pygi_proposals_parent_class)->dispose (object);
+}
+
+static void
+gbp_pygi_proposals_class_init (GbpPygiProposalsClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->dispose = gbp_pygi_proposals_dispose;
+}
+
+static void
+gbp_pygi_proposals_init (GbpPygiProposals *self)
+{
+}
+
+GbpPygiProposals *
+gbp_pygi_proposals_new (void)
+{
+  return g_object_new (GBP_TYPE_PYGI_PROPOSALS, NULL);
+}
+
+void
+gbp_pygi_proposals_filter (GbpPygiProposals *self,
+                           const char       *word)
+{
+  guint old_len;
+  GPtrArray *all;
+
+  g_return_if_fail (GBP_IS_PYGI_PROPOSALS (self));
+
+  old_len = g_list_model_get_n_items (G_LIST_MODEL (self));
+  g_clear_pointer (&self->items, g_ptr_array_unref);
+
+  self->items = g_ptr_array_new ();
+  all = get_libraries ();
+
+  for (guint i = 0; i < all->len; i++)
+    {
+      const char *item = g_ptr_array_index (all, i);
+
+      if (g_str_has_prefix (item, word))
+        g_ptr_array_add (self->items, (char *)item);
+    }
+
+  if (old_len != self->items->len)
+    g_list_model_items_changed (G_LIST_MODEL (self), 0, old_len, self->items->len);
+}
diff --git a/src/plugins/python-gi-imports-completion/gbp-pygi-proposals.h 
b/src/plugins/python-gi-imports-completion/gbp-pygi-proposals.h
new file mode 100644
index 000000000..df8eeafee
--- /dev/null
+++ b/src/plugins/python-gi-imports-completion/gbp-pygi-proposals.h
@@ -0,0 +1,35 @@
+/* gbp-pygi-proposals.h
+ *
+ * Copyright 2022 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
+ * 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/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_PYGI_PROPOSALS (gbp_pygi_proposals_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpPygiProposals, gbp_pygi_proposals, GBP, PYGI_PROPOSALS, GObject)
+
+GbpPygiProposals *gbp_pygi_proposals_new    (void);
+void              gbp_pygi_proposals_filter (GbpPygiProposals *self,
+                                             const char       *prefix);
+
+G_END_DECLS
diff --git a/src/plugins/python-gi-imports-completion/meson.build 
b/src/plugins/python-gi-imports-completion/meson.build
index 312e6cc55..94c8ad041 100644
--- a/src/plugins/python-gi-imports-completion/meson.build
+++ b/src/plugins/python-gi-imports-completion/meson.build
@@ -1,9 +1,18 @@
-install_data('python_gi_imports_completion.py', install_dir: plugindir)
-
-configure_file(
-          input: 'python-gi-imports-completion.plugin',
-         output: 'python-gi-imports-completion.plugin',
-  configuration: config_h,
-        install: true,
-    install_dir: plugindir,
+if get_option('plugin_pygi')
+
+plugins_sources += files([
+  'pygi-plugin.c',
+  'gbp-pygi-completion-provider.c',
+  'gbp-pygi-proposals.c',
+  'gbp-pygi-proposal.c',
+])
+
+plugin_pygi_resources = gnome.compile_resources(
+  'pygi-resources',
+  'pygi.gresource.xml',
+  c_name: 'gbp_pygi',
 )
+
+plugins_sources += plugin_pygi_resources
+
+endif
diff --git a/src/plugins/python-gi-imports-completion/pygi-plugin.c 
b/src/plugins/python-gi-imports-completion/pygi-plugin.c
new file mode 100644
index 000000000..e55a64775
--- /dev/null
+++ b/src/plugins/python-gi-imports-completion/pygi-plugin.c
@@ -0,0 +1,37 @@
+/* pygi-plugin.c
+ *
+ * Copyright 2022 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
+ * 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/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "pygi-plugin"
+
+#include "config.h"
+
+#include <libpeas/peas.h>
+
+#include <libide-sourceview.h>
+
+#include "gbp-pygi-completion-provider.h"
+
+_IDE_EXTERN void
+_gbp_pygi_register_types (PeasObjectModule *module)
+{
+  peas_object_module_register_extension_type (module,
+                                              GTK_SOURCE_TYPE_COMPLETION_PROVIDER,
+                                              GBP_TYPE_PYGI_COMPLETION_PROVIDER);
+}
diff --git a/src/plugins/python-gi-imports-completion/pygi.gresource.xml 
b/src/plugins/python-gi-imports-completion/pygi.gresource.xml
new file mode 100644
index 000000000..9ec8ca166
--- /dev/null
+++ b/src/plugins/python-gi-imports-completion/pygi.gresource.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/plugins/pygi">
+    <file>pygi.plugin</file>
+  </gresource>
+</gresources>
diff --git a/src/plugins/python-gi-imports-completion/python-gi-imports-completion.plugin 
b/src/plugins/python-gi-imports-completion/pygi.plugin
similarity index 68%
rename from src/plugins/python-gi-imports-completion/python-gi-imports-completion.plugin
rename to src/plugins/python-gi-imports-completion/pygi.plugin
index 0b83c5219..627cba6a5 100644
--- a/src/plugins/python-gi-imports-completion/python-gi-imports-completion.plugin
+++ b/src/plugins/python-gi-imports-completion/pygi.plugin
@@ -1,10 +1,9 @@
 [Plugin]
 Authors=Christian Hergert <christian hergert me>
 Builtin=true
-Copyright=Copyright © 2015 Christian Hergert
+Copyright=Copyright © 2015-2022 Christian Hergert
 Description=Provides autocompletion for importing GObject Introspection enabled Libraries in Python.
-Loader=python3
-Module=python_gi_imports_completion
+Module=pygi
 Name=Python GObject Introspection Imports Auto-Completion
-X-Builder-ABI=@PACKAGE_ABI@
+Embedded=_gbp_pygi_register_types
 X-Completion-Provider-Languages=python,python3


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