/* CompletionProvider.c generated by valac 0.56.19, the Vala compiler
 * generated from CompletionProvider.vala, do not modify */

#include <glib-object.h>
#include <gtksourceview/gtksource.h>
#include <gtk/gtk.h>
#include <glib.h>
#include <gio/gio.h>
#include <stdlib.h>
#include <string.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define TUBA_TYPE_COMPLETION_PROVIDER (tuba_completion_provider_get_type ())
#define TUBA_COMPLETION_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TUBA_TYPE_COMPLETION_PROVIDER, TubaCompletionProvider))
#define TUBA_COMPLETION_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TUBA_TYPE_COMPLETION_PROVIDER, TubaCompletionProviderClass))
#define TUBA_IS_COMPLETION_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TUBA_TYPE_COMPLETION_PROVIDER))
#define TUBA_IS_COMPLETION_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TUBA_TYPE_COMPLETION_PROVIDER))
#define TUBA_COMPLETION_PROVIDER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TUBA_TYPE_COMPLETION_PROVIDER, TubaCompletionProviderClass))

typedef struct _TubaCompletionProvider TubaCompletionProvider;
typedef struct _TubaCompletionProviderClass TubaCompletionProviderClass;
typedef struct _TubaCompletionProviderPrivate TubaCompletionProviderPrivate;
enum  {
	TUBA_COMPLETION_PROVIDER_0_PROPERTY,
	TUBA_COMPLETION_PROVIDER_TRIGGER_CHAR_PROPERTY,
	TUBA_COMPLETION_PROVIDER_IS_CAPTURING_INPUT_PROPERTY,
	TUBA_COMPLETION_PROVIDER_NUM_PROPERTIES
};
static GParamSpec* tuba_completion_provider_properties[TUBA_COMPLETION_PROVIDER_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _TubaCompletionProviderPopulateAsyncData TubaCompletionProviderPopulateAsyncData;

struct _TubaCompletionProvider {
	GObject parent_instance;
	TubaCompletionProviderPrivate * priv;
};

struct _TubaCompletionProviderClass {
	GObjectClass parent_class;
	gboolean (*is_trigger) (TubaCompletionProvider* self, GtkTextIter* iter, gunichar ch);
	void (*refilter) (TubaCompletionProvider* self, GtkSourceCompletionContext* context, GListModel* model);
	void (*activate) (TubaCompletionProvider* self, GtkSourceCompletionContext* context, GtkSourceCompletionProposal* proposal);
	void (*display) (TubaCompletionProvider* self, GtkSourceCompletionContext* context, GtkSourceCompletionProposal* proposal, GtkSourceCompletionCell* cell);
	void (*suggest) (TubaCompletionProvider* self, const gchar* word, GCancellable* cancellable, GAsyncReadyCallback _callback_, gpointer _user_data_);
	GListModel* (*suggest_finish) (TubaCompletionProvider* self, GAsyncResult* _res_, GError** error);
	gboolean (*word_stop) (TubaCompletionProvider* self, gunichar ch);
	gchar* (*get_formatted_text) (TubaCompletionProvider* self, GtkSourceCompletionProposal* proposal);
};

struct _TubaCompletionProviderPrivate {
	gunichar _trigger_char;
	gboolean _is_capturing_input;
};

struct _TubaCompletionProviderPopulateAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	TubaCompletionProvider* self;
	GtkSourceCompletionContext* context;
	GCancellable* cancellable;
	GListModel* result;
	GtkTextIter start;
	GtkTextIter end;
	GtkTextIter _tmp0_;
	GtkTextIter _tmp1_;
	GtkTextIter _tmp2_;
	gboolean _tmp3_;
	GListStore* _tmp4_;
	GListModel* _tmp5_;
	gchar* word;
	GtkTextIter _tmp6_;
	gchar* _tmp7_;
	const gchar* _tmp8_;
	GListStore* _tmp9_;
	GListModel* _tmp10_;
	GListModel* _tmp11_;
	const gchar* _tmp12_;
	GListModel* _tmp13_;
	GListModel* _tmp14_;
	GError* _inner_error0_;
};

