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 94592 917
New
cblavier
Hey there, It’s been more than a year since we started using LiveView as our main UI library and building a whole library of UI componen...
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
heathen
Quite interesting article Google brought me. Didn’t find any mentions about it here. What do you think in general? Would you use togethe...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
AstonJ
Since we have deprecated our Erlang sections (as we have dedicated Erlang Forums now) let’s add this thread for those who’d like to post ...
New
maennchen
:warning: Security advisory: Decimal DoS vulnerability A vulnerability has been published for decimal where very large exponents can cau...
New

Other Trending Topics Top

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
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
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews