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

Fix metadata builder to correctly handle pin operator #237

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/elixir_sense/core/metadata_builder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1820,6 +1820,9 @@ defmodule ElixirSense.Core.MetadataBuilder do
{:list, list |> Enum.map(&get_binding_type(state, &1))}
end

# pinned variable
def get_binding_type(state, {:^, _, [pinned]}), do: get_binding_type(state, pinned)

# local call
def get_binding_type(state, {var, _, args}) when is_atom(var) and is_list(args) do
{:local_call, var, Enum.map(args, &get_binding_type(state, &1))}
Expand Down
36 changes: 36 additions & 0 deletions test/elixir_sense/core/metadata_builder_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,42 @@ defmodule ElixirSense.Core.MetadataBuilderTest do
] = state |> get_line_vars(8)
end

test "vars binding by pattern matching with pin operators" do
state =
"""
defmodule MyModule do
def func(a) do
b = 1
case a do
%{b: ^2} = a1 -> 2
%{b: ^b} = a2 -> b
end
end
end
"""
|> string_to_state

vars = state |> get_line_vars(5)

assert %VarInfo{
name: :a1,
positions: [{5, 18}],
scope_id: 6,
is_definition: true,
type: {:map, [b: {:integer, 2}], nil}
} = Enum.find(vars, &(&1.name == :a1))

vars = state |> get_line_vars(6)

assert %VarInfo{
name: :a2,
positions: [{6, 18}],
scope_id: 7,
is_definition: true,
type: {:map, [b: {:variable, :b}], nil}
} = Enum.find(vars, &(&1.name == :a2))
end

test "rebinding vars" do
state =
"""
Expand Down