static gint TubaCompletionProvider_private_offset;
static gpointer tuba_completion_provider_parent_class = NULL;
VALA_EXTERN GListStore* tuba_completion_provider_EMPTY;
GListStore* tuba_completion_provider_EMPTY = NULL;
static GtkSourceCompletionProviderInterface * tuba_completion_provider_gtk_source_completion_provider_parent_iface = NULL;

VALA_EXTERN GType tuba_completion_provider_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (TubaCompletionProvider, g_object_unref)
VALA_EXTERN gboolean tuba_completion_provider_is_trigger (TubaCompletionProvider* self,
                                              GtkTextIter* iter,
                                              gunichar ch);
VALA_EXTERN void tuba_completion_provider_refilter (TubaCompletionProvider* self,
                                        GtkSourceCompletionContext* context,
                                        GListModel* model);
VALA_EXTERN void tuba_completion_provider_activate (TubaCompletionProvider* self,
                                        GtkSourceCompletionContext* context,
                                        GtkSourceCompletionProposal* proposal);
VALA_EXTERN void tuba_completion_provider_display (TubaCompletionProvider* self,
                                       GtkSourceCompletionContext* context,
                                       GtkSourceCompletionProposal* proposal,
                                       GtkSourceCompletionCell* cell);
VALA_EXTERN gboolean tuba_completion_provider_word_stop (TubaCompletionProvider* self,
                                             gunichar ch);
VALA_EXTERN gchar* tuba_completion_provider_get_formatted_text (TubaCompletionProvider* self,
                                                    GtkSourceCompletionProposal* proposal);
static gboolean tuba_completion_provider_real_is_trigger (TubaCompletionProvider* self,
                                                   GtkTextIter* iter,
                                                   gunichar ch);
VALA_EXTERN gboolean tuba_completion_provider_set_input_capture (TubaCompletionProvider* self,
                                                     gboolean state);
VALA_EXTERN gunichar tuba_completion_provider_get_trigger_char (TubaCompletionProvider* self);
VALA_EXTERN void tuba_completion_provider_set_is_capturing_input (TubaCompletionProvider* self,
                                                      gboolean value);
static void tuba_completion_provider_real_refilter (TubaCompletionProvider* self,
                                             GtkSourceCompletionContext* context,
                                             GListModel* model);
static void tuba_completion_provider_real_activate (TubaCompletionProvider* self,
                                             GtkSourceCompletionContext* context,
                                             GtkSourceCompletionProposal* proposal);
VALA_EXTERN void tuba_completion_provider_get_whole_word_iters (TubaCompletionProvider* self,
                                                    GtkSourceCompletionContext* context,
                                                    GtkTextIter* start,
                                                    GtkTextIter* end);
static void tuba_completion_provider_real_populate_async_data_free (gpointer _data);
static void tuba_completion_provider_real_populate_async (GtkSourceCompletionProvider* base,
                                                   GtkSourceCompletionContext* context,
                                                   GCancellable* cancellable,
                                                   GAsyncReadyCallback _callback_,
                                                   gpointer _user_data_);
static gboolean tuba_completion_provider_real_populate_async_co (TubaCompletionProviderPopulateAsyncData* _data_);
VALA_EXTERN gboolean tuba_completion_provider_get_is_capturing_input (TubaCompletionProvider* self);
VALA_EXTERN void tuba_completion_provider_suggest (TubaCompletionProvider* self,
                                       const gchar* word,
                                       GCancellable* cancellable,
                                       GAsyncReadyCallback _callback_,
                                       gpointer _user_data_);
VALA_EXTERN GListModel* tuba_completion_provider_suggest_finish (TubaCompletionProvider* self,
                                                     GAsyncResult* _res_,
                                                     GError** error);
static void tuba_completion_provider_populate_async_ready (GObject* source_object,
                                                    GAsyncResult* _res_,
                                                    gpointer _user_data_);
static void tuba_completion_provider_real_display (TubaCompletionProvider* self,
                                            GtkSourceCompletionContext* context,
                                            GtkSourceCompletionProposal* proposal,
                                            GtkSourceCompletionCell* cell);
VALA_EXTERN gchar* tuba_completion_provider_get_whole_word (TubaCompletionProvider* self,
                                                GtkSourceCompletionContext* context);
