Skip to content

Commit

Permalink
add support for 1.17 tokenizer
Browse files Browse the repository at this point in the history
fix tests on 1.17
  • Loading branch information
lukaszsamson committed May 26, 2024
1 parent 5f2defd commit a41777a
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/elixir_sense/core/metadata_builder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1813,7 +1813,7 @@ defmodule ElixirSense.Core.MetadataBuilder do
end

# stepped range struct
def get_binding_type(_state, {:"..//", _, [_, _, _]}) do
def get_binding_type(_state, {:..//, _, [_, _, _]}) do
{:struct, [], {:atom, Range}}
end

Expand Down
6 changes: 3 additions & 3 deletions lib/elixir_sense/core/normalized/code/fragment.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ defmodule ElixirSense.Core.Normalized.Code.Fragment do
end
rescue
e ->
if Version.match?(System.version(), ">= 1.16.0-dev") do
if Version.match?(System.version(), ">= 1.17.0-dev") do
Logger.error(
"Code.Fragment.cursor_context raised #{Exception.format(:error, e, __STACKTRACE__)}. Please report that to elixir project."
)
Expand All @@ -44,7 +44,7 @@ defmodule ElixirSense.Core.Normalized.Code.Fragment do
end
rescue
e ->
if Version.match?(System.version(), ">= 1.16.0-dev") do
if Version.match?(System.version(), ">= 1.17.0-dev") do
Logger.error(
"Code.Fragment.surround_context raised #{Exception.format(:error, e, __STACKTRACE__)}. Please report that to elixir project."
)
Expand All @@ -71,7 +71,7 @@ defmodule ElixirSense.Core.Normalized.Code.Fragment do
end
rescue
e ->
if Version.match?(System.version(), ">= 1.16.0-dev") do
if Version.match?(System.version(), ">= 1.17.0-dev") do
try do
Logger.error(
"Code.Fragment.container_cursor_to_quoted raised #{Exception.format(:error, e, __STACKTRACE__)}. Please report that to elixir project."
Expand Down
7 changes: 6 additions & 1 deletion lib/elixir_sense/core/normalized/tokenizer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,20 @@ defmodule ElixirSense.Core.Normalized.Tokenizer do
end

case result do
# < 1.17
{:ok, _line, _column, _warning, tokens} ->
Enum.reverse(tokens)

# >= 1.17
{:ok, _line, _column, _warning, tokens, _terminators} ->
tokens

{:error, _, _, _, sofar} ->
sofar
end
rescue
e ->
if Version.match?(System.version(), ">= 1.16.0-dev") do
if Version.match?(System.version(), ">= 1.17.0-dev") do
Logger.error(
":elixir_tokenizer.tokenize raised #{Exception.format(:error, e, __STACKTRACE__)}. Please report that to elixir project."
)
Expand Down
6 changes: 3 additions & 3 deletions lib/elixir_sense/core/normalized/typespec.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ defmodule ElixirSense.Core.Normalized.Typespec do
# workaround for crash
# Keyword.fetch({:error, :beam_lib, {:not_a_beam_file, ""}}, :module)
# fixed in elixir 1.16.0
if Version.match?(System.version(), ">= 1.16.0-dev") do
if Version.match?(System.version(), ">= 1.17.0-dev") do
Logger.error(
"Code.Typespec.fetch_specs raised #{Exception.format(:error, e, __STACKTRACE__)}. Please report that to elixir project."
)
Expand All @@ -33,7 +33,7 @@ defmodule ElixirSense.Core.Normalized.Typespec do
# workaround for crash
# Keyword.fetch({:error, :beam_lib, {:not_a_beam_file, ""}}, :module)
# fixed in elixir 1.16.0
if Version.match?(System.version(), ">= 1.16.0-dev") do
if Version.match?(System.version(), ">= 1.17.0-dev") do
Logger.error(
"Code.Typespec.fetch_types raised #{Exception.format(:error, e, __STACKTRACE__)}. Please report that to elixir project."
)
Expand All @@ -53,7 +53,7 @@ defmodule ElixirSense.Core.Normalized.Typespec do
# workaround for crash
# Keyword.fetch({:error, :beam_lib, {:not_a_beam_file, ""}}, :module)
# fixed in elixir 1.16.0
if Version.match?(System.version(), ">= 1.16.0-dev") do
if Version.match?(System.version(), ">= 1.17.0-dev") do
Logger.error(
"Code.Typespec.fetch_callbacks raised #{Exception.format(:error, e, __STACKTRACE__)}. Please report that to elixir project."
)
Expand Down
2 changes: 1 addition & 1 deletion lib/elixir_sense/core/type_info.ex
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ defmodule ElixirSense.Core.TypeInfo do
|> to_string()
rescue
e ->
if Version.match?(System.version(), ">= 1.16.0-dev") do
if Version.match?(System.version(), ">= 1.17.0-dev") do
Logger.error(
"Macro.to_string(#{inspect(sanitized)}) returned invalid code. Please report that to elixir project."
)
Expand Down
21 changes: 15 additions & 6 deletions test/elixir_sense/core/source_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,21 @@ defmodule ElixirSense.Core.SourceTest do
end

test "inside fn body" do
assert %{
candidate: {Enum, :map},
elixir_prefix: false,
npar: 1,
pos: {{1, 11}, {1, nil}}
} = which_func("var = Enum.map([1,2], fn(i) -> i*")
if Version.match?(System.version(), ">= 1.17.0-rc.0") do
assert %{
candidate: {nil, :*},
elixir_prefix: false,
npar: 1,
pos: {{1, 33}, {1, nil}}
} = which_func("var = Enum.map([1,2], fn(i) -> i*")
else
assert %{
candidate: {Enum, :map},
elixir_prefix: false,
npar: 1,
pos: {{1, 11}, {1, nil}}
} = which_func("var = Enum.map([1,2], fn(i) -> i*")
end
end

test "inside a list" do
Expand Down

0 comments on commit a41777a

Please sign in to comment.