From 51f3c44393c88427de5cff6f0f21d9cccb8b27a3 Mon Sep 17 00:00:00 2001 From: Lukasz Samson Date: Thu, 29 Aug 2024 23:24:04 +0200 Subject: [PATCH] format --- lib/elixir_sense/core/compiler.ex | 17 ++--- lib/elixir_sense/core/metadata_builder.ex | 2 +- lib/elixir_sense/core/state.ex | 12 +++- .../core/metadata_builder_test.exs | 68 +++++++++---------- 4 files changed, 53 insertions(+), 46 deletions(-) diff --git a/lib/elixir_sense/core/compiler.ex b/lib/elixir_sense/core/compiler.ex index e882b487..c80b591d 100644 --- a/lib/elixir_sense/core/compiler.ex +++ b/lib/elixir_sense/core/compiler.ex @@ -1522,11 +1522,12 @@ 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} @@ -1534,7 +1535,8 @@ defmodule ElixirSense.Core.Compiler do # 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 @@ -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 diff --git a/lib/elixir_sense/core/metadata_builder.ex b/lib/elixir_sense/core/metadata_builder.ex index b8d94ee4..694614f4 100644 --- a/lib/elixir_sense/core/metadata_builder.ex +++ b/lib/elixir_sense/core/metadata_builder.ex @@ -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 diff --git a/lib/elixir_sense/core/state.ex b/lib/elixir_sense/core/state.ex index a593d33a..3a81b8c5 100644 --- a/lib/elixir_sense/core/state.ex +++ b/lib/elixir_sense/core/state.ex @@ -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), @@ -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: %{}, diff --git a/test/elixir_sense/core/metadata_builder_test.exs b/test/elixir_sense/core/metadata_builder_test.exs index da8b97ab..4a0b3221 100644 --- a/test/elixir_sense/core/metadata_builder_test.exs +++ b/test/elixir_sense/core/metadata_builder_test.exs @@ -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}]} @@ -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}, @@ -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