static gboolean _tuba_completion_provider_word_stop_gtk_text_char_predicate (gunichar ch,
                                                                      gpointer self);
static gboolean tuba_completion_provider_real_word_stop (TubaCompletionProvider* self,
                                                  gunichar ch);
static gchar* tuba_completion_provider_real_get_formatted_text (TubaCompletionProvider* self,
                                                         GtkSourceCompletionProposal* proposal);
VALA_EXTERN TubaCompletionProvider* tuba_completion_provider_construct (GType object_type);
VALA_EXTERN void tuba_completion_provider_set_trigger_char (TubaCompletionProvider* self,
                                                gunichar value);
static void tuba_completion_provider_finalize (GObject * obj);
static GType tuba_completion_provider_get_type_once (void);
static void _vala_tuba_completion_provider_get_property (GObject * object,
                                                  guint property_id,
                                                  GValue * value,
                                                  GParamSpec * pspec);
static void _vala_tuba_completion_provider_set_property (GObject * object,
                                                  guint property_id,
                                                  const GValue * value,
                                                  GParamSpec * pspec);

static inline gpointer
tuba_completion_provider_get_instance_private (TubaCompletionProvider* self)
{
	return G_STRUCT_MEMBER_P (self, TubaCompletionProvider_private_offset);
}

static gboolean
tuba_completion_provider_real_is_trigger (TubaCompletionProvider* self,
                                          GtkTextIter* iter,
                                          gunichar ch)
{
	gunichar _tmp0_;
	gboolean result;
	g_return_val_if_fail (iter != NULL, FALSE);
	_tmp0_ = self->priv->_trigger_char;
	result = tuba_completion_provider_set_input_capture (self, ch == _tmp0_);
	return result;
}

gboolean
tuba_completion_provider_is_trigger (TubaCompletionProvider* self,
                                     GtkTextIter* iter,
                                     gunichar ch)
{
	TubaCompletionProviderClass* _klass_;
	g_return_val_if_fail (self != NULL, FALSE);
	_klass_ = TUBA_COMPLETION_PROVIDER_GET_CLASS (self);
	if (_klass_->is_trigger) {
		return _klass_->is_trigger (self, iter, ch);
	}
	return FALSE;
}

gboolean
tuba_completion_provider_set_input_capture (TubaCompletionProvider* self,
                                            gboolean state)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	tuba_completion_provider_set_is_capturing_input (self, state);
	if (state) {
		g_debug ("CompletionProvider.vala:15: Capturing input");
	}
	result = state;
	return result;
}

static void
tuba_completion_provider_real_refilter (TubaCompletionProvider* self,
                                        GtkSourceCompletionContext* context,
                                        GListModel* model)
{
	g_return_if_fail (context != NULL);
	g_return_if_fail (model != NULL);
}

void
tuba_completion_provider_refilter (TubaCompletionProvider* self,
                                   GtkSourceCompletionContext* context,
                                   GListModel* model)
{
	TubaCompletionProviderClass* _klass_;
	g_return_if_fail (self != NULL);
	_klass_ = TUBA_COMPLETION_PROVIDER_GET_CLASS (self);
	if (_klass_->refilter) {
		_klass_->refilter (self, context, model);
	}
}

static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

