Skip to content

Commit b7a5fd7

Browse files
committed
Improve container_cursor_to_quoted with trailing fragment, closes #14087
1 parent 04378bd commit b7a5fd7

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

lib/elixir/lib/code/fragment.ex

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,10 +1226,7 @@ defmodule Code.Fragment do
12261226
defp maybe_missing_stab?([{:else, _} | _]), do: true
12271227
defp maybe_missing_stab?([{:catch, _} | _]), do: true
12281228
defp maybe_missing_stab?([{:rescue, _} | _]), do: true
1229-
12301229
defp maybe_missing_stab?([{:stab_op, _, :->} | _]), do: false
1231-
defp maybe_missing_stab?([{:eol, _}, next | _]) when elem(next, 0) != :",", do: false
1232-
12331230
defp maybe_missing_stab?([_ | tail]), do: maybe_missing_stab?(tail)
12341231
defp maybe_missing_stab?([]), do: false
12351232
end

lib/elixir/test/elixir/code_fragment_test.exs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1315,9 +1315,15 @@ defmodule CodeFragmentTest do
13151315
assert cc2q!("(fn x ->", trailing_fragment: ":ok end)") ==
13161316
s2q!("(fn x -> __cursor__() end)")
13171317

1318-
assert cc2q!("(fn x ->", trailing_fragment: ":ok end)") ==
1318+
assert cc2q!("(fn x ->", trailing_fragment: "\n:ok end)") ==
13191319
s2q!("(fn x -> __cursor__() end)")
13201320

1321+
assert cc2q!("(fn x when ", trailing_fragment: "-> :ok end)") ==
1322+
s2q!("(fn x when __cursor__() -> :ok end)")
1323+
1324+
assert cc2q!("(fn x when ", trailing_fragment: "->\n:ok end)") ==
1325+
s2q!("(fn x when __cursor__() -> :ok end)")
1326+
13211327
assert cc2q!("(fn") == s2q!("(__cursor__())")
13221328
assert cc2q!("(fn x") == s2q!("(__cursor__())")
13231329
assert cc2q!("(fn x,") == s2q!("(__cursor__())")
@@ -1327,6 +1333,23 @@ defmodule CodeFragmentTest do
13271333
assert cc2q!("(fn x, y -> x + y end") == s2q!("(__cursor__())")
13281334
end
13291335

1336+
test "do -> end" do
1337+
assert cc2q!("if do\nx ->\n", trailing_fragment: "y\nz ->\nw\nend") ==
1338+
s2q!("if do\nx ->\n__cursor__()\nend")
1339+
1340+
assert cc2q!("if do\nx ->\ny", trailing_fragment: "\nz ->\nw\nend") ==
1341+
s2q!("if do\nx ->\n__cursor__()\nend")
1342+
1343+
assert cc2q!("if do\nx ->\ny\n", trailing_fragment: "\nz ->\nw\nend") ==
1344+
s2q!("if do\nx ->\ny\n__cursor__()\nend")
1345+
1346+
assert cc2q!("for x <- [], reduce: %{} do\ny, ", trailing_fragment: "-> :ok\nend") ==
1347+
s2q!("for x <- [], reduce: %{} do\ny, __cursor__() -> :ok\nend")
1348+
1349+
assert cc2q!("for x <- [], reduce: %{} do\ny, z when ", trailing_fragment: "-> :ok\nend") ==
1350+
s2q!("for x <- [], reduce: %{} do\ny, z when __cursor__() -> :ok\nend")
1351+
end
1352+
13301353
test "removes tokens until opening" do
13311354
assert cc2q!("(123") == s2q!("(__cursor__())")
13321355
assert cc2q!("[foo") == s2q!("[__cursor__()]")

0 commit comments

Comments
 (0)