Skip to content

Commit

Permalink
Moved to Ast.contains_position?
Browse files Browse the repository at this point in the history
  • Loading branch information
scohen committed May 24, 2024
1 parent fe7f9aa commit 8fb9622
Showing 1 changed file with 3 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ defmodule Lexical.RemoteControl.CodeAction.Handlers.RemoveUnusedAlias do
) do
finder = fn
{:alias, _, [{:__aliases__, _, ^full_alias}]} = node ->
cursor_in_node?(document, cursor, node)
Ast.contains_position?(node, cursor)

{:alias, _,
[
{:__aliases__, _, ^full_alias},
[{{:__block__, _, [:as]}, {:__aliases__, _, [^last_segment]}}]
]} = node ->
cursor_in_node?(document, cursor, node)
Ast.contains_position?(node, cursor)

_ ->
false
Expand All @@ -145,7 +145,7 @@ defmodule Lexical.RemoteControl.CodeAction.Handlers.RemoveUnusedAlias do
finder = fn
{:alias, _, [{{:., _, _}, _, multi_alias_list}]} = node ->
Enum.find_value(multi_alias_list, &segment_matches?(&1, last_segment)) and
cursor_in_node?(document, cursor, node)
Ast.contains_position?(node, cursor)

_ ->
false
Expand All @@ -170,13 +170,6 @@ defmodule Lexical.RemoteControl.CodeAction.Handlers.RemoveUnusedAlias do
end
end

defp cursor_in_node?(%Document{} = document, %Position{} = cursor, node) do
case Ast.Range.fetch(node, document) do
{:ok, range} -> Range.contains?(range, cursor)
_ -> false
end
end

defp fetch_full_alias(%Analysis{} = analysis, %Position{} = position, last_segment) do
aliases = Analyzer.aliases_at(analysis, position)

Expand Down

0 comments on commit 8fb9622

Please sign in to comment.