static void
tuba_completion_provider_real_activate (TubaCompletionProvider* self,
                                        GtkSourceCompletionContext* context,
                                        GtkSourceCompletionProposal* proposal)
{
	GtkTextIter start = {0};
	GtkTextIter end = {0};
	GtkTextIter _tmp0_ = {0};
	GtkTextIter _tmp1_ = {0};
	GtkTextBuffer* buffer = NULL;
	GtkTextBuffer* _tmp2_;
	GtkTextBuffer* _tmp3_;
	gchar* new_content = NULL;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	gint _tmp8_;
	gint _tmp9_;
	g_return_if_fail (context != NULL);
	g_return_if_fail (proposal != NULL);
	tuba_completion_provider_get_whole_word_iters (self, context, &_tmp0_, &_tmp1_);
	start = _tmp0_;
	end = _tmp1_;
	_tmp2_ = gtk_text_iter_get_buffer (&start);
	_tmp3_ = _g_object_ref0 (_tmp2_);
	buffer = _tmp3_;
	_tmp4_ = tuba_completion_provider_get_formatted_text (self, proposal);
	_tmp5_ = _tmp4_;
	_tmp6_ = g_strconcat (_tmp5_, " ", NULL);
	_tmp7_ = _tmp6_;
	_g_free0 (_tmp5_);
	new_content = _tmp7_;
	gtk_text_buffer_begin_user_action (buffer);
	gtk_text_buffer_delete (buffer, &start, &end);
	_tmp8_ = strlen (new_content);
	_tmp9_ = _tmp8_;
	g_signal_emit_by_name (buffer, "insert-text", &start, new_content, _tmp9_);
	gtk_text_buffer_end_user_action (buffer);
	tuba_completion_provider_set_input_capture (self, FALSE);
	_g_free0 (new_content);
	_g_object_unref0 (buffer);
}

void
tuba_completion_provider_activate (TubaCompletionProvider* self,
                                   GtkSourceCompletionContext* context,
                                   GtkSourceCompletionProposal* proposal)
{
	TubaCompletionProviderClass* _klass_;
	g_return_if_fail (self != NULL);
	_klass_ = TUBA_COMPLETION_PROVIDER_GET_CLASS (self);
	if (_klass_->activate) {
		_klass_->activate (self, context, proposal);
	}
}

static void
tuba_completion_provider_real_populate_async_data_free (gpointer _data)
{
	TubaCompletionProviderPopulateAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->context);
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (TubaCompletionProviderPopulateAsyncData, _data_);
}

