DEV Community

Cover image for Crafting a Language Server in Golang: A VSCode LSP for Lama2
Athreya aka Maneshwar
Athreya aka Maneshwar

Posted on • Originally published at journal.hexmos.com

Crafting a Language Server in Golang: A VSCode LSP for Lama2

This post narrates our journey to developing advanced functions in our VSCode extension for Lama2, a plain-text free API client manager. We will see how our thinking and implementation evolved through three stages over a period of a year.

The Genesis of Lama2 🦙

Lama2 is a plain-text oriented API manager optimized for team collaboration via Git.

My team stores all our APIs in a Git repository, ensuring easy collaboration and regular updates.
Whenever an API is created or updated, the link to the l2 file's Git repo is mentioned as part of the corresponding PR/MR.

The below demonstration shows how an API request can be made from a .l2 file.

Image description

The below demonstration shows how an API request can be made from the extension Lama2Code which is written in Typescript.

Image description

Running an l2 file is simple:

l2  /home/lovestaco/apihub/oneLogin/login.l2
Enter fullscreen mode Exit fullscreen mode

The diagram depicts the flow of an API call, the L2 binary gets the env from l2.env. It then uses httpie-go to make the request and outputs the results to Stdout.

Image description

The l2.env file sits in the same folder as the l2 API file. It contains environment variables(env) like:

export FABI_PROD="http://httpbin.org/"
export FABI_LOCAL="http://0.0.0.0:8000/"
Enter fullscreen mode Exit fullscreen mode

Early Steps: Naive Implementation of Auto-Completion

Elevating User Experience: Auto-Completion for api.l2

Manually referring to env variables from l2.env every time wasn't efficient. So, to make things easier, we added a feature: the extension checks l2.env for auto-completion.

Retrieving envs became a repetitive task, necessitating an efficient solution.

The diagram illustrates the flow of an API request. The extension runs the l2 command, after which the L2 binary fetches the env from l2.env, executes the request, and then outputs to stdout. The extension then reads it out and displays it out using webview.

Image description

Image description

This picture showcases the auto-completion of an env using Lama2Code for the first iteration.

The Stage 1 Hurdle

While the initial problem was addressed, the solution wasn't optimal because it was not reusable and was not standardized. Clearly, a more efficient approach was required.

As a remedy, we introduced an argument: l2 -e.
It gathered all the envs, allowing editors to invoke the command and use the registerCompletionItemProvider API for auto-completing the env.

Leveling Up: The CLI Switch

We developed the l2 -e command, this cool command can fetch envs from both l2.env and l2config.env. And when an env is declared in both files, we prioritized the values in l2.env. This decision not only helped in avoiding conflicts but also improved the efficiency of our VSCode extension.

Why We Wanted a Project-Level env(l2config.env) File:

Continue reading the full article https://journal.hexmos.com/lama2-lsp-journey/

Top comments (0)