Emacs - Elixir Setup Configuration Wiki

Awesome! I’ve been meaning to figure out how to accomplish that.

1 Like

This is pure gold :smiley: Thank you!

1 Like

I’ve added the popwin line to the wiki, seems popular! :slight_smile:

2 Likes

Cool, thank you for the suggestion. I’m currently using doom-emacs, I think the snippet should work properly.

Thanks for adding it! I promoted it on the slack as well and some people enjoyed it there. I also added :noselect t to the snippet (at the recommendation of someone on the Slack) so that the compilation buffer doesn’t take focus when you run the tests.

1 Like

I actually prefer it to be selected so it’s easier to navigate to failing output and jump to the test. Each to their own though!

1 Like

If anyone wants to use flycheck with eglot, I wrote a simple wrapper which replaces flymake with flycheck https://github.com/akash-akya/eglot-flycheck-adaptor

1 Like

Update: I finally solved my flycheck problems (yes, from July 2019). I’ve got lsp checking (dialyzer & elixir compiler) and credo working in a chain. The key was this: (setq lsp-flycheck-live-reporting nil). Disabling that prevents lsp from stomping on the value in flycheck-check-syntax-automatically. I think they are trying to replace that, but at least in a project the size of mine you cannot be running flycheck on idle/new line etc. I’ve long run it only on enable and save. Every now and then I’ll save before the last check finished and things get out of a sync so I do a quick s e b

Relevant configs:

  (add-hook 'elixir-mode-hook
    (lambda ()
      (setq lsp-flycheck-live-reporting nil)
      (setq-local flycheck-check-syntax-automatically '(mode-enabled save))))

  (add-hook 'lsp-after-initialize-hook
            (lambda ()
              (lsp--set-configuration `(:elixirLS, lsp-elixir--config-options))
              (elixir/init-flycheck-credo)
              (flycheck-add-next-checker 'lsp 'elixir-credo)))
2 Likes

Care, as it can completely bork the checking of lsp (at least it did ~a month ago when I tried to tackle this again).

The core of the issue is how lsp-mode interacts with flycheck.
The idea is that lsp runs the checker when it is needed by lsp specification, and only then.

By disabling that, your dialyzer checkers can stop working properly.

So, as I said earlier, the proper solution is to implement credo linter as part of the elixir-ls (or as a standalone plugin for the elixir-ls. I don’t know if elixir-ls supports plugins). And I am pretty sure such a contribution will be welcome

It is not just credo that doesn’t work for me. The compiler and dialyzer checkers also get stuck and stop updating unless I disable lsp-flycheck-live-reporting. It seems odd they’d document a customizable variable that can “completely bork … lsp” and not document that fact?

Hi there!
Thanks for the guide! :slight_smile:
I am using Spacemacs and eglot. The guide is not totally accurate.
package-install is prohibited in Spacemacs.

  1. You should add eglot in dotspacemacs-additional-packages instead.

  2. Then you need to add in dotspacemacs/user-config:

(require 'eglot)
(add-to-list 'eglot-server-programs '(elixir-mode "/home/nicolas/elixir-ls/release/language_server.sh"))
  1. To make your life easier and not having to type M-x eglot in any Elixir file, you may add in dotspacemacs/user-config AFTER (require 'eglot):
(add-hook 'elixir-mode-hook 'eglot-ensure)

Lastly, three things:

  1. The elixir layer in Spacemacs does not play well with Eglot. It calls lsp-mode from the Spacemacs lsp layer. If you want to use eglot in Spacemacs, you should add directly elixir-mode in dotspacemacs-additional-packages. Do not add the elixir layer.
  2. If you fail to add the require 'eglot instruction appropriately, eglot will randomly stop working on Emacs restart, and you will be prompted the error described in this GitHub issue.
  3. You can find my full .spacemacs dot file for more guidance on my GitHub.
2 Likes

Btw, if you guys and gals agree I can edit the wiki directly. Didn’t realize I could do it.

Go for it! That’s why it’s a wiki. That all looks like good information :+1:
I don’t use eglot so the instructions tend to lag a bit.

1 Like

Done editing the Spacemacs eglot configuration in the wiki!

1 Like

Indeed, I still have some problems… But the other configuration didn’t work well for Spacemacs anyway :/.

I tried to setup Spacemacs with elixir-ls, but I am still facing this error:

LSP :: The following servers support current file but do not have automatic installation configuration: elixir-ls
You may find the installation instructions at https://github.com/emacs-lsp/lsp-mode/#supported-languages.
(If you have already installed the server check *lsp-log*).
  • I am running develop Spacemacs 0.300.0@26.1
  • I cloned and built a elixir-ls (fork) release
  • I put (elixir :variables elixir-backend 'lsp) into my layers config
  • I put (use-package lsp-mode :commands lsp :ensure t :diminish lsp-mode :hook (elixir-mode . lsp) :init (add-to-list 'exec-path "/Users/eskimag/.emacs.d/elixir-ls/release/language_server.sh")) ) into my user-config

Any idea what could be wrong? Thanks a lot. I am struggling with Spacemacs for quite few hours already and I am losing my faith in it. :sweat_smile::pray:

Have you checked *lsp-log* buffer as mentioned in the error message?

Also exec-path is emacs equivalent of most OS’ PATH variable. You need to specify a folder, not the file directly.

If you want to specify the exectuable directly, then you need to (setq lsp-clients-elixir-server-executable "/Users/eskimag/.emacs.d/elixir-ls/release/language_server.sh). The default value for that variable is "language_server.sh", so it should work if you add "/Users/eskimag/.emacs.d/elixir-ls/release" to exec-path.

2 Likes

Thanks a lot. At least it’s not showing me this error anymore. Now I have to figure out all the remaining stuff like code completion, format on save etc. :slight_smile: It reminds me a lot of the times when I used Linux. :grin:

1 Like

What is this view? I want to do this in my setup.

1 Like