skweez.net

Status report: The new architecture of the language support plugins

by ritze
26.07.2012

I'm finished with merging same code of the language support plugins.

The new architecture of the language support plugins

Now all same behaviour of the language plugins like when you start typing and got proposals are merged to one code base. The language support plugins implement their language-specific code through the new subinterface IAnjutaLanguageProvider.

The support class AnjutaLanguageProvider uses this implemented interface and executes the mechanism, which is all the same in each language support plugin. Additionally the language support plugins implement the IAnjutaLanguageProvider with the methods of AnjutaLanguageProvider. It's a little bit complicated, but look at the examples below.

I have one bad news: The vala plugin doesn't use the new architecture yet, because there are some problems with generating the GIR files, which I couldn't solve in the last week.

Implementation of preference keys

The following keys have to be implemented as boolean in a GSetting file:
  • calltip-enable
  • completion-enable
  • completion-space-after-func
  • completion-brace-after-func
  • completion-closebrace-after-func

Implementation of IAnjutaProvider

assist->lang_prov is an AnjutaLanguageProvider object.
static void
iprovider_activate (IAnjutaProvider* self,
                    IAnjutaIterable* iter,
                    gpointer data,
                    GError** e)
{
	LanguageAssist* assist = LANGUAGE_ASSIST (self);
	anjuta_language_provider_activate (assist->lang_prov, self, iter, data);
}

static void
iprovider_populate (IAnjutaProvider* self,
                    IAnjutaIterable* cursor,
                    GError** e)
{
	LanguageAssist* assist = LANGUAGE_ASSIST (self);
	anjuta_language_provider_populate (assist->lang_prov, self, cursor);
}

static const gchar*
iprovider_get_name (IAnjutaProvider* self,
                    GError** e)
{
	return _("Language name");
}

static IAnjutaIterable*
iprovider_get_start_iter (IAnjutaProvider* self,
                          GError** e)
{
	LanguageAssist* assist = LANGUAGE_ASSIST (self);
	return anjuta_language_provider_get_start_iter (assist->lang_prov);
}

static void
iprovider_iface_init (IAnjutaProviderIface* iface)
{
	iface->activate            = iprovider_activate;
	iface->populate            = iprovider_populate;
	iface->get_name            = iprovider_get_name;
	iface->get_start_iter      = iprovider_get_start_iter;
}

Implementation of IAnjutaLanguageProvider

static GList*
ilanguage_provider_get_calltip_cache (IAnjutaLanguageProvider* self,
                                      gchar* call_context,
                                      GError** e)
{
	/* language-specific code */
}

static gchar*
ilanguage_provider_get_calltip_context (IAnjutaLanguageProvider *self,
                                        IAnjutaIterable *iter,
                                        GError** e)
{
	/* language-specific code */
}

static void
ilanguage_provider_new_calltip (IAnjutaLanguageProvider* self,
                                gchar* call_context,
                                IAnjutaIterable* cursor,
                                GError** e)
{
	/* language-specific code */
}

static IAnjutaIterable*
ilanguage_provider_populate_language (IAnjutaLanguageProvider* self,
                                      IAnjutaIterable* cursor,
                                      GError** e)
{
	/* language-specific code */
}

static void
ilanguage_provider_iface_init (IAnjutaLanguageProviderIface* iface)
{
	iface->get_calltip_cache   = ilanguage_provider_get_calltip_cache;
	iface->get_calltip_context = ilanguage_provider_get_calltip_context;
	iface->new_calltip         = ilanguage_provider_new_calltip;
	iface->populate_language   = ilanguage_provider_populate_language;
}

When you call ianjuta_editor_assist_proposals () you have to set the elements of the proposal list in the right way:

GList* list = NULL;
IAnjutaEditorAssistProposal* proposal = g_new0 (IAnjutaEditorAssistProposal, 1);
AnjutaLanguageProviderProposalData* data = g_new0 (AnjutaLanguageProviderProposalData, 1);

/* set data->name, data->is_func and data->has_para */

proposal->data = data;
list = g_list_append (list, proposal);