Skip to content

Commit

Permalink
fix invalid completed def type when function and macro have the same …
Browse files Browse the repository at this point in the history
…name
  • Loading branch information
lukaszsamson committed Jan 10, 2024
1 parent 93c924b commit 0fa1e57
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 15 deletions.
42 changes: 27 additions & 15 deletions lib/elixir_sense/providers/suggestion/complete.ex
Original file line number Diff line number Diff line change
Expand Up @@ -954,27 +954,29 @@ defmodule ElixirSense.Providers.Suggestion.Complete do
doc = {Introspection.extract_summary_from_docs(doc_str), meta}

case :lists.keyfind(f, 1, acc) do
{f, aa, def_arities, func_kind, docs, specs, args} ->
{f, aa, def_arities, func_kinds, docs, specs, args} ->
:lists.keyreplace(
f,
1,
acc,
{f, [a | aa], [def_a | def_arities], func_kind, [doc | docs], [spec | specs],
[arg | args]}
{f, [a | aa], [def_a | def_arities], [func_kind | func_kinds], [doc | docs],
[spec | specs], [arg | args]}
)

false ->
[{f, [a], [def_a], func_kind, [doc], [spec], [arg]} | acc]
[{f, [a], [def_a], [func_kind], [doc], [spec], [arg]} | acc]
end
end)

for {fun, arities, def_arities, func_kind, docs, specs, args} <- list,
for {fun, arities, def_arities, func_kinds, docs, specs, args} <- list,
name = Atom.to_string(fun),
if(exact?, do: name == hint, else: Matcher.match?(name, hint)) do
needed_require =
if func_kind in [:macro, :defmacro, :defguard] and mod not in env.requires and
mod != Kernel.SpecialForms do
mod
needed_requires =
for func_kind <- func_kinds do
if func_kind in [:macro, :defmacro, :defguard] and mod not in env.requires and
mod != Kernel.SpecialForms do
mod
end
end

needed_imports =
Expand All @@ -995,10 +997,10 @@ defmodule ElixirSense.Providers.Suggestion.Complete do
arities: arities,
def_arities: def_arities,
module: mod,
func_kind: func_kind,
func_kinds: func_kinds,
docs: docs,
specs: specs,
needed_require: needed_require,
needed_requires: needed_requires,
needed_imports: needed_imports,
args: args
}
Expand Down Expand Up @@ -1364,15 +1366,25 @@ defmodule ElixirSense.Providers.Suggestion.Complete do
arities: arities,
def_arities: def_arities,
needed_imports: needed_imports,
needed_require: needed_require,
needed_requires: needed_requires,
module: mod,
func_kind: func_kind,
func_kinds: func_kinds,
docs: docs,
specs: specs,
args: args
}) do
for e <- Enum.zip([arities, docs, specs, args, def_arities, needed_imports]),
{a, {doc, metadata}, spec, args, def_arity, needed_import} = e do
for e <-
Enum.zip([
arities,
docs,
specs,
args,
def_arities,
func_kinds,
needed_imports,
needed_requires
]),
{a, {doc, metadata}, spec, args, def_arity, func_kind, needed_import, needed_require} = e do
kind =
case func_kind do
k when k in [:macro, :defmacro, :defmacrop, :defguard, :defguardp] -> :macro
Expand Down
40 changes: 40 additions & 0 deletions test/elixir_sense/providers/suggestion/complete_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2204,4 +2204,44 @@ defmodule ElixirSense.Providers.Suggestion.CompleteTest do
_
] = expand(~c"unquote", %Env{requires: []})
end

test "Application.compile_env classified as macro" do

Check failure on line 2208 in test/elixir_sense/providers/suggestion/complete_test.exs

View workflow job for this annotation

GitHub Actions / mix test (Elixir 1.13.x | Erlang/OTP 22.x)

test Application.compile_env classified as macro (ElixirSense.Providers.Suggestion.CompleteTest)

Check failure on line 2208 in test/elixir_sense/providers/suggestion/complete_test.exs

View workflow job for this annotation

GitHub Actions / mix test (Elixir 1.13.x | Erlang/OTP 24.x)

test Application.compile_env classified as macro (ElixirSense.Providers.Suggestion.CompleteTest)

Check failure on line 2208 in test/elixir_sense/providers/suggestion/complete_test.exs

View workflow job for this annotation

GitHub Actions / mix test (Elixir 1.13.x | Erlang/OTP 25.x)

test Application.compile_env classified as macro (ElixirSense.Providers.Suggestion.CompleteTest)

Check failure on line 2208 in test/elixir_sense/providers/suggestion/complete_test.exs

View workflow job for this annotation

GitHub Actions / mix test (Elixir 1.13.x | Erlang/OTP 23.x)

test Application.compile_env classified as macro (ElixirSense.Providers.Suggestion.CompleteTest)

Check failure on line 2208 in test/elixir_sense/providers/suggestion/complete_test.exs

View workflow job for this annotation

GitHub Actions / mix test windows (Elixir 1.13.x | Erlang/OTP 24.x)

test Application.compile_env classified as macro (ElixirSense.Providers.Suggestion.CompleteTest)

Check failure on line 2208 in test/elixir_sense/providers/suggestion/complete_test.exs

View workflow job for this annotation

GitHub Actions / mix test windows (Elixir 1.13.x | Erlang/OTP 22.x)

test Application.compile_env classified as macro (ElixirSense.Providers.Suggestion.CompleteTest)

Check failure on line 2208 in test/elixir_sense/providers/suggestion/complete_test.exs

View workflow job for this annotation

GitHub Actions / mix test windows (Elixir 1.13.x | Erlang/OTP 23.x)

test Application.compile_env classified as macro (ElixirSense.Providers.Suggestion.CompleteTest)

Check failure on line 2208 in test/elixir_sense/providers/suggestion/complete_test.exs

View workflow job for this annotation

GitHub Actions / mix test windows (Elixir 1.13.x | Erlang/OTP 25.x)

test Application.compile_env classified as macro (ElixirSense.Providers.Suggestion.CompleteTest)
assert [
%{
name: "compile_env",
arity: 2,
type: :macro,
origin: "Application",
needed_require: "Application"
},
%{
name: "compile_env",
arity: 3,
type: :macro,
origin: "Application",
needed_require: "Application"
},
%{
name: "compile_env",
arity: 4,
type: :function,
origin: "Application",
needed_require: nil
},
%{
name: "compile_env!",
arity: 2,
type: :macro,
origin: "Application",
needed_require: "Application"
},
%{
name: "compile_env!",
arity: 3,
type: :function,
origin: "Application",
needed_require: nil
}
] = expand(~c"Application.compile_e")
end
end

0 comments on commit 0fa1e57

Please sign in to comment.