Emacs - Elixir Setup Configuration Wiki

yes, thank you @axelson, after run company mode I get an awesome autocomplete, but seems that flymake is not working for me…I don’t get any error warning, flymake or flycheck works ok with lsp-mode? would be great include some gif about the different lsp features running…

second question: are you using spacemacs?..not sure but seems that they remove the lsp layer…I always get
Warning: Unknown layer lsp declared in dotfile.

the only way it works for me (or at least he tried to load, because he then failed to tell me that there was no lsp server) was installing this like an additional packges…

1 Like

@clag I believe that flymake or flycheck is integrated by default with lsp-mode. I’m not an expert at all the emacs packages but I do get compilation warnings and credo warnings with lsp-mode, and I’m fairly sure that happens via flymake (or maybe flycheck).

Yes I am. Sorry, looks like I missed another step in the wiki! Currently, in order to use the lsp layer (which uses lsp-mode) you need to be on the develop branch of spacemacs (your ~/.emacs.d should be on the develop branch). I’ve added this to the wiki now :blush:

1 Like

thank you @axelson, I decide give a try to lsp-mode, after move the language_server.sh file to my /bin folder seems that emacs can detect this and start…but now I get this error

server elixir:9872 status:starting exited with status exit. Do you want to restart (y or n)
I press y but this fails every time…

I also tried the fork that you mention and I get the same message…

do you know what could be the issue here?

thank you @axelson for take the time to write the guide and help us…

@clag you can’t just move the language_server.sh to a different directory because all that does is call the .ez files in the same directory. There shouldn’t be any need to move language_server.sh to a /bin directory because emacs doesn’t find language_server.sh via $PATH but via the use-package command. But now re-reading the setup instructions it looks like the instructions were saying that use-package was necessary for only vanilla emacs. I’ll update those in a bit.

