Neovim 0.5 LSP with ElixirLS

Neovim 0.5 comes with a built in LSP client. This allows you to access LS Language Servers which will service the LSP, Language Server Protocol.

Elixir has a Language Server that was built on the shoulders of other analytic services.

But you won’t be able to boot Neovim 0.5 and connect automatically to the LS. You will need to configure Neovim to connect to your LS.

Install nvim-lspconfig

To connect to your LS, Neovim 0.5 has a plugin to configure the LSP client in Neovim. It is possible to configure your language server manually without this plugin.

nvim-lspconfig has a list of configuration scripts for setting up Neovim to talk to the language server you need.

nvim-lsp is a plugin. You will need a plugin manager likely but most common systems will work.

In your neovim config.

~/.config/nvim/init.vim

Add the plugin.

Plug 'neovim/nvim-lspconfig'

Then we’ll setup the configuration for ElixirLS.

lua require'nvim_lsp'.elixirls.setup{}

Now save ~/.config/nvim/init.vim and restart your Neovim.

Install elixirls

neovim/nvim-lsp adds mappings for installing ElixirLS.

To install:

:LspInstall elixirls

Now you can check if elixirls is installed.

:LspInstallInfo
{
  elixirls = {
    cmd = { "/home/rockerboo/.cache/nvim/nvim_lsp/elixirls/elixir-ls/release/language_server.sh" },
    install_dir = "/home/rockerboo/.cache/nvim/nvim_lsp/elixirls",
    is_installed = "file"
  }
}

If elixirls is not showing up, it is not installed.

Usage

I would suggest looking through the neovim lsp docs. The following is an example config.

nnoremap <silent> gd    <cmd>lua vim.lsp.buf.declaration()<CR>
nnoremap <silent> <c-]> <cmd>lua vim.lsp.buf.definition()<CR>
nnoremap <silent> K     <cmd>lua vim.lsp.buf.hover()<CR>
nnoremap <silent> gD    <cmd>lua vim.lsp.buf.implementation()<CR>
nnoremap <silent> <c-k> <cmd>lua vim.lsp.buf.signature_help()<CR>
nnoremap <silent> 1gD   <cmd>lua vim.lsp.buf.type_definition()<CR>
nnoremap <silent> gr    <cmd>lua vim.lsp.buf.references()<CR>
nnoremap <silent> g0    <cmd>lua vim.lsp.buf.document_symbol()<CR>
nnoremap <silent> gW    <cmd>lua vim.lsp.buf.workspace_symbol()<CR>

Most of my usage so far is in hover(), definition().

Go Forth

Neovim 0.5 is currently not released but it will be soon. This process simplifies a lot of previous tools that all work together under a standard system. New tools may come that make these features even better.