Enabling code navigation on GitLab

GitLab is a repository management system for storing software source code, you might say an analogue of GitHub. While the core features of GitLab are comparable to its counterparts, some implementation features can be useful for the Ada community. One of them is the code navigation directly on the repository site. GitLab understands (let’s face it, not very well) semantic information about the program in LSIF (Language Server Index Format) format, which allows you to enable code navigation, tooltips, etc. for any language. GitLab counterparts now only offer navigation support for a limited range of languages.

Having code navigation on your site is nice and makes it easier to get to know your code and conduct code reviews. To enable it in your repository, simply create a CI Pipeline which indexes the source code after changes and uploads the result as a special type of artifact. The prototype indexer program is already ready, it’s not hard to build with Alire. I prepared a script, which can be run with a one-liner:

curl -fsSL https://raw.githubusercontent.com/reznikmm/als-alire-index/main/make_lsif.sh | bash

To avoid having to build the indexer program every time you change it, you can add it directly to the image used by the pipeline, together with the compiler and alire. This is what the Dockerfile looks like:

FROM ubuntu:22.04
RUN apt-get update \
 && DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \
      python3 curl unzip git libgmp-dev libc6-dev make python3-pip python3-venv \
 && curl -fsSL https://raw.githubusercontent.com/reznikmm/als-alire-index/main/make_lsif.sh | bash \
 && mv -v alr lsif-ada /bin/ \
 && apt-get purge -y --auto-remove python3 python3-pip python3-venv \
 && apt-get clean \
 && rm -rf /var/lib/apt/lists/* /root/clean

I put the pushed image on the Docker Hub as reznik/gnat:alire and it can be used in any repository. As an example, I’ve enabled navigation in my TLS repository. You can now see where any identifier is defined with the mouse pointer.

Would you like to give it a try?

7 Likes

That’s awesome, Max. Using GitLab would have now a big plus for Ada projects, unfortunately they don’t allow searching based on the implementation language and I think they also lack topic labels, so there’s no manual way either to let others discover your Ada project.

Is this not applicable to GitHub? I think I’ve seen something similar on Python or Java projects.

GitHub provides such features only for fixed set of languages. They use a custom Haskell software based on Tree Sitter parser. Even having tree sitter parser for Ada it’s not clear to me how to add new language support.

GitLab.com allows filtering by language now, but the UI only allows selecting some specific languages and the URL uses an ID for the language, not the name. I tried to guess the ID for Ada, so we can filter the projects, but without success. There are sources claiming they use github-linguist for language detection, but those IDs don’t match.

@Max, since you’ve been working on this project, you might have some idea about how to get that number.

There’s already an issue for this problem: Allow to select less popular languages in search (#426880) · Issues · GitLab.org / GitLab · GitLab

Maybe people here are interested in giving it a thumbs-up.