Neovim - Elixir Setup Configuration from Scratch Guide

:astonished: Imagine all the things you could have done with your life instead of typing end!

1 Like

That worked for do end but not fn -> end! :smiley:

I know it sounds so silly, but what happens is that if I type end myself, it triggers autocomplete, which then captures my up arrow keypress. So you have to press escape or something to get out of autocomplete, which also takes you out of insert mode. So then you have to press i again, then up, then tab. It’s many keypresses for something that happens all the time.

Also, if you just leave a block open without the corresponding end, then everything gets colored bright red cuz it’s a syntax error. Not only that, but indent just completely stops working.

See screenshot for an example. My cursor (which you can’t see because of other neovim related reasons) is on column 1, i.e. autoindent just completely fails.

Ah, dang! You could try regular ol’ endwise, though I remember when I was trying out NeoVim it didn’t work and I had to use the treesitter one. Sorry, I’m going off recent knowledge—I actually gave up on NeoVim and back with regular ol’ classic Vim (aka, Vim). I just keep up with this thread because it’s the closest I get to Vim content 'round here.

Gah, that sounds super frustrating. Sorry I can’t be of more help.

1 Like

If you have a snippet plugin installed, you’ll get snippet type options from the autocomplete list. And if I remembered correctly, the elixir-ls provides some builtin snippets for do block and anonymous function.
So you just need to type do or fn and then select the snippet from autocomplete options. It will expand to something like do | end or fn | -> end.
If you want an experience more like auto pairs, you can try nvim-autopairs and roll your own rules.

1 Like

:no_mouth:The neovim ecosystem is moving fast, and this post is kind of outdated already. I’ll update the post later when I get more free time.

1 Like

This is a more tricky problem. LSP client in Neovim needs a project root directory to work. When you open a .ex file from an elixir project, the current working directory will be set to the elixir project root.
There’s some related discussions and possible solutions here: https://www.reddit.com/r/neovim/comments/16kkeq1/neotree_keeps_switching_working_directory_in_a/ .

1 Like

I only just started using snippets recently after 20+ years of… not using snippets. It’s the same feeling I had after not wearing sunglasses until I was 25. What the $#%@ was I thinking this whole time???

1 Like

exactly! this is my personal beef with at least some of pre-packaged Neovim distributions - i feel like maintenance cost on my side and amount of paper cuts is just not worth it.

skipping aside the fact i am losing opportunity to learn bit of Lua and finally have an excuse to poke around Neovim’s plugin API (sure, it’s a subjective matter, i get it).

:raised_hand: guilty! :slight_smile:

1 Like

Hey there

I am having troubles trying to make the elixir ls understand the root of my project.

I have a single repo with multiple elixir projects. When I enter one of the projects I expect the elixirls to understand that the root should be that subfolder, but it keeps going up to the root of the mono repo.

Any suggestions?

Is it an umbrella? Or is it a directory containing several independent projects in sub-directories?

1 Like

I want to use ElixirLS since it has been working well for me in VS Code. Looking at the ElixirLS repository, I see three variations for Neovim. Which one should I install?

Almost in all cases it’s the third one.

3 Likes

Thanks for clearing that up! Could you explain what a debug adapter is?

It’s more or less a client for a debug protocol (DAP) so you can step into/out of functions, do single step executions etc.

I am not judging anyone who needs debugging but I have stopped using it at least 15 years ago.

2 Likes

Can someone help me configure ElixirLS? The instructions in the repo feel overwhelming. Are there any tutorials or step-by-step guides I can follow for the setup?

Got it, thank you for that explanation.

You are better off using a ā€œdistroā€ like AstroNvim or LazyVim to be honest. I wouldn’t know how to setup all those pieces one by one and I am getting quite annoyed myself. I prefer the all-in-one package.

1 Like

If I choose LazyVim or AstroNvim, do I still need to install a language server? I thought it was required—did I misunderstand?

This should help :wink:

2 Likes

It’s been a while but I’m still using this setup and it works fine. Have to manually update elixir-ls every now and then.

1 Like