Code Search for GNOME Builder : GSOC 2017

I am very happy to be part of GNOME and Google Summer of Code 2017. First of all, thank you for all GNOME members for giving me this opportunity and Christian Hergert for mentoring and helping me in this project. In this post I will introduce my project and approach for doing this project.

Goal of the project is to enhance Go to Definition and Global Search in GNOME Builder for C/C++ projects. Currently in GNOME Builder, using Go to Definition one can go from reference of a symbol to its definition if definition is there in current file or included in current file. In this project, Go to Definition will be enhanced and using that one can go from reference of a symbol to its definition which can be present in any file in the project. Global Search will also be enhanced by allowing to search all symbols in the project fuzzily right from search bar.


These are the approaches for implementing Go to Definition and Global Search.

Go to Definition:

In C/C++ files we will have declarations/definitions of various types of symbols like variables, functions, structs, enums, unions, classes, types and many more. Each declaration will have a name and some scope. And no two declarations of same type of symbol in same scope will have same name (with some exceptions like function overloading). Using this idea, a key can be generated for a declaration: key = scope+type+name. So we can use this key to uniquely identify a declaration. Thanks to libclang library which will generate this key for a declaration for making our lives easy.

Lets take 2 files,


int foo ()
  return 0;


int foo ();
int bar ()
  int a;
  a = foo ();
  return a;

If we want to go to definition of foo() from 2.c : line 5,  first we will go to declaration present in 2.c and generate key for that, key =File Scope+Fucntion+foo = ::F::foo. (Going from a reference to its declaration present in same file can be done by libclang library directly.) Now we will use this key and search in every file for a definition with same key. If search key matches to the key of a definition, then that is definition of our reference. If we form a database of keys of all declarations, then we can search for definition of reference very quickly. This is how Go to definition will be implemented in GNOME Builder.

Global Search:

Goal of this is to search all symbols in the project fuzzily. For doing that, names of all declarations in all files will be extracted by traversing clang AST and stored in a database. When ever we get aquery we will search this database for fuzzy matched. For storing all names, fuzzy index implementation in libdazzle library written by Christian Hergert (mentor for my project) will be used. This is the idea for implementing Global Search.

For doing above two things first an index of code needs to be created. This will be done by creating a new plugin in Builder which will do indexing process.  In conclusion implementation of project is divided into 3 tasks.

  1. Indexing: Creating a plugin which will index project and store that index into hard disk.
  2. Global Search: Implementing an interface which will searching index for a name and show fuzzy matches.
  3. Go to Definition: Implementing an interface which will search index for a key and give location of corresponding definition.

Now I am working on first part and here is the progress in implementation till now patch.  This patch does indexing but few things needs to be improved, like indexing in sub process and not in main process. By completing first part in my next post I will post about how indexing is done.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s