Elixir LS can bring us some IDE features to our editor of choice thanks to the Language Server Protocol (LSP). If you are like me, you prefer the speed and simplicity of Sublime Text. Let’s see how to compile Elixir Language Server and how to use it within Sublime Text 3 editor via LSP plugin on Fedora.
Before we dive in, let’s make sure that we have already installed both Sublime Text 3 and Elixir programming language. If you are on Fedora, one easy way to get ST3 running is to use Fedy which you can also use to install other cool software and utilities. For Elixir itself, the official elixir package is all that’s needed for Fedora systems.
Next we need to prepare and compile the Elixir Language Server (Elixir LS). To make sure it will work smoothly with our system we compile it from scratch. The process is no different to compiling other Mix projects:
$ cd elixir-ls
$ mix deps.get
$ mix compile
$ mix elixir_ls.release -o release
The last line will make a release for us to a directory of our choice. We need to remember this path for the next step. Specifically we need to locate a file called language_server.sh
. It’s a good idea to try to run it so that it’s clear this step was successful.
Once the Elixir LS is in place we can continue and install two new packages in Sublime Text using Package Control. “Elixir” package for syntax highlighting and “LSP” for running language servers. To do so we simply invoke Package Control with CTRL+SHIFT+P shortcut and start typing “Install Package” followed by ENTER and the name of the package.
After that we need to tell the LSP package about our Elixir language server location so we hit CTRL+SHIFT+P again and search for “LSP Settings”. That should open two files, ~/.config/sublime-text-3/Packages/User/LSP.sublime-settings
and .config/sublime-text-3/Packages/User/LSP/LSP.sublime-settings
. We will edit the user file (which overrides the global settings) with the following (change the command path to the actual path!):
{
"default_clients": {
"elixir-ls": {
"command": ["/path/to/release/language_server.sh"],
"enabled": true,
"languageId": "elixir",
"scopes": ["source.elixir"],
"syntaxes": ["Packages/Elixir/Syntaxes/Elixir.tmLanguage"]
}
}
}
The “default_clients” part is important as we have to use the same structure as in the global file. After saving the file we can go to any Elixir project and enable LSP using Package Control again by hitting CTRL+SHIFT+P and typing “LSP: Enable Language Server in Project”.
We should now get a report of warnings and failures on every save. Clicking any line will bring us directly to the location of the issue. That’s it!