Neovim elixirls failed autocompletion for local module

Begin learning elixir recently, and i was setup the elixirls in neovim following this guide. I could get most of the lsp elixirls feature work, such as doc hover, snippet, autocompletion, and so on, but I found I just can’t get the autocompeletion work for local module in another file. I’ll describe my problem as follows:

I’ve got two files in same directory, person.exs and main.exs:

![file1](/Users/huibosa/Desktop/Screenshot 2023-10-03 at 4.14.18 PM.png)

![file2](/Users/huibosa/Desktop/Screenshot 2023-10-03 at 4.15.35 PM.png)

which can be seen from the pictures that the autocompeletion source for module Person failed in main.exs. However, when I move the statements to person.exs`, I could get the expected autocompeletion:

![file3](/Users/huibosa/Desktop/Screenshot 2023-10-03 at 4.16.36 PM.png)

At first I thought this would be a lack of implementation of something in elixirls, but when I switch to vscode, where I’ve installed the elixirls viscose extension, finding that the autocompeletion works as ecpected:

![file4](/Users/huibosa/Desktop/Screenshot 2023-10-03 at 3.59.40 PM.png)

To give you more information:

  • Neovim version: v0.9.2
  • Elixirs version: v0.16.0
  • OS: mac

Autocompletion for files outside a mix project should only be limited to the current open file. So you can’t get auto completion from “person.exs” in “main.exs”. And I’ve tested it in both Neovim and VSCode.
Can you reupload those broken images if I misunderstood something?

1 Like

Thanks for your generous help. Since the forum system tells me that the new user can’t upload a picture, I’ve get the help from the github issue.

Furtherly, for any beginner like me from other languages who wants to get the autocompletion in a “single-file-script”, I recommend just move the code snippets inside the module, like the run() function below:

defmodule People.Person do
  alias People.Person

  defstruct first_name: nil,
            last_name: nil,
            birthday: nil,
            location: "home"

  def full_name(%__MODULE__{first_name: first_name, last_name: nil}) do

  def full_name(%__MODULE__{first_name: first_name, last_name: last_name}) do
    "#{first_name} #{last_name}"

  def age(%__MODULE__{birthday: birthday}) do
    days = Date.diff(Date.utc_today(), birthday)
    days / 365.25

  def toggle_location(%__MODULE__{location: "home"} = person) do
    person |> set_location("away")

  def toggle_location(%__MODULE__{location: "away"} = person) do
    person |> set_location("home")

  defp set_location(%__MODULE__{} = person, location) do
    %{person | location: location}

  def run() do
    person = %Person{
      first_name: "foo",
      last_name: "bla",
      birthday: ~D{1995-03-19}

    person |> Person.full_name() |> IO.puts()