Skip to content

Commit 2add785

Browse files
committed
ensure compatibility with 1.13
1 parent 6188bb6 commit 2add785

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

apps/debug_adapter/lib/debug_adapter/utils.ex

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,16 @@ defmodule ElixirLS.DebugAdapter.Utils do
5050
defp clamp_offset_to_surrogate_boundary(_bin, offset, _max_bytes) when offset <= 0,
5151
do: 0
5252

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

5960
# If that 16-bit code_unit is a high surrogate, we've sliced in half
6061
if code_unit in 0xD800..0xDBFF do
61-
offset - 2
62+
prefix_offset
6263
else
6364
offset
6465
end

apps/language_server/lib/language_server/source_file.ex

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,15 +337,16 @@ defmodule ElixirLS.LanguageServer.SourceFile do
337337
defp clamp_offset_to_surrogate_boundary(_bin, offset, _max_bytes) when offset <= 0,
338338
do: 0
339339

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

346347
# If that 16-bit code_unit is a high surrogate, we've sliced in half
347348
if code_unit in 0xD800..0xDBFF do
348-
offset - 2
349+
prefix_offset
349350
else
350351
offset
351352
end

0 commit comments

Comments
 (0)