Pilgrim

Pilgrim

How is snippet expansion/code completion supposed to work in Emacs with eglot/elixir-ls

I’ve got elixir-mode and eglot configured in my emacs.d and it mostly works. One thing I can’t figure out though is how to work with the code completion (via company) in elixir code.

Say I type defm at this point I get the completion options pop up. I select defmodule and then it expands to

defmodule $1 do
        $0
end

But the cursor (point) moves to the end of end. I get no opportunity to specify the module name and also complete the module body.

When I disable eglot and use only elixir-mode I get the expected behaviour were selecting defmodule from the completion list places the cursor (point) between defmodule and do where I type the module name then another tab places the cursor inside the module body.

What is the way to work with what seems to be eglot’s way of code completion?

Marked As Solved

mpmiszczyk

mpmiszczyk

I run into same issue with my Emacs setup, and I was able to solve it.

Based on the github issue I was able to deduce that Eglot upon start communicates to Language Server that he supports snippets, and I would guess, that based on this start-up info it will either try to pass it into snippet engine or not. You could look into your *EGLOT (....) events* buffer; find first message ( with M-<), and verify your settings.

client-request (id:1) Fri Jan 31 00:35:47 2020:
(:jsonrpc "2.0" :id 1 :method "initialize" :params
          (:processId 14783 :rootPath .... 
                      (:workspace
                       ......
                        (:dynamicRegistration :json-false :completionItem
                                              (:snippetSupport t)
                                              :contextSupport t)

I was able to achieve such setup by installing Yasnippets, and turning them on in elixir-mode


(use-package elixir-mode)

(use-package eglot
  :commands (eglot eglot-ensures)
  :hook
  (elixir-mode . eglot-ensure)
  (before-save . eglot-format-buffer)
  :config
  (add-to-list
   `eglot-server-programs `(elixir-mode ,(expand-file-name  "~/elixir_ls/release/language_server.sh"))))

(use-package yasnippet
  :hook (elixir-mode . yas-minor-mode))

Also Liked

Pilgrim

Pilgrim

@rodrigues can I take a look around your emacs.d? My company config is really simple below and I spent hours going over it without success.

;; Company mode
(add-to-list 'completion-styles 'initials t)

(use-package company
  :ensure t
  :hook (after-init . global-company-mode)
  :init
  (setq company-minimum-prefix-length 2)
  ;;(setq company-auto-complete nil)
  (setq company-idle-delay 0)
  (setq company-require-match 'never)
  (setq-default company-dabbrev-other-buffers 'all
                company-tooltip-align-annotations t)
  (setq tab-always-indent 'complete)
  ;;(defvar completion-at-point-functions-saved nil)
  :config
  (define-key company-mode-map (kbd "M-/") 'company-complete)
  (define-key company-active-map (kbd "C-n") 'company-select-next)
  (define-key company-active-map (kbd "C-p") 'company-select-previous))

Eglot currently is setup like so

(use-package eglot
  :ensure t)

and Elixir’s looks like this:

(use-package elixir-mode
  :after (company flycheck)
  :ensure t
  :init
  ;;(add-to-list 'exec-path "/Users/napo/Github/elixir-ls/release")
  (add-to-list 'eglot-server-programs '(elixir-mode . ("/Users/napo/Github/elixir-ls/release/language_server.sh")))

  ;;(add-hook 'elixir-mode-hook #'lsp)
  (add-hook 'elixir-mode-hook 'eglot-ensure)
  (add-hook 'elixir-mode-hook 'flycheck-mode)
  (add-hook 'elixir-mode-hook #'smartparens-mode)
  (add-hook 'elixir-mode-hook
            (lambda () (add-hook 'before-save-hook 'eglot-format nil t))))
rodrigues

rodrigues

@Pilgrim my emacs.d repo gets constantly rebased with GitHub - purcell/emacs.d: An Emacs configuration bundle with batteries included · GitHub

Other than that, that’s my only company specific custom config:

(add-hook 'after-init-hook 'global-company-mode)
(setq company-dabbrev-downcase 0)
(setq company-idle-delay 0)

As for eglot/elixir, there it is, at the moment:

(require-package 'elixir-mode)
(require-package 'eglot)
(require 'eglot)
(require 'eldoc-box)

(add-to-list
 'eglot-server-programs
 '(elixir-mode . ("sh" "/Users/rodrigues/code/elixir-ls/release/language_server.sh")))

(add-hook
 'elixir-mode-hook
 (lambda ()
   (subword-mode)
   (eglot-ensure)
   (company-mode)
   (flymake-mode)
   (add-hook 'before-save-hook 'eglot-format nil t)))

Where Next?

Popular in Questions Top

_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
Kurisu
For example for a current url like http://localhost:4000/cosmetic/products?_utf8=✓&amp;query=perfume&amp;page=2, I would like to get: ...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
JulienCorb
I am trying to implement my new.html.eex file to create new posts on my website. new.html.eex: &lt;h1&gt;Create Post&lt;/h1&gt; &lt;%= ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New

Other popular topics Top

sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 43487 311
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52673 488
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement