diff --git a/apps/common/lib/lexical/ast/tokens.ex b/apps/common/lib/lexical/ast/tokens.ex index f7bf3026..f8c3494c 100644 --- a/apps/common/lib/lexical/ast/tokens.ex +++ b/apps/common/lib/lexical/ast/tokens.ex @@ -163,6 +163,10 @@ defmodule Lexical.Ast.Tokens do Enum.reverse(ranges) end + defp get_start_pos([{:eol, {start_line, start_column, _}} | _]) do + {start_line, start_column} + end + defp get_start_pos([{_, {start_line, start_column, _}, _} | _]) do {start_line, start_column} end diff --git a/apps/common/test/lexical/ast/tokens_test.exs b/apps/common/test/lexical/ast/tokens_test.exs index 837b8fcb..15d1d215 100644 --- a/apps/common/test/lexical/ast/tokens_test.exs +++ b/apps/common/test/lexical/ast/tokens_test.exs @@ -47,5 +47,40 @@ defmodule Lexical.Ast.TokensTest do assert Enum.to_list(tokens) == [] end + + test "works on interpolations with newlines" do + text = ~S[ + ~S""" + "foo«#{ + 2 + }»bar" + """ + | + ] + + {position, document} = pop_cursor(text, as: :document) + + tokens = Tokens.prefix_stream(document, position) + + assert Enum.to_list(tokens) == [ + {:eol, '\n', []}, + {:eol, '\n', []}, + {:eol, '\n', []}, + {:eol, '\n', []}, + { + :interpolated_string, + [ + {:literal, "foo«", {{1, 1}, {1, 5}}}, + {:interpolation, + [{:eol, {3, 18, 1}}, {:int, {4, 13, 2}, '2'}, {:eol, {4, 14, 1}}], + {{3, 18}, {5, 11}}}, + {:literal, "»bar", {{5, 11}, {5, 15}}} + ], + {3, 11} + }, + {:eol, '\n', []}, + {:eol, '\n', []} + ] + end end end