Elixir-ls snippets insert tabs with emacs lsp-mode

Screen Shot 2020-08-19 at 8.59.16 AM

I haven’t hit upon the correct setting to solve the annoying problem in the image above: when snippets complete, tabs are inserted instead of spaces. I’ve tried a few things including verifying that indent-tabs-mode is nil. I’ve also tried toggling lsp-enable-indentation but that setting has no effect. I’m using doom-emacs with emacs-lsp and elixir-ls. It’s working really well, except for this issue.

Any ideas? Thanks!

Hmmm, if you’re using a recent version of ElixirLS (0.5.0 or master) then the do end is not inserted by ElixirLS but instead by yasnippet. Do you have ~/.emacs.d/.local/straight/repos/doom-snippets/elixir-mode/do on your machine? Does it have a tab character?

If you’re using an earlier version of ElixirLS the do end snippet was removed in:

Thanks for responding. :slight_smile:

I’m using the latest master of ElixirLS and have this in my ~/.doom.d/config.el

(setq lsp-clients-elixir-server-executable "~/code/tools/elixir-ls/release/language_server.sh")
(add-hook 'before-save-hook (lambda () (when (eq 'elixir-mode major-mode)
                                         (lsp-format-buffer))))

I have yasnippet installed and yasnippet-minor-mode is enabled. When I run yas-insert-snippet I get the output I prefer. However, lsp-mode is picking the snippets from ElixirLS by default (see screenshot below). I do notice there’s a tab in those snippet definitions. But that doesn’t seem to be an issue in VS Code, only in Emacs.

I’ve looked around for a way to force lsp-mode to prefer yasnippets, but haven’t hit upon the right config just yet. It’s not so bad, since I’m formatting the buffer on save - and I save a lot.

1 Like