Emacs lsp-mode (language server) + elixir-ls anyone?

Has anyone tried the emacs lsp-mode + elixir-ls?

I’ve noticed that the emacs support is starting to get behind other editors. Actually, alchemist and elixir-mode are really nice, but they are lagging behind in terms of evolution. Several issues without answer and no new releases for a while.

I started to take a look at alternatives and I really like the idea of a Language Server for Elixir (and Erlang). Elixir-ls works nicely with Visual Studio Code and I wonder if it would work with emacs-lsp but Haven found the time to try it yet.

So, has anyone tried this combination with luck? I really think all efforts on IDE/text editors support should focus on language server now. We would all have a very similar experience with our prefered keybindings and plugins…

6 Likes

Definitely agree—I use spacemacs daily but know just enough elisp to be dangerous… literally. Trying get mix format to format my code on save i managed to get my emacs into a situation where I literally could not close it short of a force kill. Don’t ask me how, I have no idea.

So the moral of the story is that I’m at the tender mercies of those brave souls who forge a path for us mortals to tread. I wish I could help move integrations like alchemist forward, but seriously, I’m a danger to others. I’m going to check out this lsp-mode and pray I don’t manage set off a WarGames situation. Will report back if I’m successful, but don’t wait too long to send out search parties.

1 Like

Seems an interesting path to move into!

My elisp is also potentially dangerous heheh, I’ve been using emacs for a couple of months only, so I can only do the basic stuff… but gonna play a bit with it, at least take a look at what they did for the other languages :+1:

@karmajunkie on the mix format issue, I’m using https://github.com/anildigital/mix-format.el, so far no problems with it!

2 Likes

I am using mix-format too, though it is a bit slower on Emacs than on VS Code. The issue is that it is not on Melpa yet so I`ve copied it to my config.

Also, the creator of mix-format is interested in merging it into elixir-mode itself. Though it seems it is blocked currently because there is a shortage of elisp reviewers =/

1 Like

Was trying to hack my way through this, but it still doesn’t work. Here is the wip as for now: https://gist.github.com/rodrigues/a7277c70ab9be361390fa52f923e7e03

3 Likes

Any luck with that approach?

1 Like

BTW, Spacemacs just added LSP support. Maybe you can see what they did there to make it work.

6 Likes

I’ve just gotten around to publishing a precompiled release package which includes .sh and .bat scripts for launching the language server and debugger: https://github.com/JakeBecker/elixir-ls/releases

I’m hoping this makes it easier to integrate into IDE plugins. Hope that helps @rodrigues and everyone!

6 Likes

It’s definitely still in progress, but now it’s talking to elixir-ls behind the scenes!! https://gist.github.com/rodrigues/a7277c70ab9be361390fa52f923e7e03 :cowboy_hat_face:

Thanks @JakeBecker, the releases really helped!

EDIT: moved it into a github repo. PRs are more than welcome!

https://github.com/rodrigues/lsp-elixir

7 Likes

I’m using Alchemist with elixir-ls.

https://github.com/tonini/alchemist.el/pull/341

4 Likes

I’ve managed to get elixir-ls through alchemist working too. Here is my configuration just in case anyone would want to give it a try:

First, I’ve cloned @Trevoke’s for on ~/.alchemist. Then on my init.el (with use-package already configured), I have:

(use-package company
  :ensure t
  :diminish company-mode
  :bind ("M-/" . company-complete)
  :defer t
  :config
  (global-company-mode))

 (use-package company-quickhelp
  :after (company)
  :ensure t
  :config
  (company-quickhelp-mode))

(use-package lsp-mode
  :ensure t)

(use-package lsp-ui
  :after (lsp-mode)
  :ensure t)

(use-package company-lsp
  :after (company lsp-mode)
  :config
  (push 'company-lsp company-backends)
  :ensure t)

(use-package alchemist
  :after (elixir-mode)
  :load-path "../.alchemist"
  :config
  (require 'alchemist-elixir-ls)
  (require 'alchemist-goto)
  (require 'alchemist))

Hope this helps!

7 Likes

Please submit all this to Spacemacs elixir layer! ^.^

3 Likes

I think the layer needs some love from someone more experienced than me on Elisp. I am really not that comfortable with Elisp. I am learning, but still long ways to go…

Besides, this is still a test branch from @Trevoke. So it is ongoing work… IMHO it is still not ready to be integrated to spacemacs. You’d need to git pull origin use-elixir-ls to update the setup :smile:

1 Like

Hi all,

Thanks for the interest!

Yeah, this is not yet ready for spacemacs, unfortunately. I originally thought I could do a back-end refactor of alchemist and get rid of all the original code, using only elixir-ls, but it turns out that alchemist does a lot of things that need to be implemented in the LSP server, so I’m going to do the refactor much more incrementally.

I’m looking forward to collaborating with the community on the growth of elixir_sense (the Elixir code analyzer), elixir-ls (the Elixir LSP server) and alchemist (the emacs client).

I’ve started forks of the back-end components ( https://github.com/elixir-lsp ) because I had a very hard time getting in touch with the maintainers – and because I think this stuff should belong to the community, not a single person.

5 Likes

lsp-mode changed quite a bit, now it comes with builtin support to elixir, thanks to https://github.com/emacs-lsp/lsp-mode/pull/569, my lsp-mode elixir config here

There is also a new lsp client for emacs, eglot, which is working better for me, my eglot elixir config here.


EDIT: elixir-ls master doesn’t work yet with eglot. This PR is needed at least for it to work, and this other PR is needed if you want to use the formatting.

3 Likes

You can also use this active fork of elixir-ls:

@Trevoke, @asummers, and I are working on maintaining elixir-ls and elixir_sense (used by elixir-ls) since progress on those projects has stalled.

I haven’t tested with eglot but those PR’s are merged into the fork so everything should work.

2 Likes

The README still refers to @JakeBecker’s VScode plugin, which installs his version of the LS. Can you provide any instruction of how to use your fork with any of the known plugins?

1 Like

Ah, you are correct! I’ll work on getting that updated, but I was also meaning to provide configuration examples for the elixir-ls elixir-lsp fork (and other projects). So I created a wiki post on this forum: Emacs - Elixir Setup Configuration Wiki. Specifically you want the elixir-ls elixir-lsp fork configuration section. Let me know if that makes sense/works for you, or even better just edit the post directly!

Also if anyone wants to contribute to the elixir-ls elixir-lsp fork, then hang out in the #alchemist-dev channel of the Elixir Slack (and maybe the #language-server channel but that isn’t very active).

2 Likes

I can’t see anything mentioning VScode in there, only Emacs, which I have dropped for elixir for now, but maybe I’ll check again in a couple of days if Emacs works better with your guide.

2 Likes

Ooops, yeah nothing there was specific to VScode. I don’t use that myself so I’m not sure how to switch the elixir-ls version that you’re using with the extension. But it looks like the “contributing” instructions in the repo may get you partway there.

1 Like