ChrisAmelia

ChrisAmelia

Built a language server for learning purposes

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?

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...
2976 91332 914
New
f0rest8
Hi everyone :waving_hand: Posting here to showcase and announce that Metamorphic is now officially live on a public-facing domain at htt...
New
andrielfn
Hey there :waving_hand: I want to introduce Fluxon UI, a modern UI component library for Phoenix LiveView that I have been working on fo...
New
byu
@chrismccord : I just saw the Extract AGENTS.md from Phoenix.new into phx.new generator commit to the phoenix project. My initial shotgu...
New
arcanemachine
I was working on an Ecto migration and I needed a timestamp. So, for the nth time, I looked up the different data types for timestamps, a...
New
AstonJ
Just a general thread to post chat/news/info relating to AI/ML stuff that may be relevant for Nx now or in the future. Got anything to sh...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
kip
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
New
webofbits
Squid Mesh is an open source workflow automation runtime for Elixir applications. It is aimed at Phoenix and OTP apps that want to defin...
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
kip
In 2021 I started a new library called Tempo with the objective of modelling time as a set of intervals - not as instants. In 2022 I gave...
New

We're in Beta

About us Mission Statement