Skip to content

Commit

Permalink
remove dubious missing env fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszsamson committed Dec 5, 2023
1 parent a3ddc75 commit 5d2a1e8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 32 deletions.
24 changes: 6 additions & 18 deletions lib/elixir_sense/core/parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 ->
Expand Down Expand Up @@ -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
Expand Down
13 changes: 0 additions & 13 deletions lib/elixir_sense/core/state.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/elixir_sense/core/parser_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 5d2a1e8

Please sign in to comment.