How to be productive without autocompletion?

Most of my experience comes from Dart and Kotlin, this is my first dynamic language. I recently tried to get into Elixir out of curiosity but it seems auto-completion does not work for code that is imported?

I was following the documentation page for Phoenix Controllers and one of the code samples is:

def index(conn, _params) do
  conn
  |> put_resp_content_type("text/xml")
  |> render("index.xml", content: some_xml_content)
end

Typing put_r and pressing ctrl + space does not suggest me put_resp_content_type. After searching a bit I found out this function is defined in the module Plug.Conn but even if I explictly do

require Plug.Conn
# OR
import Plug.Conn

The auto-completion still doesn’t work as I’d like. I am using ElixirLS on vscode. Should I just… have the documentation downloaded and ready?
Would doing something like

def index(conn, _params) do
  conn
  |> Plug.Conn.put_resp_content_type("text/xml")
  |> Phoenix.Controller.render("index.xml", content: some_xml_content)
end

Be considered unidiomatic? I was looking into F# and Falco and their approach is more friendly to auto-completion. The important bits of the framework belong to a module, so you’d do Requests.ofPlainText instead of using something “free-floating” in global space. Allowing you to type Requests. and trigger autocompletion from there. There’s another benefit though:

I know where the function comes from when reading the docs. To produce the example above, I had to manually find where render and put_resp_content_type come from since there isn’t even a import/require statement hinting at where to look.

I use both Elixir LS and the following plugin, even though they might conflict.

So I get everything working.

Also I’m not sure if adding @spec to our code improves some auto suggestions.

1 Like

The issue is probably because the version ElixirLS has been compiled with is different than the one of your project.

See Autocomplete/hover does not work properly for code aliases via use · Issue #193 · elixir-lsp/elixir-ls · GitHub

I use a little script to compile ElixirLS with my local version and that solves the issues with autocomplete when using use macro.

4 Likes