[gnome-builder] libide: add iter helper for in comment or string
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] libide: add iter helper for in comment or string
- Date: Fri, 30 Oct 2015 21:15:54 +0000 (UTC)
commit 6d45a38dca7b226f4bd7f798d05985d8bb8e830d
Author: Christian Hergert <chergert redhat com>
Date: Mon Oct 19 21:03:50 2015 -0700
libide: add iter helper for in comment or string
Completion providers that want to avoid completion inside of strings
and comments should use this to be less redundent.
libide/ide-completion-provider.c | 27 +++++++++++++++++++++++++++
libide/ide-completion-provider.h | 7 ++++---
2 files changed, 31 insertions(+), 3 deletions(-)
---
diff --git a/libide/ide-completion-provider.c b/libide/ide-completion-provider.c
index c25636a..a84dc12 100644
--- a/libide/ide-completion-provider.c
+++ b/libide/ide-completion-provider.c
@@ -59,6 +59,33 @@ ide_completion_provider_context_in_comment (GtkSourceCompletionContext *context)
return FALSE;
}
+gboolean
+ide_completion_provider_context_in_comment_or_string (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") ||
+ gtk_source_buffer_iter_has_context_class (buffer, &iter, "string"))
+ 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") ||
+ gtk_source_buffer_iter_has_context_class (buffer, &iter, "string"))
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
gchar *
ide_completion_provider_context_current_word (GtkSourceCompletionContext *context)
{
diff --git a/libide/ide-completion-provider.h b/libide/ide-completion-provider.h
index 3fbdea0..a5e5841 100644
--- a/libide/ide-completion-provider.h
+++ b/libide/ide-completion-provider.h
@@ -42,9 +42,10 @@ struct _IdeCompletionProviderInterface
IdeContext *context);
};
-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);
+GType ide_completion_provider_get_type (void);
+gboolean ide_completion_provider_context_in_comment (GtkSourceCompletionContext *context);
+gboolean ide_completion_provider_context_in_comment_or_string (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]