For now try adding:

  (use-package lsp-mode
    :commands lsp
    :ensure t
    :diminish lsp-mode
    :hook
    (elixir-mode . lsp)
    :init
    (add-to-list 'exec-path "path-to-elixir-ls/release"))

To your spacemacs user-config, and fill in "path-to-elixir-ls/release" with the path to the release folder in your elixir-ls installation.

Thanks for your post. I am absolute new to elixir and spacemacs, and try the config above, but have no luck to success, is there something wrong in the init.el?

(defun dotspacemacs/user-config '(use-package lsp-mode
:commands lsp
:ensure t
:diminish lsp-mode
:hook
(elixir-mode . lsp)
:init
(add-to-list 'exec-path “C:/elixir-ls/release”)))

@DavidCheuk welcome to the forum and Elixir!

I would expect your spacemacs user config to look slightly different. I think the default looks like:

(defun dotspacemacs/user-config ()
  ;; "Configuration for user code:
  ;; This function is called at the very end of Spacemacs startup, after layer
  ;; configuration.
  ;;  Put your configuration code here, except for variables that should be set
  ;; before packages are loaded."
)

So your configuration after adding the lsp-mode configuration should look like:

(defun dotspacemacs/user-config ()
  ;; "Configuration for user code:
  ;; This function is called at the very end of Spacemacs startup, after layer
  ;; configuration.
  ;;  Put your configuration code here, except for variables that should be set
  ;; before packages are loaded."
  (use-package lsp-mode
    :commands lsp
    :ensure t
    :diminish lsp-mode
    :hook
    (elixir-mode . lsp)
    :init
    (add-to-list 'exec-path "C:/elixir-ls/release"))
)

(notice there is no ' before the use-package statement).

2 Likes

Thx a lot, at least I can load spacemacs normally now, but when I open an elixir file, it said “LSP :: No LSP server for elixir-mode.” I have the elixir-ls correctly setup already, what could be the cause? Thx again!

LSP :: No LSP server for elixir-mode.

That indicates that lsp-mode is unable to find the language_server.bat for elixir. When you ran mix elixir_ls.release did it complete successfully? What are the contents of your C:/elixir-ls/release directory?

I think it completed successfully, I can find language_server.bat in the c:\elixir-ls\release. I get this when I run it:
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}}

Hmm, do you have anything beyond that error in your *messages* or *lsp-log* buffers?

I was having the same problem @DavidCheuk, but then I realized that another part of my dot files was overwriting my exec-path after my lsp-mode configuration and therefore dropping the directory with the language server file from exec-path.

1 Like

In my case it was (exec-path-from-shell-initialize) overwriting things. I just changed the order of config code loading so that my lsp-mode config was after that and things came right with it.

Also note that I had to install the use-package package to use the given lsp-mode config.

1 Like

I am not sure, I am just using the default emacs v26 and latest spacemacs. Here is the init.el content in my .spacemacs.d folder, also I cannot install use-package as it is like already included in the test branch…

(defun dotspacemacs/layers ()
  (setq-default
   dotspacemacs-distribution 'spacemacs
   dotspacemacs-excluded-packages '(alchemist)
   dotspacemacs-additional-packages '(exunit
                                      elixir-mode
                                      lsp-elixir.el)
   dotspacemacs-configuration-layers '(
                                       (org :variables
                                            org-enable-github-support t
                                            org-enable-bootstrap-support t
                                            org-enable-reveal-js-support t
                                            )
                                       bibtex
                                       (latex :variables
                                              latex-enable-auto-fill t
                                              latex-enable-folding t
                                              )
                                       html
                                       emacs-lisp
                                       markdown
                                       syntax-checking
                                       auto-completion
                                       git 
                                       html
                                       colors
                                       themes-megapack
                                       lsp
                                       dap
                                       erlang
                                       )))

(defun dotspacemacs/init ())
(defun dotspacemacs/user-init ())
(defun dotspacemacs/config ())
(defun dotspacemacs/user-config ()
(use-package lsp-mode
    :commands lsp
    :ensure t
    :diminish lsp-mode
    :hook
    (elixir-mode . lsp)
    :init
    (add-to-list 'exec-path "c:/elixir-ls/release"))
(require 'dap-elixir)
(dap-ui-mode)
(dap-mode)
(use-package lsp-ui :commands lsp-ui-mode)
(use-package company-lsp :commands company-lsp))

(setq-default dotspacemacs-themes '(twilight-anti-bright))

(defun dotspacemacs/emacs-custom-settings ()
  "Emacs custom settings.
This is an auto-generated function, do not modify its content directly, use
Emacs customize menu instead.
This function is called at the very end of Spacemacs initialization."
(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(package-selected-packages
   (quote
    (dap-mode lsp-elixir zenburn-theme zen-and-art-theme yasnippet-snippets ws-butler writeroom-mode winum white-sand-theme which-key web-mode web-beautify volatile-highlights vi-tilde-fringe uuidgen use-package underwater-theme ujelly-theme twilight-theme twilight-bright-theme twilight-anti-bright-theme treemacs-projectile treemacs-evil toxi-theme toc-org tao-theme tangotango-theme tango-plus-theme tango-2-theme tagedit symon sunny-day-theme sublime-themes subatomic256-theme subatomic-theme string-inflection spaceline-all-the-icons spacegray-theme soothe-theme solarized-theme soft-stone-theme soft-morning-theme soft-charcoal-theme smyx-theme smeargle slim-mode seti-theme scss-mode sass-mode reverse-theme restart-emacs rebecca-theme rainbow-mode rainbow-identifiers rainbow-delimiters railscasts-theme purple-haze-theme pug-mode professional-theme prettier-js popwin planet-theme phoenix-dark-pink-theme phoenix-dark-mono-theme persp-mode pcre2el password-generator paradox ox-twbs ox-reveal ox-gfm overseer orgit organic-green-theme org-ref org-projectile org-present org-pomodoro org-mime org-download org-bullets org-brain open-junk-file omtose-phellack-theme oldlace-theme occidental-theme obsidian-theme ob-elixir noctilux-theme naquadah-theme nameless mustang-theme move-text monokai-theme monochrome-theme molokai-theme moe-theme mmm-mode minimal-theme material-theme markdown-toc majapahit-theme magit-svn magit-gitflow madhat2r-theme macrostep lush-theme lsp-ui lorem-ipsum link-hint light-soap-theme kaolin-themes jbeans-theme jazz-theme ir-black-theme inkpot-theme indent-guide impatient-mode hungry-delete hl-todo highlight-parentheses highlight-numbers highlight-indentation heroku-theme hemisu-theme helm-xref helm-themes helm-swoop helm-purpose helm-projectile helm-org-rifle helm-mode-manager helm-make helm-gitignore helm-git-grep helm-flx helm-descbinds helm-css-scss helm-company helm-c-yasnippet helm-ag hc-zenburn-theme gruvbox-theme gruber-darker-theme grandshell-theme gotham-theme google-translate golden-ratio gnuplot gitignore-templates gitconfig-mode gitattributes-mode git-timemachine git-messenger git-link gh-md gandalf-theme fuzzy font-lock+ flycheck-pos-tip flycheck-mix flycheck-credo flx-ido flatui-theme flatland-theme fill-column-indicator farmhouse-theme fancy-battery eziam-theme eyebrowse expand-region exotica-theme evil-visualstar evil-visual-mark-mode evil-unimpaired evil-tutor evil-surround evil-org evil-numbers evil-nerd-commenter evil-matchit evil-magit evil-lisp-state evil-lion evil-indent-plus evil-iedit-state evil-goggles evil-exchange evil-escape evil-ediff evil-cleverparens evil-args evil-anzu eval-sexp-fu espresso-theme erlang emmet-mode elisp-slime-nav editorconfig dumb-jump dracula-theme dotenv-mode doom-themes doom-modeline django-theme diminish define-word darktooth-theme darkokai-theme darkmine-theme darkburn-theme dakrone-theme cyberpunk-theme counsel-projectile company-web company-statistics company-lsp company-auctex column-enforce-mode color-theme-sanityinc-tomorrow color-theme-sanityinc-solarized color-identifiers-mode clues-theme clean-aindent-mode cherry-blossom-theme centered-cursor-mode busybee-theme bubbleberry-theme birds-of-paradise-plus-theme badwolf-theme auto-yasnippet auto-highlight-symbol auto-compile apropospriate-theme anti-zenburn-theme ample-zen-theme ample-theme alect-themes aggressive-indent afternoon-theme ace-link ace-jump-helm-line ac-ispell))))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )
)

It’s probably not the issue (more likely the c:/elixir-ls/release is either not there or perhaps not correct permissions), but to double check I would move this to end of that config file:

(use-package lsp-mode
    :commands lsp
    :ensure t
    :diminish lsp-mode
    :hook
    (elixir-mode . lsp)
    :init
    (add-to-list 'exec-path "c:/elixir-ls/release"))
(require 'dap-elixir)
(dap-ui-mode)
(dap-mode)
(use-package lsp-ui :commands lsp-ui-mode)
(use-package company-lsp :commands company-lsp))

and restart and see if you have any luck.

Can some one translate this into plain elisp? Not everyone uses use-package

@NobbZ I’m not sure what the exact translation is in plain elisp but you can take a look at the official lsp-mode installation instructions.

I spent several hours and realize that

in the last line of this config

(use-package lsp-mode
    :commands lsp
    :ensure t
    :diminish lsp-mode
    :hook
    (elixir-mode . lsp)
    :init
    (add-to-list 'exec-path "path-to-elixir-ls/release"))

the path shouldn’t include the language_server.sh, just the path to elixir-ls/release and it finally works.

3 Likes

Thanks for this, it made the transition from Alchemist in spacemacs real easy.

Re: exunit and spacemacs:
Spacemacs users should add non-layer packages to dotspacemacs-additional-packages to get a portable setup.
It looks like the recommended spacemacs exunit bindings might be backwards between ‘tb’ and ‘ta’.

1 Like

Oh, it say