How to get code completion in IEx programmatically?

Hi all,

I’m new to Elixir. I’m trying to use IEx in Emacs. Right now the code completion isn’t supported, and I don’t know how to get the completion from Elixir/IEx programmatically, I tried IEx.Autocomplete.expand "String." but it doesn’t work (I expect it to return a list of completions so I can use it from Emacs.):

iex(11)> IEx.Autocomplete.expand "String."
** (FunctionClauseError) no function clause matching in IEx.Autocomplete.expand/2

    The following arguments were given to IEx.Autocomplete.expand/2:

        # 1
        "String."

        # 2
        IEx.Server

    Attempted function clauses (showing 2 out of 2):

        def expand([], server)
        def expand([h | t] = expr, server)

    (iex) lib/iex/autocomplete.ex:6: IEx.Autocomplete.expand/2

Emacs setup:

(define-derived-mode inferior-elixir-mode comint-mode "Inferior Elixir"
  "Major mode for Elixir inferior process."
  (setq comint-prompt-regexp (rx bol (or "iex" "...") "(" (1+ num) ") ")))

(defun run-elixir ()
  (interactive)
  (with-current-buffer (make-comint-in-buffer "Elixir" "*Elixir*" "iex" nil)
    (inferior-elixir-mode)
    (display-buffer (current-buffer))))

Autocompletiond ist supported, the elixir language server just got forked and is currently better supported through Emacs than visual studio code. Just search the forum. It was posted this year AFAIR.

I think you mean this post: Emacs lsp-mode (language server) + elixir-ls anyone?

And this emacs configuration: Emacs - Elixir Setup Configuration Wiki

It does have some support for autocomplete as well as some other features.

1 Like

I’ve already set Eglot + Elixir-Ls but it doesn’t seem there is a REPL

I also wanted to note that IEx.Autocomplete is labeled with @moduledoc false which means that it is a private api that shouldn’t be relied upon. It also looks like the functions in IEx.Autocomplete are using a bunch of private modules/functions as well. So I think you may need to raise an issue on the Elixir github to ask for programmatic access to autocomplete.

1 Like