Skip to content

Commit 6a395a7

Browse files
authored
Fragment handle anonymous calls with extra spaces (#12847)
1 parent 11b2e3e commit 6a395a7

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

lib/elixir/lib/code/fragment.ex

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -246,20 +246,23 @@ defmodule Code.Fragment do
246246
end
247247
end
248248

249-
defp call_to_cursor_context({[?., h | t], spaces}) when h not in @non_identifier do
250-
case identifier_to_cursor_context([h | t], spaces, true) do
251-
{{:local_or_var, acc}, count} -> {{:anonymous_call, {:var, acc}}, count + 1}
252-
{{:module_attribute, _} = attr, count} -> {{:anonymous_call, attr}, count + 1}
253-
{_, _} -> {:none, 0}
254-
end
255-
end
256-
257249
defp call_to_cursor_context({reverse, spaces}) do
258-
case identifier_to_cursor_context(reverse, spaces, true) do
259-
{{:local_or_var, acc}, count} -> {{:local_call, acc}, count}
260-
{{:dot, base, acc}, count} -> {{:dot_call, base, acc}, count}
261-
{{:operator, acc}, count} -> {{:operator_call, acc}, count}
262-
{_, _} -> {:none, 0}
250+
with [?. | rest] <- reverse,
251+
{rest, spaces} = strip_spaces(rest, spaces),
252+
[h | _] when h not in @non_identifier <- rest do
253+
case identifier_to_cursor_context(rest, spaces, true) do
254+
{{:local_or_var, acc}, count} -> {{:anonymous_call, {:var, acc}}, count + 1}
255+
{{:module_attribute, _} = attr, count} -> {{:anonymous_call, attr}, count + 1}
256+
{_, _} -> {:none, 0}
257+
end
258+
else
259+
_ ->
260+
case identifier_to_cursor_context(reverse, spaces, true) do
261+
{{:local_or_var, acc}, count} -> {{:local_call, acc}, count}
262+
{{:dot, base, acc}, count} -> {{:dot_call, base, acc}, count}
263+
{{:operator, acc}, count} -> {{:operator_call, acc}, count}
264+
{_, _} -> {:none, 0}
265+
end
263266
end
264267
end
265268

lib/elixir/test/elixir/code_fragment_test.exs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,10 @@ defmodule CodeFragmentTest do
209209
assert CF.cursor_context("hello.(\n") == {:anonymous_call, {:var, ~c"hello"}}
210210
assert CF.cursor_context("hello.(\r\n") == {:anonymous_call, {:var, ~c"hello"}}
211211

212+
assert CF.cursor_context("hello . (") == {:anonymous_call, {:var, ~c"hello"}}
213+
212214
assert CF.cursor_context("@hello.(") == {:anonymous_call, {:module_attribute, ~c"hello"}}
215+
assert CF.cursor_context("@hello . (") == {:anonymous_call, {:module_attribute, ~c"hello"}}
213216
end
214217

215218
test "nested expressions" do

0 commit comments

Comments
 (0)