Skip to content

Commit

Permalink
store env on every node with meta
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszsamson committed Aug 22, 2024
1 parent d7cc89d commit b5d01ce
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
10 changes: 10 additions & 0 deletions lib/elixir_sense/core/compiler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ defmodule ElixirSense.Core.Compiler do

def expand(ast, state, env) do
try do
state =
case ast do
{_, meta, _} when is_list(meta) ->
add_current_env_to_line(state, meta, env)

# state
_ ->
state
end

do_expand(ast, state, env)
catch
kind, payload ->
Expand Down
34 changes: 26 additions & 8 deletions test/elixir_sense/core/metadata_builder_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,29 @@ defmodule ElixirSense.Core.MetadataBuilderTest do
assert Map.has_key?(state.lines_to_env[3].versioned_vars, {:abc, nil})

assert [
# %VarInfo{name: :abc, positions: [{1, 1}]},
%VarInfo{name: :abc, positions: [{2, 1}]}
%VarInfo{name: :abc, version: 1, positions: [{2, 1}]}
] = state |> get_line_vars(3)

assert [
%VarInfo{name: :abc, version: 0, positions: [{1, 1}]}
] = state |> get_line_vars(2)

assert state.vars_info_per_scope_id[0] == %{
{:abc, 0} => %VarInfo{
name: :abc,
positions: [{1, 1}],
scope_id: 0,
version: 0,
type: {:integer, 5}
},
{:abc, 1} => %VarInfo{
name: :abc,
positions: [{2, 1}],
scope_id: 0,
version: 1,
type: {:local_call, :foo, []}
}
}
end

test "binding in function call" do
Expand Down Expand Up @@ -564,7 +584,7 @@ defmodule ElixirSense.Core.MetadataBuilderTest do
|> string_to_state

assert Map.keys(state.lines_to_env[1].versioned_vars) == []
assert [] = state |> get_line_vars(3)
assert [] = state |> get_line_vars(1)

assert Map.keys(state.lines_to_env[2].versioned_vars) == [{:abc, nil}]

Expand All @@ -585,7 +605,7 @@ defmodule ElixirSense.Core.MetadataBuilderTest do
] = state |> get_line_vars(4)

assert Map.keys(state.lines_to_env[6].versioned_vars) == []
assert [] = state |> get_line_vars(3)
assert [] = state |> get_line_vars(6)
end

test "for bitstring" do
Expand Down Expand Up @@ -1686,21 +1706,19 @@ defmodule ElixirSense.Core.MetadataBuilderTest do
assert get_line_attributes(state, 4) == [
%AttributeInfo{
name: :myattribute,
positions: [{2, 3}, {3, 16}, {4, 16}],
positions: [{2, 3}, {3, 16}],
type: {:tuple, 2, [{:atom, :ok}, {:map, [abc: {:atom, nil}], nil}]}
}
]

assert [
%VarInfo{
name: :other,
# TODO do we need to rewrite? change Binding
# type: {:local_call, :elem, [{:attribute, :myattribute}, {:integer, 0}]}
type: {
:call,
{:atom, :erlang},
:element,
[integer: 1, attribute: :myattribute]
[{:integer, 1}, {:attribute, :myattribute}]
}
},
%VarInfo{
Expand Down

0 comments on commit b5d01ce

Please sign in to comment.