Skip to content

Commit 959e665

Browse files
committed
trace behaviour_info
1 parent 6ec0b39 commit 959e665

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

lib/elixir_sense/core/compiler.ex

+12
Original file line numberDiff line numberDiff line change
@@ -1799,6 +1799,18 @@ defmodule ElixirSense.Core.Compiler do
17991799
end)
18001800
end)
18011801

1802+
# elixir forces runtime dependency on behaviour via Module.force_behaviour_dependencies
1803+
# which emits a trace for a fake behaviour_info call
1804+
state =
1805+
Enum.reduce(state.behaviours[full], state, fn behaviour, state ->
1806+
state
1807+
|> State.add_call_to_line(
1808+
{behaviour, :behaviour_info, 1},
1809+
[line: meta[:line]],
1810+
:remote_function
1811+
)
1812+
end)
1813+
18021814
# restore vars from outer scope
18031815
# restore version counter
18041816
state =

test/elixir_sense/core/metadata_builder_test.exs

+21
Original file line numberDiff line numberDiff line change
@@ -7661,6 +7661,27 @@ defmodule ElixirSense.Core.MetadataBuilderTest do
76617661
end)
76627662
end
76637663

7664+
test "registers behaviour_info call on @behaviour" do
7665+
state =
7666+
"""
7667+
defmodule NyModule do
7668+
@behaviour MyBehaviour
7669+
end
7670+
"""
7671+
|> string_to_state
7672+
7673+
assert [
7674+
%CallInfo{func: :defmodule},
7675+
%CallInfo{
7676+
arity: 1,
7677+
position: {1, nil},
7678+
mod: MyBehaviour,
7679+
func: :behaviour_info,
7680+
kind: :remote_function
7681+
}
7682+
] = state.calls[1]
7683+
end
7684+
76647685
defmodule StructExpansion do
76657686
defstruct [:foo]
76667687
end

0 commit comments

Comments
 (0)