Skip to content

Commit

Permalink
Handle unqualified double-parenthesis calls in get_range
Browse files Browse the repository at this point in the history
  • Loading branch information
zachallaun committed Oct 31, 2023
1 parent c79f4be commit 2ebf14e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/sourceror/range.ex
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,10 @@ defmodule Sourceror.Range do
# -> b
defp do_get_range({:->, meta, [[], right]}) do
start_pos = Keyword.take(meta, [:line, :column])
end_pos = get_range(right).end

%{start: start_pos, end: end_pos}
with %{end: end_pos} <- get_range(right) do
%{start: start_pos, end: end_pos}
end
end

# Stabs with args
Expand Down Expand Up @@ -366,6 +367,12 @@ defmodule Sourceror.Range do
get_range_for_unqualified_call(quoted)
end

# Double-parenthesis unqualified calls:
# unquote(foo)()
defp do_get_range({{call, _, _}, _, _} = quoted) when is_atom(call) do
get_range_for_unqualified_call(quoted)
end

# Catch-all
defp do_get_range(_), do: nil

Expand Down
7 changes: 7 additions & 0 deletions test/range_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,13 @@ defmodule SourcerorTest.RangeTest do
}
end

test "unqualified double calls" do
assert to_range(~S/unquote(foo)()/) == %{
start: [line: 1, column: 1],
end: [line: 1, column: 15]
}
end

test "module aliases" do
assert to_range(~S/Foo/) == %{start: [line: 1, column: 1], end: [line: 1, column: 4]}
assert to_range(~S/Foo.Bar/) == %{start: [line: 1, column: 1], end: [line: 1, column: 8]}
Expand Down

0 comments on commit 2ebf14e

Please sign in to comment.