GSoC: GNOME Builder: Improving word completion phase 1

- 2 mins

Currently, Builder uses word completion from GtkSourceCompletionWords from the GtkSource* module. The idea is to mimick the word completion technique as in Vim Ctrl-p and Ctrl-n from the insertion cursor.

Scanning entities : Current buffer, open buffers and #includes

Basic scan steps:

The above process has to be made incremental. In layman terms, we cannot keep scanning the buffers all at once; we need to return back the results in an incremental manner and display them. Otherwise, this might stall the completion window drawing which would be waiting for all the proposals to get in first. In this regard, I learnt more about GdkFrameClock which is a better way to place our bids against the GTK+ drawing cycle.

GdkFrameClock can help us to update and paint every frame i.e. avoid frame drops. Every new frame will get up-to-date results as somewhat opposed to timeouts used. But still we can use timeouts right now along with making the process “incremental”, which would just work fine. Although, going ahead with this, we still need to keep in mind that GdkFrameClock is still a better way to do this.

A bit more verbose model of incremental process:

static gboolean scan_buffer_incrementally (GtkSourceBuffer *buffer, guint64 clock)
{
	..
	/* get insert cursor GtkTextIter and bounds of current buffer */
	insert_mark = gtk_text_buffer_get_insert (GTK_TEXT_BUFFER (buffer));
	gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (buffer), &insert_iter, insert_mark);
	gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (buffer), &start, &end);
	...

	while (TRUE)
	{
		if (g_get_monotonic_time() < clock)
			/* keep scanning the buffers */
		
		else /* time slab over */
			break;
	}

	/* adjust scan regions and iters to the next scan chunk */
	
}

static gboolean scan_buffer (GtkSourceBuffer *buffer)
{
	...

	clock = g_get_monotonic_time() + 5000;
	scan_buffer_incrementally (buffer, clock);
}


static void file_loaded(GObject *object, GAsyncResult *res, gpointer data)
{
	...
	g_timeout_add_full (G_PRIORITY_DEFAULT, 50, (GSourceFunc)scan_buffer, buffer, NULL);


}

Thank you Christian Hergert (hergertme) for overall guidance till now. Also thanks to Matthias Clasen (mclasen) for explaining me GTK+ drawing model and Debarshi Ray (rishi) for GdkFrameClock.

More posts follow soon. Lot of things under experimentation. Stay tuned. Happy Hacking. :)

Umang Jain

Umang Jain

Makes the machines talk

comments powered by Disqus
rss facebook twitter github youtube mail spotify instagram linkedin google pinterest medium