static void
tuba_completion_provider_real_populate_async (GtkSourceCompletionProvider* base,
                                              GtkSourceCompletionContext* context,
                                              GCancellable* cancellable,
                                              GAsyncReadyCallback _callback_,
                                              gpointer _user_data_)
{
	TubaCompletionProvider * self;
	TubaCompletionProviderPopulateAsyncData* _data_;
	TubaCompletionProvider* _tmp0_;
	GtkSourceCompletionContext* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (context != NULL);
	self = (TubaCompletionProvider*) base;
	_data_ = g_slice_new0 (TubaCompletionProviderPopulateAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, tuba_completion_provider_real_populate_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (context);
	_g_object_unref0 (_data_->context);
	_data_->context = _tmp1_;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	tuba_completion_provider_real_populate_async_co (_data_);
}

static GListModel*
tuba_completion_provider_populate_finish (GtkSourceCompletionProvider* base,
                                          GAsyncResult* _res_,
                                          GError** error)
{
	GListModel* result;
	TubaCompletionProviderPopulateAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static void
tuba_completion_provider_populate_async_ready (GObject* source_object,
                                               GAsyncResult* _res_,
                                               gpointer _user_data_)
{
	TubaCompletionProviderPopulateAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	tuba_completion_provider_real_populate_async_co (_data_);
}

static gboolean
tuba_completion_provider_real_populate_async_co (TubaCompletionProviderPopulateAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	memset (&_data_->_tmp0_, 0, sizeof (GtkTextIter));
	memset (&_data_->_tmp1_, 0, sizeof (GtkTextIter));
	tuba_completion_provider_get_whole_word_iters (_data_->self, _data_->context, &_data_->_tmp0_, &_data_->_tmp1_);
	_data_->start = _data_->_tmp0_;
	_data_->end = _data_->_tmp1_;
	_data_->_tmp2_ = _data_->start;
	tuba_completion_provider_is_trigger (_data_->self, &_data_->_tmp2_, gtk_text_iter_get_char (&_data_->start));
	_data_->_tmp3_ = _data_->self->priv->_is_capturing_input;
	if (!_data_->_tmp3_) {
		_data_->_tmp4_ = tuba_completion_provider_EMPTY;
		_data_->_tmp5_ = _g_object_ref0 ((GListModel*) _data_->_tmp4_);
		_data_->result = _data_->_tmp5_;
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp6_ = _data_->end;
	_data_->_tmp7_ = gtk_text_iter_get_text (&_data_->start, &_data_->_tmp6_);
	_data_->word = _data_->_tmp7_;
	_data_->_tmp8_ = _data_->word;
	if (g_strcmp0 (_data_->_tmp8_, "") == 0) {
		g_debug ("CompletionProvider.vala:52: Empty trigger");
		tuba_completion_provider_set_input_capture (_data_->self, FALSE);
		_data_->_tmp9_ = tuba_completion_provider_EMPTY;
		_data_->_tmp10_ = _g_object_ref0 ((GListModel*) _data_->_tmp9_);
		_data_->result = _data_->_tmp10_;
		_g_free0 (_data_->word);
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp12_ = _data_->word;
	_data_->_state_ = 1;
	tuba_completion_provider_suggest (_data_->self, _data_->_tmp12_, _data_->cancellable, tuba_completion_provider_populate_async_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp13_ = tuba_completion_provider_suggest_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
	_data_->_tmp11_ = _data_->_tmp13_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_free0 (_data_->word);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp14_ = _data_->_tmp11_;
	_data_->_tmp11_ = NULL;
	_data_->result = _data_->_tmp14_;
	_g_object_unref0 (_data_->_tmp11_);
	_g_free0 (_data_->word);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
tuba_completion_provider_real_display (TubaCompletionProvider* self,
                                       GtkSourceCompletionContext* context,
                                       GtkSourceCompletionProposal* proposal,
                                       GtkSourceCompletionCell* cell)
{
	g_critical ("Type `%s' does not implement abstract method `tuba_completion_provider_display'", g_type_name (G_TYPE_FROM_INSTANCE (self)));
	return;
}

void
tuba_completion_provider_display (TubaCompletionProvider* self,
                                  GtkSourceCompletionContext* context,
                                  GtkSourceCompletionProposal* proposal,
                                  GtkSourceCompletionCell* cell)
{
	TubaCompletionProviderClass* _klass_;
	g_return_if_fail (self != NULL);
	_klass_ = TUBA_COMPLETION_PROVIDER_GET_CLASS (self);
	if (_klass_->display) {
		_klass_->display (self, context, proposal, cell);
	}
}

void
tuba_completion_provider_suggest (TubaCompletionProvider* self,
                                  const gchar* word,
                                  GCancellable* cancellable,
                                  GAsyncReadyCallback _callback_,
                                  gpointer _user_data_)
{
	TubaCompletionProviderClass* _klass_;
	_klass_ = TUBA_COMPLETION_PROVIDER_GET_CLASS (self);
	if (_klass_->suggest) {
		_klass_->suggest (self, word, cancellable, _callback_, _user_data_);
	}
}

GListModel*
tuba_completion_provider_suggest_finish (TubaCompletionProvider* self,
                                         GAsyncResult* _res_,
                                         GError** error)
{
	TubaCompletionProviderClass* _klass_;
	_klass_ = TUBA_COMPLETION_PROVIDER_GET_CLASS (self);
	if (_klass_->suggest_finish) {
		return _klass_->suggest_finish (self, _res_, error);
	}
	return NULL;
}

gchar*
tuba_completion_provider_get_whole_word (TubaCompletionProvider* self,
                                         GtkSourceCompletionContext* context)
{
	GtkTextIter start = {0};
	GtkTextIter end = {0};
	GtkTextIter _tmp0_ = {0};
	GtkTextIter _tmp1_ = {0};
	GtkTextIter _tmp2_;
	gchar* _tmp3_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (context != NULL, NULL);
	tuba_completion_provider_get_whole_word_iters (self, context, &_tmp0_, &_tmp1_);
	start = _tmp0_;
	end = _tmp1_;
	_tmp2_ = end;
	_tmp3_ = gtk_text_iter_get_text (&start, &_tmp2_);
	result = _tmp3_;
	return result;
}

static gboolean
_tuba_completion_provider_word_stop_gtk_text_char_predicate (gunichar ch,
                                                             gpointer self)
{
	gboolean result;
	result = tuba_completion_provider_word_stop ((TubaCompletionProvider*) self, ch);
	return result;
}

void
tuba_completion_provider_get_whole_word_iters (TubaCompletionProvider* self,
                                               GtkSourceCompletionContext* context,
                                               GtkTextIter* start,
                                               GtkTextIter* end)
{
	GtkTextIter _vala_start = {0};
	GtkTextIter _vala_end = {0};
	GtkTextIter _tmp0_ = {0};
	GtkTextIter _tmp1_ = {0};
	gboolean _tmp2_ = FALSE;
	g_return_if_fail (self != NULL);
	g_return_if_fail (context != NULL);
	gtk_source_completion_context_get_bounds (context, &_tmp0_, &_tmp1_);
	_vala_start = _tmp0_;
	_vala_end = _tmp1_;
	if (gtk_text_iter_backward_find_char (&_vala_start, _tuba_completion_provider_word_stop_gtk_text_char_predicate, self, NULL)) {
		_tmp2_ = g_unichar_isspace (gtk_text_iter_get_char (&_vala_start));
	} else {
		_tmp2_ = FALSE;
	}
	if (_tmp2_) {
		gtk_text_iter_forward_char (&_vala_start);
	}
	gtk_text_iter_backward_char (&_vala_end);
	gtk_text_iter_forward_find_char (&_vala_end, _tuba_completion_provider_word_stop_gtk_text_char_predicate, self, NULL);
	if (start) {
		*start = _vala_start;
	}
	if (end) {
		*end = _vala_end;
	}
}

static gboolean
tuba_completion_provider_real_word_stop (TubaCompletionProvider* self,
                                         gunichar ch)
{
	gboolean result;
	result = g_unichar_isspace (ch);
	return result;
}

gboolean
tuba_completion_provider_word_stop (TubaCompletionProvider* self,
                                    gunichar ch)
{
	TubaCompletionProviderClass* _klass_;
	g_return_val_if_fail (self != NULL, FALSE);
	_klass_ = TUBA_COMPLETION_PROVIDER_GET_CLASS (self);
	if (_klass_->word_stop) {
		return _klass_->word_stop (self, ch);
	}
	return FALSE;
}

static gchar*
g_unichar_to_string (gunichar self)
{
	gchar* str = NULL;
	gchar* _tmp0_;
	gchar* result;
	_tmp0_ = g_new0 (gchar, 7);
	str = (gchar*) _tmp0_;
	g_unichar_to_utf8 (self, str);
	result = str;
	return result;
}

static gchar*
tuba_completion_provider_real_get_formatted_text (TubaCompletionProvider* self,
                                                  GtkSourceCompletionProposal* proposal)
{
	gunichar _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* result;
	g_return_val_if_fail (proposal != NULL, NULL);
	_tmp0_ = self->priv->_trigger_char;
	_tmp1_ = g_unichar_to_string (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = gtk_source_completion_proposal_get_typed_text (proposal);
	_tmp4_ = _tmp3_;
	_tmp5_ = g_strconcat (_tmp2_, _tmp4_, NULL);
	_tmp6_ = _tmp5_;
	_g_free0 (_tmp4_);
	_g_free0 (_tmp2_);
	result = _tmp6_;
	return result;
}

gchar*
tuba_completion_provider_get_formatted_text (TubaCompletionProvider* self,
                                             GtkSourceCompletionProposal* proposal)
{
	TubaCompletionProviderClass* _klass_;
	g_return_val_if_fail (self != NULL, NULL);
	_klass_ = TUBA_COMPLETION_PROVIDER_GET_CLASS (self);
	if (_klass_->get_formatted_text) {
		return _klass_->get_formatted_text (self, proposal);
	}
	return NULL;
}

TubaCompletionProvider*
tuba_completion_provider_construct (GType object_type)
{
	TubaCompletionProvider * self = NULL;
	self = (TubaCompletionProvider*) g_object_new (object_type, NULL);
	return self;
}

gunichar
tuba_completion_provider_get_trigger_char (TubaCompletionProvider* self)
{
	gunichar result;
	g_return_val_if_fail (self != NULL, 0U);
	result = self->priv->_trigger_char;
	return result;
}

void
tuba_completion_provider_set_trigger_char (TubaCompletionProvider* self,
                                           gunichar value)
{
	gunichar old_value;
	g_return_if_fail (self != NULL);
	old_value = tuba_completion_provider_get_trigger_char (self);
	if (old_value != value) {
		self->priv->_trigger_char = value;
		g_object_notify_by_pspec ((GObject *) self, tuba_completion_provider_properties[TUBA_COMPLETION_PROVIDER_TRIGGER_CHAR_PROPERTY]);
	}
}

gboolean
tuba_completion_provider_get_is_capturing_input (TubaCompletionProvider* self)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	result = self->priv->_is_capturing_input;
	return result;
}

void
tuba_completion_provider_set_is_capturing_input (TubaCompletionProvider* self,
                                                 gboolean value)
{
	gboolean old_value;
	g_return_if_fail (self != NULL);
	old_value = tuba_completion_provider_get_is_capturing_input (self);
	if (old_value != value) {
		self->priv->_is_capturing_input = value;
		g_object_notify_by_pspec ((GObject *) self, tuba_completion_provider_properties[TUBA_COMPLETION_PROVIDER_IS_CAPTURING_INPUT_PROPERTY]);
	}
}

static void
tuba_completion_provider_class_init (TubaCompletionProviderClass * klass,
                                     gpointer klass_data)
{
	GListStore* _tmp0_;
	tuba_completion_provider_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &TubaCompletionProvider_private_offset);
	((TubaCompletionProviderClass *) klass)->is_trigger = (gboolean (*) (TubaCompletionProvider*, GtkTextIter*, gunichar)) tuba_completion_provider_real_is_trigger;
	((TubaCompletionProviderClass *) klass)->refilter = (void (*) (TubaCompletionProvider*, GtkSourceCompletionContext*, GListModel*)) tuba_completion_provider_real_refilter;
	((TubaCompletionProviderClass *) klass)->activate = (void (*) (TubaCompletionProvider*, GtkSourceCompletionContext*, GtkSourceCompletionProposal*)) tuba_completion_provider_real_activate;
	((TubaCompletionProviderClass *) klass)->display = (void (*) (TubaCompletionProvider*, GtkSourceCompletionContext*, GtkSourceCompletionProposal*, GtkSourceCompletionCell*)) tuba_completion_provider_real_display;
	((TubaCompletionProviderClass *) klass)->word_stop = (gboolean (*) (TubaCompletionProvider*, gunichar)) tuba_completion_provider_real_word_stop;
	((TubaCompletionProviderClass *) klass)->get_formatted_text = (gchar* (*) (TubaCompletionProvider*, GtkSourceCompletionProposal*)) tuba_completion_provider_real_get_formatted_text;
	G_OBJECT_CLASS (klass)->get_property = _vala_tuba_completion_provider_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_tuba_completion_provider_set_property;
	G_OBJECT_CLASS (klass)->finalize = tuba_completion_provider_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), TUBA_COMPLETION_PROVIDER_TRIGGER_CHAR_PROPERTY, tuba_completion_provider_properties[TUBA_COMPLETION_PROVIDER_TRIGGER_CHAR_PROPERTY] = g_param_spec_uint ("trigger-char", "trigger-char", "trigger-char", 0, G_MAXUINT, 0U, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), TUBA_COMPLETION_PROVIDER_IS_CAPTURING_INPUT_PROPERTY, tuba_completion_provider_properties[TUBA_COMPLETION_PROVIDER_IS_CAPTURING_INPUT_PROPERTY] = g_param_spec_boolean ("is-capturing-input", "is-capturing-input", "is-capturing-input", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	_tmp0_ = g_list_store_new (G_TYPE_OBJECT);
	tuba_completion_provider_EMPTY = _tmp0_;
}

static void
tuba_completion_provider_gtk_source_completion_provider_interface_init (GtkSourceCompletionProviderInterface * iface,
                                                                        gpointer iface_data)
{
	tuba_completion_provider_gtk_source_completion_provider_parent_iface = g_type_interface_peek_parent (iface);
	iface->is_trigger = (gboolean (*) (GtkSourceCompletionProvider*, GtkTextIter*, gunichar)) tuba_completion_provider_is_trigger;
	iface->refilter = (void (*) (GtkSourceCompletionProvider*, GtkSourceCompletionContext*, GListModel*)) tuba_completion_provider_refilter;
	iface->activate = (void (*) (GtkSourceCompletionProvider*, GtkSourceCompletionContext*, GtkSourceCompletionProposal*)) tuba_completion_provider_activate;
	iface->populate_async = (void (*) (GtkSourceCompletionProvider*, GtkSourceCompletionContext*, GCancellable*, GAsyncReadyCallback, gpointer)) tuba_completion_provider_real_populate_async;
	iface->populate_finish = (GListModel* (*) (GtkSourceCompletionProvider*, GAsyncResult*, GError**)) tuba_completion_provider_populate_finish;
	iface->display = (void (*) (GtkSourceCompletionProvider*, GtkSourceCompletionContext*, GtkSourceCompletionProposal*, GtkSourceCompletionCell*)) tuba_completion_provider_display;
}

static void
tuba_completion_provider_instance_init (TubaCompletionProvider * self,
                                        gpointer klass)
{
	self->priv = tuba_completion_provider_get_instance_private (self);
	self->priv->_is_capturing_input = FALSE;
}

static void
tuba_completion_provider_finalize (GObject * obj)
{
	TubaCompletionProvider * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TUBA_TYPE_COMPLETION_PROVIDER, TubaCompletionProvider);
	G_OBJECT_CLASS (tuba_completion_provider_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
tuba_completion_provider_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (TubaCompletionProviderClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) tuba_completion_provider_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (TubaCompletionProvider), 0, (GInstanceInitFunc) tuba_completion_provider_instance_init, NULL };
	static const GInterfaceInfo gtk_source_completion_provider_info = { (GInterfaceInitFunc) tuba_completion_provider_gtk_source_completion_provider_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType tuba_completion_provider_type_id;
	tuba_completion_provider_type_id = g_type_register_static (G_TYPE_OBJECT, "TubaCompletionProvider", &g_define_type_info, G_TYPE_FLAG_ABSTRACT);
	g_type_add_interface_static (tuba_completion_provider_type_id, gtk_source_completion_provider_get_type (), &gtk_source_completion_provider_info);
	TubaCompletionProvider_private_offset = g_type_add_instance_private (tuba_completion_provider_type_id, sizeof (TubaCompletionProviderPrivate));
	return tuba_completion_provider_type_id;
}

GType
tuba_completion_provider_get_type (void)
{
	static GType tuba_completion_provider_type_id__once = 0;
	if (g_once_init_enter_pointer (&tuba_completion_provider_type_id__once)) {
		GType tuba_completion_provider_type_id;
		tuba_completion_provider_type_id = tuba_completion_provider_get_type_once ();
		g_once_init_leave_pointer (&tuba_completion_provider_type_id__once, tuba_completion_provider_type_id);
	}
	return tuba_completion_provider_type_id__once;
}

static void
_vala_tuba_completion_provider_get_property (GObject * object,
                                             guint property_id,
                                             GValue * value,
                                             GParamSpec * pspec)
{
	TubaCompletionProvider * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, TUBA_TYPE_COMPLETION_PROVIDER, TubaCompletionProvider);
	switch (property_id) {
		case TUBA_COMPLETION_PROVIDER_TRIGGER_CHAR_PROPERTY:
		g_value_set_uint (value, tuba_completion_provider_get_trigger_char (self));
		break;
		case TUBA_COMPLETION_PROVIDER_IS_CAPTURING_INPUT_PROPERTY:
		g_value_set_boolean (value, tuba_completion_provider_get_is_capturing_input (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_tuba_completion_provider_set_property (GObject * object,
                                             guint property_id,
                                             const GValue * value,
                                             GParamSpec * pspec)
{
	TubaCompletionProvider * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, TUBA_TYPE_COMPLETION_PROVIDER, TubaCompletionProvider);
	switch (property_id) {
		case TUBA_COMPLETION_PROVIDER_TRIGGER_CHAR_PROPERTY:
		tuba_completion_provider_set_trigger_char (self, g_value_get_uint (value));
		break;
		case TUBA_COMPLETION_PROVIDER_IS_CAPTURING_INPUT_PROPERTY:
		tuba_completion_provider_set_is_capturing_input (self, g_value_get_boolean (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

