[gtksourceview/wip/chergert/gsv-gtk4] snippets: handle empty language_id



commit 05593f7ddc672fa4a47f3229d80ea73c370fab20
Author: Christian Hergert <chergert redhat com>
Date:   Thu Sep 10 14:28:37 2020 -0700

    snippets: handle empty language_id
    
    We don't want to match everything when searching for these snippets.

 .../snippets/gtksourcecompletionsnippets.c                  |  8 ++++----
 gtksourceview/gtksourcesnippetbundle.c                      | 13 ++++++++++---
 gtksourceview/gtksourceview-snippets.c                      |  2 +-
 3 files changed, 15 insertions(+), 8 deletions(-)
---
diff --git a/gtksourceview/completion-providers/snippets/gtksourcecompletionsnippets.c 
b/gtksourceview/completion-providers/snippets/gtksourcecompletionsnippets.c
index 140b139a..abaf7227 100644
--- a/gtksourceview/completion-providers/snippets/gtksourcecompletionsnippets.c
+++ b/gtksourceview/completion-providers/snippets/gtksourcecompletionsnippets.c
@@ -157,7 +157,7 @@ gtk_source_completion_snippets_populate (GtkSourceCompletionProvider  *provider,
        GtkSourceSnippetManager *manager;
        GtkSourceLanguage *language;
        GtkSourceBuffer *buffer;
-       const gchar *language_id = NULL;
+       const gchar *language_id = "";
        GtkTextIter begin, end;
        GListModel *matches;
        GListModel *results = NULL;
@@ -200,9 +200,9 @@ gtk_source_completion_snippets_populate (GtkSourceCompletionProvider  *provider,
        if (results == NULL)
        {
                g_set_error (error,
-                            G_IO_ERROR,
-                            G_IO_ERROR_NOT_SUPPORTED,
-                            "No results");
+                            G_IO_ERROR,
+                            G_IO_ERROR_NOT_SUPPORTED,
+                            "No results");
        }
 
        return results;
diff --git a/gtksourceview/gtksourcesnippetbundle.c b/gtksourceview/gtksourcesnippetbundle.c
index 8a2cc651..f896b558 100644
--- a/gtksourceview/gtksourcesnippetbundle.c
+++ b/gtksourceview/gtksourcesnippetbundle.c
@@ -244,7 +244,7 @@ elements_end_element (GMarkupParseContext  *context,
        {
                if (state->languages != NULL && state->languages[0] != NULL)
                {
-                       GtkSourceSnippetInfo info;
+                       GtkSourceSnippetInfo info = {0};
 
                        info.identifier = state->last_identifier;
                        info.group = _gtk_source_snippet_manager_intern (state->manager, state->group);
@@ -637,8 +637,15 @@ info_matches (const GtkSourceSnippetInfo *info,
        if (group != NULL && g_strcmp0 (group, info->group) != 0)
                return FALSE;
 
-       if (language_id != NULL && g_strcmp0 (language_id, info->language) != 0)
-               return FALSE;
+       if (language_id != NULL)
+       {
+               /* If we got "" for language, skip it */
+               if (info->language != NULL && info->language[0] == 0)
+                       return FALSE;
+
+               if (g_strcmp0 (language_id, info->language) != 0)
+                       return FALSE;
+       }
 
        if (trigger != NULL)
        {
diff --git a/gtksourceview/gtksourceview-snippets.c b/gtksourceview/gtksourceview-snippets.c
index 5bd190a7..731c46b9 100644
--- a/gtksourceview/gtksourceview-snippets.c
+++ b/gtksourceview/gtksourceview-snippets.c
@@ -426,7 +426,7 @@ lookup_snippet_by_trigger (GtkSourceViewSnippets *snippets,
 {
        GtkSourceSnippetManager *manager;
        GtkSourceLanguage *language;
-       const gchar *language_id = NULL;
+       const gchar *language_id = "";
 
        g_assert (snippets != NULL);
        g_assert (word != NULL);


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