Skip to content

Commit

Permalink
ensure compatibility with 1.13
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszsamson committed Jan 30, 2025
1 parent 6188bb6 commit 2add785
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions apps/debug_adapter/lib/debug_adapter/utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,16 @@ defmodule ElixirLS.DebugAdapter.Utils do
defp clamp_offset_to_surrogate_boundary(_bin, offset, _max_bytes) when offset <= 0,
do: 0

defp clamp_offset_to_surrogate_boundary(bin, offset, _max_bytes) do
defp clamp_offset_to_surrogate_boundary(bin, offset, _max_bytes) when offset >= 2 do
# We know 0 < offset < max_bytes at this point
# Look at the 2 bytes immediately before `offset`
<<_::binary-size(offset - 2), maybe_high::binary-size(2), _::binary>> = bin
prefix_offset = offset - 2
<<_::binary-size(prefix_offset), maybe_high::binary-size(2), _::binary>> = bin
code_unit = :binary.decode_unsigned(maybe_high, :big)

# If that 16-bit code_unit is a high surrogate, we've sliced in half
if code_unit in 0xD800..0xDBFF do
offset - 2
prefix_offset
else
offset
end
Expand Down
7 changes: 4 additions & 3 deletions apps/language_server/lib/language_server/source_file.ex
Original file line number Diff line number Diff line change
Expand Up @@ -337,15 +337,16 @@ defmodule ElixirLS.LanguageServer.SourceFile do
defp clamp_offset_to_surrogate_boundary(_bin, offset, _max_bytes) when offset <= 0,
do: 0

defp clamp_offset_to_surrogate_boundary(bin, offset, _max_bytes) do
defp clamp_offset_to_surrogate_boundary(bin, offset, _max_bytes) when offset >= 2 do
# We know 0 < offset < max_bytes at this point
# Look at the 2 bytes immediately before `offset`
<<_::binary-size(offset - 2), maybe_high::binary-size(2), _::binary>> = bin
prefix_offset = offset - 2
<<_::binary-size(prefix_offset), maybe_high::binary-size(2), _::binary>> = bin
code_unit = :binary.decode_unsigned(maybe_high, :big)

# If that 16-bit code_unit is a high surrogate, we've sliced in half
if code_unit in 0xD800..0xDBFF do
offset - 2
prefix_offset
else
offset
end
Expand Down

0 comments on commit 2add785

Please sign in to comment.