Emacs - Elixir Setup Configuration Wiki

Glad it helped you! Yeah we are getting a little behind at this point. Will try to sync it up soon

Hey all, I’m trying to get spacemacs, elixir-ls (the fork), and friends to play nice on Ubuntu.

I think I’ve followed all the steps correctly, but am getting:

File mode specification error: (wrong-type-argument lsp-session [cl-struct-lsp-session ( *** GIANT LIST OF ALL MY ELIXIR, RUST AND PYTHON projects (LSP!) *** ) nil #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.800000011920929 data ()) #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.800000011920929 data ()) #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.800000011920929 data ())])

Any advice?

Hmmm, I’m not sure about what would cause that. Are you using a recent version of Emacs? (at least 26?). I’m really not sure where the list of your elixir, rust, and python projects are coming from because I didn’t think that lsp-mode stored a list like that. Is your Spacemacs setup pretty vanilla or have you customized it already?

0.300.0@26.1 (spacemacs) on Ubuntu 19.04. I try to keep my Spacemacs setup as close to vanilla as possible.

Do you have a .spacemacs file to copy or are there diagnostic steps i can take to make sure i’ve got elixir-ls installed correctly?

Thanks for the great resource, I’ve been looking for exactly this.

I am using spacemacs latest develop 0.300.0@26.1 too with https://github.com/JakeBecker/elixir-lslsp layer, auto-completion layer it’s working.
One bit that I found out is that you have to use the same elixir/otp version in elixir_ls and the one in the project that you are working on.
Although I am not sure about your specific error, i hope that this helps!

…and welcome!

I started over from vanilla with JakeBecker’s elixir-ls and it’s working now. Not sure what I did wrong but thanks all for the help.


I’m glad you got it working!

Hi, all. Thank you for the great information about Elixir setup for Emacs.

How do you get Emacs checking syntax errors as a linter?

After a quick research, I found flycheck and flymake didn’t support Elixir officially.
In flycheck document, there’s a recommendation for Elixir syntax checker flycheck-mix, and several packages are listed on melpa like flicheck-credo and flymake-elixir. But it seems these extensions are outdated and also their development is stopped.

What packages do you use for syntax checking in Emacs? It’s good to mention it in this wiki, I think. Thanks.

What kind of linting do you miss?

Syntax errors and compile time warnings are marked properly when I do use emacs and the ELS. I did not configure something special, its just that flycheck is part of my base configuration.

I tend to not use credo at all though. Formatter does most of the things I used credo for back when I used it. And I do not agree with a lot of the other lints and would disable many anyway…

Compile time messages are useful, but inline warnings when writing source code are also convenient in my opinion.

Syntax errors and compile time warnings are marked properly when I do use emacs and the ELS.

Maybe I’m missing something, can elixir-ls indicate syntax errors alongside the line numbers or something?

In my case, I set up code formatting when I save the buffer according to elixir-mode instruction. So, if I get syntax errors, warnings only appear in *elixir-format-errors* after saving. There’s no indicator on the same buffer.

As the LS compiles on save, they are there “as you type”.

I do see red and yellow squiggly lines. My office box has no emacs installed though and I can’t SSH to home for some reasons that I have to debug later, so I can not show you a screenshot right now, perhaps later today (6 to 10 hours from now).

I do use eglot, for LS, perhaps that is making the difference?

Anyway, you can look my emacs config up at https://gitlab.com/NobbZ/emacs.d, perhaps you spot the difference?

1 Like

Ohh… It seems I just misconfigured project root directory settings. I’m using elixir-ls with lsp-mode, and exec M-x lsp-workspace-folders-remove then M-x lsp-workspace-folders-add to set proper project root. After that syntax errer indicator appears in the current buffer. Sorry for the noise, I’m a Emacs and Elixir noob :P.

@NobbZ Out of curiosity, I tried to configure elixir-ls with eglot. How do you set project root under eglot? In lsp-mode, above commands can handle root directory, but I can’t find such counterparts in eglot. Eglot recognize the current directory where the editing file exists as project root, so syntax error detection doesn’t work.

1 Like

I’ve not done anything special, my assumption is that it just works because eglot or projectile recognise the git root as project root.

git init at project root resolve the issue. I really appreciate you.

By the way, mix new already created .gitignore file, so isn’t it better mix new also create git repository at the same time like cargo new in Rust language? (a bit off topic though)

1 Like

Because this would require you to have a working git installation before you were able to use elixir.

Even worse, both had to work within the same terminal session. Especially this is not trivial on some operating systems.

Using latest spacemacs develop and tried using both LS I get the following error:

File mode specification error: (error elixir-ls: Cannot communicate with the process (exit))
LSP :: elixir-ls has exited (exited abnormally with code 127)
Server elixir-ls:22877 status:starting exited with status exit. Do you want to restart it? (y or n) y
LSP :: Restarting LSP in buffer cli.ex
error in process sentinel: lsp--send-no-wait: elixir-ls: Cannot communicate with the process (exit)

Not sure how I correct this, anybody got some tips?

1 Like

I’m on the latest spacemacs dev and latest elixir-lsp/elixir-ls master branch and everything is working for me so it seems like there’s something funky going on with your setup.

Can you tell me:

  • Operating System version
  • Elixir version
  • Erlang version
  • What happens if you run elixir-ls/release/language_server.sh

Ubuntu 19.04
Elixir 1.8.1 (installed using asdf)
Erlang 21
running sh language_server.sh I get:

warning: the VM is running with native name encoding of latin1 which may cause Elixir to malfunction as it expects utf8. Please ensure your locale is set to UTF-8 (which can be verified by running "locale" in your shell)
Content-Length: 559

{"jsonrpc":"2.0","method":"window/logMessage","params":{"message":"  Warning: the `dialyxir` application's start function was called, which likely means you\n  did not add the dependency with the `runtime: false` flag. This is not recommended because\n  it will mean that unnecessary applications are started, and unnecessary applications are most\n  likely being added to your PLT file, increasing build time.\n  Please add `runtime: false` in your `mix.exs` dependency section e.g.:\n  {:dialyxir, \"~> 0.5\", only: [:dev], runtime: false}\n","type":4}}

Content-Length: 99

{"jsonrpc":"2.0","method":"window/logMessage","params":{"message":"Started ElixirLS","type":4}}

Content-Length: 138

{"jsonrpc":"2.0","method":"window/logMessage","params":{"message":"Elixir version: \"1.8.1 (compiled with Erlang/OTP 20)\"","type":4}}

Content-Length: 105

{"jsonrpc":"2.0","method":"window/logMessage","params":{"message":"Erlang version: \"21\"","type":4}}

I’ll try a clean install of spacemacs and elixir-lsp

EDIT: Clean install worked perfectly! Not sure what happened there but sorry for the trouble.

1 Like

No worries, I’m glad you got it working :+1:

@ynakao I’ve once written flycheck-mix. It does the job for me and it was working for me since then. It is quite stupid because it just runs mix compile over and over but that worked for me. I am not even sure if spacemacs creators didn’t pull it in as part of the elixir layer.
If you think it needs improvements, feel free to ping me :slight_smile: