Skip to content

Commit a0aa183

Browse files
authored
Merge pull request #1130 from sabiwara/require-defmacro
Avoid requiring the module when using local macros
2 parents 1785064 + 56b036d commit a0aa183

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

apps/elixir_ls_utils/lib/completion_engine.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,7 @@ defmodule ElixirLS.Utils.CompletionEngine do
10281028
needed_requires =
10291029
for func_kind <- func_kinds do
10301030
if func_kind in [:macro, :defmacro, :defguard] and mod not in env.requires and
1031-
mod != Kernel.SpecialForms do
1031+
mod != Kernel.SpecialForms and mod != env.module do
10321032
mod
10331033
end
10341034
end

apps/elixir_ls_utils/test/complete_test.exs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2208,6 +2208,32 @@ defmodule ElixirLS.Utils.CompletionEngineTest do
22082208
] = expand(~c"unquote", %Env{requires: []})
22092209
end
22102210

2211+
2212+
test "macros from the same module should not add needed_require" do
2213+
macro_info = %ElixirSense.Core.State.ModFunInfo{
2214+
type: :defmacro,
2215+
params: [[:_]]
2216+
}
2217+
2218+
metadata = %Metadata{
2219+
mods_funs_to_positions: %{
2220+
{MyModule, nil, nil} => %ElixirSense.Core.State.ModFunInfo{},
2221+
{MyModule, :info, 1} => macro_info
2222+
}
2223+
}
2224+
2225+
assert [
2226+
%{
2227+
name: "info",
2228+
arity: 1,
2229+
type: :macro,
2230+
origin: "MyModule",
2231+
needed_require: nil,
2232+
visibility: :public
2233+
}
2234+
] = expand(~c"inf", %Env{requires: [], module: MyModule}, metadata)
2235+
end
2236+
22112237
if Version.match?(System.version(), ">= 1.14.0") do
22122238
test "Application.compile_env classified as macro" do
22132239
assert [

0 commit comments

Comments
 (0)