Neovim - Elixir Setup Configuration from Scratch Guide

With coc.nvim, I use this in my coc-settings.json:

  "[elixir]": {
    "coc.preferences.formatOnSave": true
  },

Ah, sorry I didn’t mention I am using neovim’s builtin language server.

Yes this thread is mostly about the built-in LSP. I just wanted to point out the alternative, which as I said on the linked thread, while less pure due to relying on NodeJs is in my experience much easier to set up and configure, and the defaults mostly worked how I wanted. Nobody told me this when I was doing the same thing, so I want to add something to consider for those struggling with getting the built in options working :slight_smile:

1 Like

Funny enough I had the exact opposite experience :slight_smile:
I was using coc on vim, switched to nvim mostly because of treesitter, and I wasn’t able to keep my coc configuration.
Tried built-in LSP and it worked basically OOTB.

It takes all kinds to make a world, I suppose.

Has anybody succeeded to get the heex snippets working inside the H sigil?

Hi you should check that thread :

https://elixirforum.com/t/getting-heex-and-h-working-in-nvim-with-astronvim/54779

It worked for me.

2 Likes

Embarrassingly I had too many tabs open and realised I replied to the wrong thread…it won’t let me repost the same and I can’t delete the old one, but can see here: Neovim: nvim-lsp + elixir - #17 by te_chris

Basically, I’m using nvim and the NVChad config. Have installed the elixirls package with mason and LspInfo says it’s being used. I’m not getting any completions though. Debug suggestions welcome!

Just a note as it might help someone. Had nvim + elixirls + treesitter nicely working, except syntax highlighting for ~H sigils. Bashed my head against the wall to figure out why, reinstalled & updated all dependencies and tried everything I found online, almost gave up, then decided to update neovim itself (from 0.8.2 to 0.9.2). And boom, it works!

tl;dr: make sure neovim is up to date :slight_smile:

Another tip: As of Aug 2023, packer.nvim is unmaintained. I migrated to lazy.nvim - smooth transition. For me lazy runs faster and is simpler to setup.

1 Like

I would suggest not just using lazy package manager but the LazyVim distro.

LazyVim is by the far the cleanest and well structured nvim distro I have used. I have used a number of distros including bootstrapping nvim from scratch. LazyNvim is not intrusive, its transparent and very easy to get started and customise however you want.

One of the great features of LazyNvim that it has working Elixir language support out of the box.

I use asdf to ensure I have a very recent stable version of nvim and recommend asdf as the way to go for installing and managing versions of Erlang/OTP, node etc too.

The Elixir plugin is described here, along with all the plugin defaults it enables:

One you have followed the easy peasy LazyVim installation, just add a single elixir plugin “lazyvim.plugins.extras.lang.elixir” to lua/config/lazy.lua and you’re cooking with gas:

require("lazy").setup({
  spec = {
    { "LazyVim/LazyVim", import = "lazyvim.plugins" },
    { import = "lazyvim.plugins.extras.lang.elixir" },
    { import = "plugins" },
  },
})
7 Likes

I’m on lunarvim right now. But you might have convinced me to give lazyvim a try :upside_down_face:

1 Like

Neovim ecosystem is evolving fast. Actually I’ve switched to lazy.nvim plugin manager since the discontinued development of packer.nvim. I’ll update the guide when I’ve got time.

2 Likes

Also you can enable it with x command for extras.

3 months later: I am gonna call you out on that. I have been using https://github.com/jdx/rtx for a few months now and I like it more. It’s absolutely instantaneous at whatever you give it to do (minus the networked operations). And I’ve observed asdf being slow in a number of occasions which always baffled me because really, what does that thing have to do? It isn’t much, yet it still manages to lag. (And the rtx author claims that asdf also adds overhead via its shims, and says that rtx does not.)

rtx fixed that for me. It’s completely invisible and is uber fast, and is compatible with all asdf plugins. It’s a drop-in replacement, with only 1-2 gotchas on how to set global versions of tools (slightly different than asdf but it can also work just fine with .tool-versions files as well).

2 Likes

I haven’t tried rtx yet but I have been meaning to give it a go, but asdf is not slowing me down enough to bother right now.

Works like charm. Thanks for this little tutorial.

Im running FreeBSD, so to make elixir-ls to run and not quit on me at the startup, I had to change the #!/bin/sh to use #!/usr/local/bin/bash as ‘<<<’-operator isnt supported by sh.

It is typical to use env in portable scripts to locate the executable, in this case “bash” on the users path.

#!/usr/bin/env bash

It probably should be fixed upstream.

1 Like

Yeah that, but the greatest problem is the use of bash syntax but specifying (I assume) Bourne shell in the hashbang

If everything else is intended to work with sh - the upstream fix would perhaps be to use a ‘sh’ replacement for ‘<<<’-operator.

Hi there! Thanks for the guide, it was really useful. I’m relatively new to Elixir and Phoenix and I’m seriously considering them for my next big project… The ecosystem looks fantastic!

Anyways, if someone is using credo for linting I’d recommend using the nvim packages "mfussenegger/nvim-lint", "dgagn/diagflow.nvim" and "folke/trouble.nvim".

Together they provide a very nice coding experience.

I’ve never heard of any of these packages. I’m going to look into them, but would you mind explaining why they are particularly useful when paired with Credo?

EDIT: So I use coc.nvim and coc-elixir. I’ve been looking to ditch CoC for a while (because why have some bloated npm mess running in the background when I could avoid that), but it’s already set up so so I’ve kept it around. Plus, holy hell are there ever a lot of neo/vim plugins related to LSP/IDE stuff.

1 Like