Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
2 tasks done
SergeyMosin opened this issue Sep 21, 2024 · 1 comment
Closed
2 tasks done

Comments

@SergeyMosin
Copy link

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
@lukaszsamson
Copy link
Collaborator

This is the current limitation - only trivial use macros are expanded. This branch has change replacing the inference engine and rebuilding it on top of new Macro.Env API elixir-lsp/elixir-ls#1116. With that macro expansion is possible in more places and this scenario is working.
Screenshot 2024-09-21 at 15 15 38

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants