Monthly Archives: September 2013

My Vala backend implementation

Hey all,

My Vala backend looks working fine now. I didn’t do all tests, but I can show you how it is working for some kind of errors.

If you forget to declare type (it is simple, but very common for Python/Ruby programmers, for example):

Image

Or you forget to close a brace:

Image

Or a parenthesis:

Image

More examples:

ImageImageImage

Document file

Following Python backend implementation, the other class which I codified was Vala.Document. For this class I can create some auxiliar classes to works together Vala.Document class update solution.

Vala.Document’s implements Gcp.DiagnosticSupport which is related to Gcp.Document. Gcp.DiagnosticSupport has some abstract methods that need to be implemented:

  • begin_diagnostics
  • end_diagnostics
  • set_diagnostic_tags
  • get_diagnostic_tags

Another necessary method is that one which will be called on Backend on_document_changed method to “diagnostic” gedit document making validations of file for the especific programming language.

In my case, I named as “update”. In this method I include a timeout to parse, following others Backend files. To start the parsing, I gather some document informations as path, text bounds which are used to reference what I need to analyze.

Vala has a Reporter class that make syntax analysis of its own code. So, it is not necessary to create the many parse methods to check the many possibilities of syntax errors.

And you can override some Reporter class methods, which I did to call DiagnosticSupport method responsible for display these errors to user.

So, when your parser find a error, it needs to:

  1. create a SourceIndex object
  2. get begin and end bounds of error that will be used to create a SourceLocation object used in SouceRange instantiation
  3. create a Gcp.Diagnostic object using the informations above and add this on SouceIndex object created in the begining.

Finally, you will lock the mean Diagnostic thread, set your new SourceIndex object as diagnostics object from global assistance and emit a diagnostic updated signal.

Backend file

When I was implement my Vala Backend solution, in addition to metadata files I implement two other files with basically two classes Backend and Document. This post, I’m describing the first one.

Backend’s class implements class Backend Implementation from gcp original source. So, you need reference this class as a abstract class on your code and override tree methods:

  • create_document
  • destroy_document
  • on_document_changed (trigger your method to deal with document update)

I still don’t know why, but I needed to include this lines to make it works fine:

[ModuleInit]
public void peas_register_types (TypeModule module)
{
    Peas.ObjectModule mod = module as Peas.ObjectModule;

    mod.register_extension_type (typeof (Gcp.Backend),
                                 typeof (Gcp.Vala.Backend));
}

I “stole” this from C backend code 😛 I will ask my mentors about it, since it is present on backends that was implemented using Vala but I didn’t see on Python’s codes.

Gnome Yearbook

Hey, I’m glad to be present in Gnome yearbook of this year. I received mine via postoffice, since I couldn’t be present on GUADEC in Brno. My yearbook has a world of people, I just could see their faces on pics.
For me was a good surprise seeing that, with my yearbook, I received 2 Gnome stickers ❤ I love stickers!! 🙂 I put one on my netbook, so cute!Image