Skip to content

Commit

Permalink
fix regression in call discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszsamson committed Jul 7, 2023
1 parent 24e542c commit a8c8925
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 17 deletions.
47 changes: 30 additions & 17 deletions lib/elixir_sense/core/metadata_builder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1138,23 +1138,6 @@ defmodule ElixirSense.Core.MetadataBuilder do
|> result(ast)
end

defp pre({call, meta, params} = ast, state)
when is_call(call, params) and is_call_meta(meta) do
line = Keyword.fetch!(meta, :line)
column = Keyword.fetch!(meta, :column)

state =
if String.starts_with?(to_string(call), "__atom_elixir_marker_") do
state
else
add_call_to_line(state, {nil, call, length(params)}, {line, column})
end

state
|> add_current_env_to_line(line)
|> result(ast)
end

defp pre(
{{:., meta1, [{:__aliases__, _, module_expression = [:Record]}, call]}, meta,
params = [name, _]} = ast,
Expand Down Expand Up @@ -1258,6 +1241,36 @@ defmodule ElixirSense.Core.MetadataBuilder do
|> result(ast)
end

defp pre({call, meta, params} = ast, state)
when is_call(call, params) do
case Keyword.get(meta, :line) do
nil ->
{ast, state}

_ ->
line = Keyword.fetch!(meta, :line)

if not Keyword.get(meta, :no_call, false) do
column = Keyword.fetch!(meta, :column)

state =
if String.starts_with?(to_string(call), "__atom_elixir_marker_") do
state
else
add_call_to_line(state, {nil, call, length(params)}, {line, column})
end

state
|> add_current_env_to_line(line)
|> result(ast)
else
state
|> add_current_env_to_line(line)
|> result(ast)
end
end
end

# Any other tuple with a line
defp pre({_, meta, _} = ast, state) do
case Keyword.get(meta, :line) do
Expand Down
2 changes: 2 additions & 0 deletions lib/elixir_sense/core/state.ex
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,8 @@ defmodule ElixirSense.Core.State do
defp after_elixir_prefix([Elixir | rest]), do: rest
defp after_elixir_prefix(rest), do: rest

def add_call_to_line(%__MODULE__{} = state, {nil, :__block__, _}, _position), do: state

def add_call_to_line(%__MODULE__{} = state, {mod, func, arity}, {line, _column} = position) do
call = %CallInfo{mod: mod, func: func, arity: arity, position: position}

Expand Down
25 changes: 25 additions & 0 deletions test/elixir_sense/core/metadata_builder_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4446,6 +4446,31 @@ defmodule ElixirSense.Core.MetadataBuilderTest do
assert state.calls == %{3 => [%CallInfo{arity: 1, func: :func, position: {3, 6}, mod: nil}]}
end

test "registers calls on ex_unit DSL" do
state =
"""
defmodule MyModuleTest do
use ExUnit.Case
describe "describe1" do
test "test1" do
end
end
test "test2" do
end
end
"""
|> string_to_state

assert state.calls == %{
2 => [%CallInfo{arity: 2, position: {2, 3}, func: :unless, mod: nil}],
4 => [%CallInfo{arity: 2, position: {4, 3}, func: :describe, mod: nil}],
5 => [%CallInfo{arity: 2, position: {5, 5}, func: :test, mod: nil}],
9 => [%CallInfo{arity: 2, position: {9, 3}, func: :test, mod: nil}]
}
end

test "registers types" do
state =
"""
Expand Down

0 comments on commit a8c8925

Please sign in to comment.