Skip to content

Commit

Permalink
made Ast.contains_position? inclusive, like range, and switched to it
Browse files Browse the repository at this point in the history
  • Loading branch information
scohen committed May 30, 2024
1 parent 9d47ae7 commit e11b299
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 14 deletions.
4 changes: 2 additions & 2 deletions apps/common/lib/lexical/ast.ex
Original file line number Diff line number Diff line change
Expand Up @@ -321,13 +321,13 @@ defmodule Lexical.Ast do

cond do
on_same_line? ->
position.character >= start_pos[:column] and position.character < end_pos[:column]
position.character >= start_pos[:column] and position.character <= end_pos[:column]

position.line == start_pos[:line] ->
position.character >= start_pos[:column]

position.line == end_pos[:line] ->
position.character < end_pos[:column]
position.character <= end_pos[:column]

true ->
position.line > start_pos[:line] and position.line < end_pos[:line]
Expand Down
4 changes: 2 additions & 2 deletions apps/common/test/lexical/ast_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ defmodule Lexical.AstTest do
setup do
{range, code} = pop_range(~q|
[
«single_line_call(1, 2, 3»)
«single_line_call(1, 2, 3
]
|)

Expand Down Expand Up @@ -247,7 +247,7 @@ defmodule Lexical.AstTest do
[
«multi_line_call(
1, 2, 3
»)
]
|)

Expand Down
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 e11b299

Please sign in to comment.