Skip to content

Commit f3dc077

Browse files
authored
Merge pull request #12 from elixir-lang/doorgan/broken_interpolation_tokens
[fix] Fix `prefix_stream` crashing on interpolations with newlines
2 parents 9627e4f + 34b2433 commit f3dc077

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

apps/common/lib/lexical/ast/tokens.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ defmodule Lexical.Ast.Tokens do
163163
Enum.reverse(ranges)
164164
end
165165

166+
defp get_start_pos([{:eol, {start_line, start_column, _}} | _]) do
167+
{start_line, start_column}
168+
end
169+
166170
defp get_start_pos([{_, {start_line, start_column, _}, _} | _]) do
167171
{start_line, start_column}
168172
end

apps/common/test/lexical/ast/tokens_test.exs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,40 @@ defmodule Lexical.Ast.TokensTest do
4747

4848
assert Enum.to_list(tokens) == []
4949
end
50+
51+
test "works on interpolations with newlines" do
52+
text = ~S[
53+
~S"""
54+
"foo«#{
55+
2
56+
}»bar"
57+
"""
58+
|
59+
]
60+
61+
{position, document} = pop_cursor(text, as: :document)
62+
63+
tokens = Tokens.prefix_stream(document, position)
64+
65+
assert Enum.to_list(tokens) == [
66+
{:eol, '\n', []},
67+
{:eol, '\n', []},
68+
{:eol, '\n', []},
69+
{:eol, '\n', []},
70+
{
71+
:interpolated_string,
72+
[
73+
{:literal, "foo«", {{1, 1}, {1, 5}}},
74+
{:interpolation,
75+
[{:eol, {3, 18, 1}}, {:int, {4, 13, 2}, '2'}, {:eol, {4, 14, 1}}],
76+
{{3, 18}, {5, 11}}},
77+
{:literal, "»bar", {{5, 11}, {5, 15}}}
78+
],
79+
{3, 11}
80+
},
81+
{:eol, '\n', []},
82+
{:eol, '\n', []}
83+
]
84+
end
5085
end
5186
end

0 commit comments

Comments
 (0)