[gtksourceview] gtksourcesnippetbundle: add private API to use snippet info



commit 567a2dbb660e52c53da5faf361612d2ef0735fb4
Author: Christian Hergert <chergert redhat com>
Date:   Fri Jul 22 17:45:49 2022 -0700

    gtksourcesnippetbundle: add private API to use snippet info
    
    Instead of forcing through the inflation of GtkSourceSnippet, we can often
    use info's directly to avoid the extra memory/parsing overhead.
    
    We want to use this from the snippet completion in particular.

 gtksourceview/gtksourcesnippetbundle-private.h | 50 ++++++++++++++------------
 gtksourceview/gtksourcesnippetbundle.c         | 24 ++++++++++++-
 2 files changed, 50 insertions(+), 24 deletions(-)
---
diff --git a/gtksourceview/gtksourcesnippetbundle-private.h b/gtksourceview/gtksourcesnippetbundle-private.h
index 0e8a99b3..18beac6f 100644
--- a/gtksourceview/gtksourcesnippetbundle-private.h
+++ b/gtksourceview/gtksourcesnippetbundle-private.h
@@ -28,34 +28,38 @@ G_BEGIN_DECLS
 
 typedef struct
 {
-       int          identifier;
-       const gchar *group;
-       const gchar *name;
-       const gchar *trigger;
-       const gchar *language;
-       const gchar *description;
-       const gchar *text;
+       int         identifier;
+       const char *group;
+       const char *name;
+       const char *trigger;
+       const char *language;
+       const char *description;
+       const char *text;
 } GtkSourceSnippetInfo;
 
 #define GTK_SOURCE_TYPE_SNIPPET_BUNDLE (_gtk_source_snippet_bundle_get_type())
 
 G_DECLARE_FINAL_TYPE (GtkSourceSnippetBundle, _gtk_source_snippet_bundle, GTK_SOURCE, SNIPPET_BUNDLE, 
GObject)
 
-GtkSourceSnippetBundle  *_gtk_source_snippet_bundle_new           (void);
-GtkSourceSnippetBundle  *_gtk_source_snippet_bundle_new_from_file (const gchar              *path,
-                                                                   GtkSourceSnippetManager  *manager);
-void                     _gtk_source_snippet_bundle_merge         (GtkSourceSnippetBundle   *self,
-                                                                   GtkSourceSnippetBundle   *other);
-const gchar            **_gtk_source_snippet_bundle_list_groups   (GtkSourceSnippetBundle   *self);
-GtkSourceSnippet        *_gtk_source_snippet_bundle_get_snippet   (GtkSourceSnippetBundle   *self,
-                                                                   const gchar              *group,
-                                                                   const gchar              *language_id,
-                                                                   const gchar              *trigger);
-GListModel              *_gtk_source_snippet_bundle_list_matching (GtkSourceSnippetBundle   *self,
-                                                                   const gchar              *group,
-                                                                   const gchar              *language_id,
-                                                                   const gchar              *trigger_prefix);
-GPtrArray               *_gtk_source_snippet_bundle_parse_text    (const gchar              *text,
-                                                                   GError                  **error);
+GtkSourceSnippetBundle  *_gtk_source_snippet_bundle_new            (void);
+GtkSourceSnippetBundle  *_gtk_source_snippet_bundle_new_from_file  (const char                  *path,
+                                                                    GtkSourceSnippetManager     *manager);
+void                     _gtk_source_snippet_bundle_merge          (GtkSourceSnippetBundle      *self,
+                                                                    GtkSourceSnippetBundle      *other);
+const char             **_gtk_source_snippet_bundle_list_groups    (GtkSourceSnippetBundle      *self);
+GtkSourceSnippet        *_gtk_source_snippet_bundle_get_snippet    (GtkSourceSnippetBundle      *self,
+                                                                    const char                  *group,
+                                                                    const char                  *language_id,
+                                                                    const char                  *trigger);
+GListModel              *_gtk_source_snippet_bundle_list_matching  (GtkSourceSnippetBundle      *self,
+                                                                    const char                  *group,
+                                                                    const char                  *language_id,
+                                                                    const char                  
*trigger_prefix);
+GPtrArray               *_gtk_source_snippet_bundle_parse_text     (const char                  *text,
+                                                                    GError                     **error);
+GtkSourceSnippetInfo    *_gtk_source_snippet_bundle_get_info       (GtkSourceSnippetBundle      *self,
+                                                                    guint                        position);
+GtkSourceSnippet        *_gtk_source_snippet_bundle_create_snippet (GtkSourceSnippetBundle      *self,
+                                                                    const GtkSourceSnippetInfo  *info);
 
 G_END_DECLS
diff --git a/gtksourceview/gtksourcesnippetbundle.c b/gtksourceview/gtksourcesnippetbundle.c
index 560533c8..3d96736b 100644
--- a/gtksourceview/gtksourcesnippetbundle.c
+++ b/gtksourceview/gtksourcesnippetbundle.c
@@ -639,6 +639,16 @@ create_snippet_from_info (GtkSourceSnippetBundle     *self,
        return g_steal_pointer (&snippet);
 }
 
+GtkSourceSnippet *
+_gtk_source_snippet_bundle_create_snippet (GtkSourceSnippetBundle     *self,
+                                           const GtkSourceSnippetInfo *info)
+{
+       g_return_val_if_fail (GTK_SOURCE_IS_SNIPPET_BUNDLE (self), NULL);
+       g_return_val_if_fail (info != NULL, NULL);
+
+       return create_snippet_from_info (self, info);
+}
+
 static gboolean
 info_matches (const GtkSourceSnippetInfo *info,
               const gchar                *group,
@@ -715,7 +725,7 @@ _gtk_source_snippet_bundle_list_matching (GtkSourceSnippetBundle *self,
                                           const gchar            *trigger_prefix)
 {
        GtkSourceSnippetBundle *ret;
-       const gchar *last = NULL;
+       const char *last = NULL;
 
        g_return_val_if_fail (GTK_SOURCE_IS_SNIPPET_BUNDLE (self), NULL);
 
@@ -750,6 +760,18 @@ gtk_source_snippet_bundle_get_n_items (GListModel *model)
        return GTK_SOURCE_SNIPPET_BUNDLE (model)->infos->len;
 }
 
+GtkSourceSnippetInfo *
+_gtk_source_snippet_bundle_get_info (GtkSourceSnippetBundle *self,
+                                     guint                   position)
+{
+       if (position >= self->infos->len)
+       {
+               return NULL;
+       }
+
+       return &g_array_index (self->infos, GtkSourceSnippetInfo, position);
+}
+
 static gpointer
 gtk_source_snippet_bundle_get_item (GListModel *model,
                                     guint       position)


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