diff --git a/lib/elixir_sense/core/parser.ex b/lib/elixir_sense/core/parser.ex index 7926b44c..e390d485 100644 --- a/lib/elixir_sense/core/parser.ex +++ b/lib/elixir_sense/core/parser.ex @@ -7,7 +7,6 @@ defmodule ElixirSense.Core.Parser do alias ElixirSense.Core.MetadataBuilder alias ElixirSense.Core.Normalized.Tokenizer alias ElixirSense.Core.Source - alias ElixirSense.Core.State alias ElixirSense.Core.Normalized.Code, as: NormalizedCode require Logger @@ -54,16 +53,13 @@ defmodule ElixirSense.Core.Parser do !try_to_fix_line_not_found do create_metadata(source, {:ok, acc, error}) else - result = - case try_fix_line_not_found_by_inserting_marker(modified_source, cursor_position) do - {:ok, acc} -> - acc + case try_fix_line_not_found_by_inserting_marker(modified_source, cursor_position) do + {:ok, acc} -> + create_metadata(source, {:ok, acc, error || {:error, :env_not_found}}) - _ -> - fix_line_not_found_by_taking_previous_line(acc, elem(cursor_position, 0)) - end - - create_metadata(source, {:ok, result, error || {:error, :env_not_found}}) + _ -> + create_metadata(source, {:ok, acc, error || {:error, :env_not_found}}) + end end {:error, _reason} = error -> @@ -143,14 +139,6 @@ defmodule ElixirSense.Core.Parser do end end - defp fix_line_not_found_by_taking_previous_line(acc, cursor_line_number) - when is_integer(cursor_line_number) do - previous_env_or_default = State.get_closest_previous_env(acc, cursor_line_number) - - fixed_lines_to_env = acc.lines_to_env |> Map.put(cursor_line_number, previous_env_or_default) - %State{acc | lines_to_env: fixed_lines_to_env} - end - defp try_fix_line_not_found_by_inserting_marker( modified_source, {cursor_line_number, _} = cursor_position diff --git a/lib/elixir_sense/core/state.ex b/lib/elixir_sense/core/state.ex index 8cd94788..debef88c 100644 --- a/lib/elixir_sense/core/state.ex +++ b/lib/elixir_sense/core/state.ex @@ -1359,19 +1359,6 @@ defmodule ElixirSense.Core.State do defp merge_type(old, old), do: old defp merge_type(old, new), do: {:intersection, [old, new]} - def get_closest_previous_env(%__MODULE__{} = metadata, line) do - metadata.lines_to_env - |> Enum.max_by( - fn - {env_line, _} when env_line < line -> env_line - _ -> 0 - end, - &>=/2, - fn -> {0, default_env()} end - ) - |> elem(1) - end - def default_env, do: %ElixirSense.Core.State.Env{} def expand_alias(%__MODULE__{} = _state, module) when is_atom(module) do diff --git a/test/elixir_sense/core/parser_test.exs b/test/elixir_sense/core/parser_test.exs index cdbae99b..0881d339 100644 --- a/test/elixir_sense/core/parser_test.exs +++ b/test/elixir_sense/core/parser_test.exs @@ -339,7 +339,7 @@ defmodule ElixirSense.Core.ParserTest do end """ - %Metadata{error: {:error, :parse_error}, lines_to_env: %{5 => _}} = + %Metadata{error: {:error, :parse_error}, lines_to_env: %{6 => _}} = parse_string(source, true, true, {5, 12}) end