Emacs - Elixir Setup Configuration Wiki

Pr was merged, so the post can be updated :slight_smile:

Le epic gif
3 Likes

@axelson in the spacemacs part it is worth to specify either link to the layer doc about backend or write here, that in the layer definition you should set the backend

(elixir :variables elixir-backend 'lsp)

as alchemist is still the default backend (left it so, for backwards compatibility as elixir-ls requires additional step of installing the server itself)

1 Like

Hi, does anyone meet the error ā€œToo many open filesā€ in spacemacs when lsp is watching many files?

Loading /Users/james/.spacemacs.d/init.el (source)...done
Starting a server...
Spacemacs is ready.
Loading /Users/james/.emacs.d/.cache/recentf...done
Skipping check for new version (reason: dotfile)
[yas] Prepared just-in-time loading of snippets successfully.
LSP :: Connected to [elixir-ls:53015 status:starting].
LSP :: Connected to [elixir-ls:53267 status:starting].
init.el has auto save data; consider M-x recover-this-file
There are 14222 files in folder /Users/james/src/evercam_wechat/ and watching the repo which may slow Emacs down. To configure:
1. Use `lsp-enable-file-watchers' to disable file watchers globally or for the project(via .dir-local).
2. Increase/set to nil `lsp-file-watch-threshold' to remove the warning.
Do you want to continue? (y or n) n
There are 3013 files in folder /Users/james/src/brightu_umbrella/ and watching the repo which may slow Emacs down. To configure:
1. Use `lsp-enable-file-watchers' to disable file watchers globally or for the project(via .dir-local).
2. Increase/set to nil `lsp-file-watch-threshold' to remove the warning.
Do you want to continue? (y or n) y
LSP :: Connected to [elixir-ls:53267]. [3 times]
File local-variables error: (file-error Creating pipe Too many open files)
[persp-mode] Error: Can not autoresume perspectives -- (file-error Cannot redirect stderr Too many open files /dev/null)
user-error: Minibuffer window is not active
evil-line-move: Beginning of buffer [6 times]
evil-line-move: End of buffer [10 times]
Quit

The config is following:

     (elixir :variables
             elixir-backend 'lsp
             elixir-ls-path "~/src/elixir-ls/release")

Too many open files can happen everywhereā€¦

Please check the ulimit -n, perhaps even increase the limits of emacs parent environment (depending on how you start it).

1 Like

Thanks, Iā€™m on macOS, the default value is 256. Set the max open files limits and problem solved.

sudo launchctl limit maxfiles 65535 102400
2 Likes

Hi, did you figure this out? The codebase that I work on enforces strict credo standards so it would be nice for me to have credo working properly on save, just like it does under alchemist. For me the situation is exactly as you described, i.e. credo messages only show up upon lsp-ui changes.

No, I havenā€™t, and sadly enough Iā€™m still using Alchemist on my work computer.

Hello folks, does anyone have this issue with spacemacs develop branch?
If the post does not belong to this wiki, I will delete and create a separate post. Thank you!

@SZJX
I donā€™t think the issue is connected to lsp-mode or emacs in general.

lsp-mode will only report errors/warnings, that elixir-ls passes it. So in order to integrate credo to
lsp-mode it should be implemented in elixir-ls. I donā€™t know if elixir-ls has any kind of plugin endpoint though.

I.e. In python world there is a bunch linters you can use. If you want them to work with lsp, you need to add a plugin of that linter to python-language-server. So the ls will report messages from that linter to lsp-mode client.

We donā€™t need lsp-mode to report the warnings, because credo has its own flycheck plugin. Lint checkers for many languages work the same way, we just have to do a flycheck-add-next-checker. For example this configuration works fine for me for chaining hlint behind intero-mode in Haskell:

      (flycheck-add-next-checker 'intero
                                 '(warning . haskell-hlint))

Using the same method for Credo & LSP Mode does not work. I donā€™t know if you read my original message, but the problem is not that warnings are never reported. It is that they are not dismissed correctly, and may be masked if lsp-mode doesnā€™t have its own warnings to report.

One difference with the Elixir checker is that it only runs on save, Iā€™m not sure if thats why the problem exists.

I havenā€™t gotten a chance to try it out yet, but since this is a wiki feel free to go ahead and edit the wiki yourself :slight_smile:

I have a question about environent variables in Spacemacs + lsp + elixir_ls + direnv.
I have env variables needed to compile the project in .envrc.
When I first start the lsp-mode it tries to compile the project in test env but it uses the variables from ~/elixir_ls/release instread of ~/myproject.
I am not sure what is the correct way to solve it. Should I configure the lsp layer somehow to run the backend with correct variables, or is it a problem with elixir_ls?

.env files are just a convention, perhaps itā€™s better to explicitly load them? Projectile should be able to load from your env file and start the LS in a way that has the env properly loaded?

Projectile loads them for sure. The part that runs tests with , t t works and compiles files. Emacs direnv package makes sure that correct env is loaded for each buffer. The problem is that language server runs with different env. The one elixir_ls/release if I am not mistaken.

I think I know what is the problem. Direnv mode executes after lsp starts, so it is too late to set the variables. I am not sure how to control in what order do the modes when opening elixir file.

[EDIT:] Found a solution. I can start lsp in deferred mode. In layer config I donā€™t set lsp backend in variables. Jsut putting elixir there.

Later I add lsp to hooks like this in user-config

  (use-package lsp-mode
    :hook (elixir-mode . lsp-deferred)
    :diminish lsp-mode
    :commands (lsp lsp-deferred))
3 Likes

Does anyone have trouble with Eglot? It displays most of the doc string for functions in the mini buffer and provides auto completion via company-mode, but linting isnā€™t working. Flymake is stuck on ā€œFlymake:Wait[0 0]ā€ with no errors.

Using lsp-mode, do I need to add anything to make documenation of functions show? In VSCode for example if it autocompletes on Enum.map(enumerable, fun) it also shows what the map function does.

By updating with mix deps.update --all elixir-ls the problem looks solved

1 Like

I think it should just work by default, although you have to wait a second for it to show up. Hereā€™s what it looks like for me:

You can also press , h h when over a call to get the full docs in a new split.

1 Like

Hi Iā€™m new and interested in emacs so I try to setup elixir development on spacemacs.
itā€™s seem elixir-ls not working, when I open elixir-ls::stderr buffer it says

/Users/arpple/elixir-ls/release/language_server.sh: line 18: elixir: command not found

I open the shell in spacemacs and run elixir also get command not found so I tried to export my path from .zshrc and elixir now work in shell but still not found for elixir-ls

my machine is macos catalina version 10.15

actually Iā€™d tried spacemacs before with elixir and itā€™s work fine, not sure if itā€™s a about catalina update or something else