Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszsamson committed Aug 29, 2024
1 parent 3731b6a commit 51f3c44
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 46 deletions.
17 changes: 9 additions & 8 deletions lib/elixir_sense/core/compiler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1522,19 +1522,21 @@ defmodule ElixirSense.Core.Compiler do
# elixir dispatches callbacks by raw dispatch and eval_forms
# instead we expand a bock with require and possibly expand macros
# we do not attempt to exec function callbacks
ast = {:__block__, [],
[
{:require, [], [hd(target)]},
{{:., [], target}, [], [env]}
]}
ast =
{:__block__, [],
[
{:require, [], [hd(target)]},
{{:., [], target}, [], [env]}
]}

{_result, state, env} = expand(ast, state, env)
{remove_func_vars_scope(state, state_orig), env}
end)

# restore vars from outer scope
# restore version counter
state = state
state =
state
|> apply_optional_callbacks(%{env | module: full})
|> remove_vars_scope(state_orig, true)
|> remove_attributes_scope
Expand Down Expand Up @@ -2142,8 +2144,7 @@ defmodule ElixirSense.Core.Compiler do

{e_expr, se, _ee} = expand_for_do_block(expr, sc, ec, maybe_reduce)

{{:for, meta, e_cases ++ [[{:do, e_expr} | normalized_opts]]},
remove_vars_scope(se, s), e}
{{:for, meta, e_cases ++ [[{:do, e_expr} | normalized_opts]]}, remove_vars_scope(se, s), e}
end

defp expand_for_do_block([{:->, _, _} | _] = clauses, s, e, false) do
Expand Down
2 changes: 1 addition & 1 deletion lib/elixir_sense/core/metadata_builder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ defmodule ElixirSense.Core.MetadataBuilder do
end
}

{_ast, state, _env} =Compiler.expand(ast, state_orig, Compiler.env())
{_ast, state, _env} = Compiler.expand(ast, state_orig, Compiler.env())

state
|> remove_attributes_scope
Expand Down
12 changes: 9 additions & 3 deletions lib/elixir_sense/core/state.ex
Original file line number Diff line number Diff line change
Expand Up @@ -820,8 +820,13 @@ defmodule ElixirSense.Core.State do
%__MODULE__{state | attributes: [[] | state.attributes], scope_attributes: [[]]}
end

def remove_vars_scope(%__MODULE__{} = state, %{vars: vars, unused: unused}, restore_version_counter \\ false) do
def remove_vars_scope(
%__MODULE__{} = state,
%{vars: vars, unused: unused},
restore_version_counter \\ false
) do
state = maybe_move_vars_to_outer_scope(state)

state = %__MODULE__{
state
| scope_ids: tl(state.scope_ids),
Expand Down Expand Up @@ -1254,8 +1259,9 @@ defmodule ElixirSense.Core.State do
def default_env, do: %ElixirSense.Core.State.Env{}

defp maybe_move_vars_to_outer_scope(
%__MODULE__{vars_info: [current_scope_vars, outer_scope_vars | other_scopes_vars]} = state
) do
%__MODULE__{vars_info: [current_scope_vars, outer_scope_vars | other_scopes_vars]} =
state
) do
outer_scope_vars =
for {key, _} <- outer_scope_vars,
into: %{},
Expand Down
68 changes: 34 additions & 34 deletions test/elixir_sense/core/metadata_builder_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2661,14 +2661,14 @@ defmodule ElixirSense.Core.MetadataBuilderTest do
|> string_to_state

assert [
%VarInfo{name: :_par5, positions: [{3, 57}], scope_id: scope_id_1},
%VarInfo{name: :par1, positions: [{3, 20}], scope_id: scope_id_1},
%VarInfo{name: :par2, positions: [{3, 33}], scope_id: scope_id_1},
%VarInfo{name: :par3, positions: [{3, 39}], scope_id: scope_id_1},
%VarInfo{name: :par4, positions: [{3, 51}], scope_id: scope_id_1},
%VarInfo{name: :var_in1, positions: [{4, 5}], scope_id: scope_id_1},
%VarInfo{name: :var_in2, positions: [{5, 5}], scope_id: scope_id_1}
] = state |> get_line_vars(6)
%VarInfo{name: :_par5, positions: [{3, 57}], scope_id: scope_id_1},
%VarInfo{name: :par1, positions: [{3, 20}], scope_id: scope_id_1},
%VarInfo{name: :par2, positions: [{3, 33}], scope_id: scope_id_1},
%VarInfo{name: :par3, positions: [{3, 39}], scope_id: scope_id_1},
%VarInfo{name: :par4, positions: [{3, 51}], scope_id: scope_id_1},
%VarInfo{name: :var_in1, positions: [{4, 5}], scope_id: scope_id_1},
%VarInfo{name: :var_in2, positions: [{5, 5}], scope_id: scope_id_1}
] = state |> get_line_vars(6)

assert [
%VarInfo{name: :arg, positions: [{8, 14}, {8, 24}]}
Expand Down Expand Up @@ -2715,12 +2715,12 @@ defmodule ElixirSense.Core.MetadataBuilderTest do
|> string_to_state

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

assert [
%VarInfo{name: :var_in, positions: [{4, 5}]}
] = state |> get_line_vars(5)
assert [
%VarInfo{name: :var_in, positions: [{4, 5}]}
] = state |> get_line_vars(5)

assert Map.keys(state.lines_to_env[8].versioned_vars) == [
{:var_out1, nil},
Expand Down Expand Up @@ -3449,27 +3449,27 @@ defmodule ElixirSense.Core.MetadataBuilderTest do
]

assert [
%VarInfo{
name: :_my_other,
positions: [{2, 24}],
scope_id: scope_id_1
},
%VarInfo{
name: :abc,
positions: [{3, 6}],
scope_id: scope_id_1
},
%VarInfo{
name: :my_var,
positions: [{2, 13}],
scope_id: scope_id_1
},
%VarInfo{
name: :x,
positions: [{2, 43}, {3, 14}],
scope_id: scope_id_1
}
] = state |> get_line_vars(4)
%VarInfo{
name: :_my_other,
positions: [{2, 24}],
scope_id: scope_id_1
},
%VarInfo{
name: :abc,
positions: [{3, 6}],
scope_id: scope_id_1
},
%VarInfo{
name: :my_var,
positions: [{2, 13}],
scope_id: scope_id_1
},
%VarInfo{
name: :x,
positions: [{2, 43}, {3, 14}],
scope_id: scope_id_1
}
] = state |> get_line_vars(4)
end
end

Expand Down

0 comments on commit 51f3c44

Please sign in to comment.