Skip to content

Autocomplete does not work for functions generated via macros in the same module/file. #435

@SergeyMosin

Description

@SergeyMosin

Environment

  • Elixir & Erlang versions (elixir --version): Erlang/OTP 26 [erts-14.2.5] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit:ns]
  • Elixir 1.15.7 (compiled with Erlang/OTP 26)
  • VSCode ElixirLS version: 0.23.1
  • Operating System Version: linux 6.8.0-40-generic, Ubuntu 22.04.5 LTS

Troubleshooting

  • Restart your editor (which will restart ElixirLS) sometimes fixes issues
  • Stop your editor, remove the entire .elixir_ls directory, then restart your editor

Description/Problem

Autocomplete does not work for functions generated via macros in the same module/file. However, it works when called from other modules/files.

Details

MyMacros.ex

defmodule MyMacros do
  defmacro enums_kv(kv) do
    Enum.map(kv, fn {k, v} ->
      quote do
        @spec unquote(k)() :: unquote(v)
        def unquote(k)(), do: unquote(v)
      end
    end)
  end

MyMod.ex (Autocomplete does NOT works when typing on or tw inside hello)

defmodule MyMod do
  require MyMacros
  MyMacros.enums_kv(one: 1, two: 2)
  # enums_kv(one: 1, two: 2) generates:
  #   def one, do: 1
  #   def two, do: 2

  def hello do
    one()
  end
end

MyOtherMod.ex (Autocomplete works when typing MyMod.t or MyMod.o inside hello)

defmodule MyOtherMod do
  def hello do
    MyMod.two()
  end
end

Demo/Video

video-demo.webm

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions