diff --git a/lib/elixir_sense/core/metadata_builder.ex b/lib/elixir_sense/core/metadata_builder.ex index 35f1dcae..7b65dbe3 100644 --- a/lib/elixir_sense/core/metadata_builder.ex +++ b/lib/elixir_sense/core/metadata_builder.ex @@ -49,9 +49,7 @@ defmodule ElixirSense.Core.MetadataBuilder do state |> remove_attributes_scope |> remove_behaviours_scope - |> remove_alias_scope - |> remove_import_scope - |> remove_require_scope + |> remove_lexical_scope |> remove_vars_scope |> remove_namespace |> remove_protocol_implementation @@ -155,11 +153,9 @@ defmodule ElixirSense.Core.MetadataBuilder do |> add_namespace(module) |> add_current_module_to_index(position, end_position, generated: state.generated) |> alias_submodule(module) - |> new_alias_scope + |> new_lexical_scope |> new_attributes_scope |> new_behaviours_scope - |> new_import_scope - |> new_require_scope |> new_vars_scope |> maybe_add_protocol_behaviour(module) @@ -195,9 +191,7 @@ defmodule ElixirSense.Core.MetadataBuilder do |> apply_optional_callbacks |> remove_attributes_scope |> remove_behaviours_scope - |> remove_alias_scope - |> remove_import_scope - |> remove_require_scope + |> remove_lexical_scope |> remove_vars_scope |> remove_namespace |> remove_protocol_implementation @@ -307,9 +301,7 @@ defmodule ElixirSense.Core.MetadataBuilder do state |> new_named_func(name, length(params || [])) |> add_func_to_index(name, params || [], position, end_position, type, options) - |> new_alias_scope - |> new_import_scope - |> new_require_scope + |> new_lexical_scope |> new_func_vars_scope |> add_vars(vars, true) |> add_current_env_to_line(Keyword.fetch!(meta, :line)) @@ -349,9 +341,7 @@ defmodule ElixirSense.Core.MetadataBuilder do defp post_func(ast, state) do # dbg(ast) state - |> remove_alias_scope - |> remove_import_scope - |> remove_require_scope + |> remove_lexical_scope |> remove_func_vars_scope |> remove_last_scope_from_scopes |> result(ast) @@ -400,9 +390,7 @@ defmodule ElixirSense.Core.MetadataBuilder do end state - |> new_alias_scope - |> new_import_scope - |> new_require_scope + |> new_lexical_scope |> new_vars_scope |> result(ast) end @@ -418,9 +406,7 @@ defmodule ElixirSense.Core.MetadataBuilder do end state - |> remove_alias_scope - |> remove_import_scope - |> remove_require_scope + |> remove_lexical_scope |> maybe_move_vars_to_outer_scope |> remove_vars_scope |> result(ast) @@ -435,9 +421,7 @@ defmodule ElixirSense.Core.MetadataBuilder do |> merge_same_name_vars() state - |> new_alias_scope - |> new_import_scope - |> new_require_scope + |> new_lexical_scope |> new_vars_scope |> add_vars(vars, true) |> add_current_env_to_line(line) @@ -446,9 +430,7 @@ defmodule ElixirSense.Core.MetadataBuilder do defp post_clause(ast, state) do state - |> remove_alias_scope - |> remove_import_scope - |> remove_require_scope + |> remove_lexical_scope |> maybe_move_vars_to_outer_scope |> remove_vars_scope |> result(ast) diff --git a/lib/elixir_sense/core/state.ex b/lib/elixir_sense/core/state.ex index 5a23fb72..a72170d1 100644 --- a/lib/elixir_sense/core/state.ex +++ b/lib/elixir_sense/core/state.ex @@ -731,12 +731,6 @@ defmodule ElixirSense.Core.State do %{state | scopes: [[{:typespec, name, arity} | hd(state.scopes)] | state.scopes]} end - # def remove_typespec_namespace(%__MODULE__{} = state) do - # outer_scopes = state.scopes |> tl - - # %{state | scopes: outer_scopes} - # end - def register_optional_callbacks(%__MODULE__{} = state, list) do [_ | rest] = state.optional_callbacks_context %{state | optional_callbacks_context: [list | rest]} @@ -942,14 +936,6 @@ defmodule ElixirSense.Core.State do end) end - def new_alias_scope(%__MODULE__{} = state) do - %__MODULE__{state | aliases: [[] | state.aliases]} - end - - def remove_alias_scope(%__MODULE__{} = state) do - %__MODULE__{state | aliases: tl(state.aliases)} - end - def new_vars_scope(%__MODULE__{} = state) do scope_id = state.scope_id_count + 1 @@ -1153,30 +1139,26 @@ defmodule ElixirSense.Core.State do Enum.reduce(aliases_tuples, state, fn tuple, state -> add_alias(state, tuple) end) end - def new_import_scope(%__MODULE__{} = state) do + def new_lexical_scope(%__MODULE__{} = state) do %__MODULE__{ state | functions: [hd(state.functions) | state.functions], - macros: [hd(state.macros) | state.macros] + macros: [hd(state.macros) | state.macros], + requires: [[] | state.requires], + aliases: [[] | state.aliases] } end - def new_require_scope(%__MODULE__{} = state) do - %__MODULE__{state | requires: [[] | state.requires]} - end - - def remove_import_scope(%__MODULE__{} = state) do + def remove_lexical_scope(%__MODULE__{} = state) do %__MODULE__{ state | functions: tl(state.functions), - macros: tl(state.macros) + macros: tl(state.macros), + requires: tl(state.requires), + aliases: tl(state.aliases) } end - def remove_require_scope(%__MODULE__{} = state) do - %__MODULE__{state | requires: tl(state.requires)} - end - def add_import(%__MODULE__{} = state, module, opts) when is_atom(module) or is_list(module) do module = expand_alias(state, module)