Skip to content

Commit

Permalink
feat: accept column and line options
Browse files Browse the repository at this point in the history
  • Loading branch information
mhanberg committed Feb 11, 2024
1 parent 47de42c commit 12a1827
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/spitfire.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1792,7 +1792,8 @@ defmodule Spitfire do
case code
|> String.to_charlist()
|> :elixir_tokenizer.tokenize(
1,
opts[:line] || 1,
opts[:column] || 1,
opts |> Keyword.put(:check_terminators, false) |> Keyword.put(:cursor_completion, false)
) do
{:ok, _, _, _, tokens} ->
Expand Down
10 changes: 9 additions & 1 deletion test/spitfire_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1815,6 +1815,12 @@ defmodule SpitfireTest do
assert Spitfire.parse(code) == s2q(code)
end
end

test "line and column opt" do
code = "foo"

assert Spitfire.parse(code, line: 12, column: 7) == s2q(code, line: 12, column: 7)
end
end

describe "code with errors" do
Expand Down Expand Up @@ -2317,7 +2323,9 @@ defmodule SpitfireTest do
end
end

defp s2q(code), do: Code.string_to_quoted(code, columns: true, token_metadata: true, emit_warnings: false)
defp s2q(code, opts \\ []) do
Code.string_to_quoted(code, Keyword.merge([columns: true, token_metadata: true, emit_warnings: false], opts))
end

def print(ast) do
ast |> Macro.to_string() |> IO.puts()
Expand Down

0 comments on commit 12a1827

Please sign in to comment.