Skip to content

Commit

Permalink
Fix metadata builder to correctly handle pin operator
Browse files Browse the repository at this point in the history
  • Loading branch information
Goose97 committed Jul 13, 2023
1 parent 1166a2f commit 9dab90c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
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

0 comments on commit 9dab90c

Please sign in to comment.