[gnome-builder] libide: add some libide helpers for completion providers



commit 339e2ebe211bbd634762bc022930875ffc82ca3f
Author: Christian Hergert <christian hergert me>
Date:   Mon Sep 28 06:18:42 2015 -0700

    libide: add some libide helpers for completion providers

 libide/ide-completion-provider.c |   53 ++++++++++++++++++++++++++++++++++++++
 libide/ide-completion-provider.h |    5 +++-
 2 files changed, 57 insertions(+), 1 deletions(-)
---
diff --git a/libide/ide-completion-provider.c b/libide/ide-completion-provider.c
index a7fc324..c25636a 100644
--- a/libide/ide-completion-provider.c
+++ b/libide/ide-completion-provider.c
@@ -33,3 +33,56 @@ ide_completion_provider_default_init (IdeCompletionProviderInterface *iface)
                                                             IDE_TYPE_CONTEXT,
                                                             (G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | 
G_PARAM_STATIC_STRINGS)));
 }
+
+gboolean
+ide_completion_provider_context_in_comment (GtkSourceCompletionContext *context)
+{
+  GtkTextIter iter;
+
+  g_return_val_if_fail (GTK_SOURCE_IS_COMPLETION_CONTEXT (context), FALSE);
+
+  if (gtk_source_completion_context_get_iter (context, &iter))
+    {
+      GtkSourceBuffer *buffer = GTK_SOURCE_BUFFER (gtk_text_iter_get_buffer (&iter));
+
+      if (gtk_source_buffer_iter_has_context_class (buffer, &iter, "comment"))
+        return TRUE;
+
+      if (!gtk_text_iter_starts_line (&iter))
+        {
+          gtk_text_iter_backward_char (&iter);
+          if (gtk_source_buffer_iter_has_context_class (buffer, &iter, "comment"))
+            return TRUE;
+        }
+    }
+
+  return FALSE;
+}
+
+gchar *
+ide_completion_provider_context_current_word (GtkSourceCompletionContext *context)
+{
+  GtkTextIter end;
+  GtkTextIter begin;
+  gunichar ch = 0;
+
+  g_return_val_if_fail (GTK_SOURCE_IS_COMPLETION_CONTEXT (context), NULL);
+
+  if (!gtk_source_completion_context_get_iter (context, &end))
+    return NULL;
+
+  begin = end;
+
+  do
+    {
+      if (!gtk_text_iter_backward_char (&begin))
+        break;
+      ch = gtk_text_iter_get_char (&begin);
+    }
+  while (g_unichar_isalnum (ch) || (ch == '_'));
+
+  if (ch && !g_unichar_isalnum (ch) && (ch != '_'))
+    gtk_text_iter_forward_char (&begin);
+
+  return gtk_text_iter_get_slice (&begin, &end);
+}
diff --git a/libide/ide-completion-provider.h b/libide/ide-completion-provider.h
index 4d99397..3fbdea0 100644
--- a/libide/ide-completion-provider.h
+++ b/libide/ide-completion-provider.h
@@ -37,11 +37,14 @@ struct _IdeCompletionProviderInterface
 {
   GtkSourceCompletionProviderIface parent_interface;
 
+  /* Pacify Vala */
   void (*set_context) (IdeCompletionProvider *self,
                        IdeContext            *context);
 };
 
-GType ide_completion_provider_get_type (void);
+GType     ide_completion_provider_get_type             (void);
+gboolean  ide_completion_provider_context_in_comment   (GtkSourceCompletionContext *context);
+gchar    *ide_completion_provider_context_current_word (GtkSourceCompletionContext *context);
 
 G_END_DECLS
 


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