ChrisAmelia

ChrisAmelia

Educational project

I was always intrigued by how IDEs provide smart completions when you press certain keys, how the diagnostics hit right, and all the mechanics they provide behind the scenes.

So I decided to dive into the process behind it: the Language Server Protocol. I also wanted to learn Elixir and ended up building an educational language server in Elixir.

While this is educational, I have implemented some basic functionalities regarding English writing:

  1. Shows the definition of the word under the cursor by calling vim.lsp.buf.hover() (default to K in Neovim).
  2. Sends an error diagnostic if the document contains VS Code.
  3. Suggests a list of words for completion.
  4. Suggests some code actions: replace VS Code with Neovim or censor it with VS C*de.

Any feedback, especially on the Elixir part, is welcome. I’m looking to get better in that language.

Architecture

  1. There are two GenServer: InputServer and LSPServer. They are both initialized in the module Application by a Supervisor.
                                    ┌──────────────┐ 
                               ┌───►│  InputServer │ 
                               │    └──────────────┘ 
                               │                     
                               │                     
                               │                     
  ┌─────────────┐  initialize  │                     
  │ Application ├──────────────┤                     
  │  Supervisor │              │                     
  └─────────────┘              │                     
                               │                     
                               │                     
                               │    ┌───────────┐    
                               └───►│ LSPServer │    
                                    └───────────┘    
  1. This is where the life cycle starts: InputServer listens on stdio.
    2.1. InputServer sends that message to LSPServer.
    2.2. LSPServer processes it and sends back a result to InputServer.
                                     
                                     
           message                   
  ┌──────┐         ┌─────────────┐   
  │client├────────►│ InputServer │   
  └──────┘         └───┬────▲────┘   
                       │    │ result 
                       │    │        
                       │    │        
               convey  │    │        
                    ┌──▼────┴───┐    
                    │ LSPServer │    
                    └───────────┘    
                                     
  1. InputServer sends the result back to the client and then loops back to listening on stdio.
                                                               
                                                               
                                              ready to listen  
                                            ┌──────────┐       
                                            │          │       
                                            │          │       
                                            ▼          │       
                               ┌───────────────┐       │       
   ┌────────┐  result          │               ├───────┘       
   │ client │◄─────────────────┤  InputServer  │               
   └────────┘                  │               │               
                               └───────────────┘               
                                                               
                                                               

Notes

I have encountered two challenges that I haven’t solved in the Elixir way.

When and how to properly shut down the application?

I have set two System.stop() at two different occasions, which I found redundant:

  • when the client sends the shutdown request,
  • when :eof is received after listening with IO.read(:stdio, :line).

Process still runs in the background if a crash happens

In the life cycle of InputServer, if a crash happens (example String.split(nil, "\n")),
the process is still alive even after having closed Neovim, probably a zombie?
The only fix I have found was finding the source of the issue by checking the logs and correcting it.

Where Next? Top

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2977 92995 915
New
caslu
I want to open this thread for you all to discuss and help those who really like Ash but are still hesitant to use it in a real project. ...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
GES233
I’m posting this in response to Jose’s recent tweet (Cr. link) : People are sleeping on Elixir for a coding harness: Hot-code swappi...
New
_mfierro
Hello, I wrote Stop My Hand, a Scattergories-like web application using Phoenix/LiveView as my learning project for Elixir (after readin...
New
marciol
It would be helpful to have a list of companies worldwide that hire engineers without prior experience in Elixir. Often, it can be quite ...
New
durvia
Anyone running long-lived stateful processes on BEAM? We’re building an AI agent runtime and would love to compare notes. We’re a small ...
New

Other Trending Topics Top

garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews