mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-12-16 21:28:03 +08:00
Fix completion crash on higher unicode characters (#466)
* Fix completion crash on higher unicode characters * Safely rescue from intellisense errors
This commit is contained in:
parent
943d8b6059
commit
f9ec058e43
3 changed files with 19 additions and 2 deletions
|
|
@ -13,6 +13,8 @@ defmodule Livebook.Evaluator do
|
||||||
|
|
||||||
use GenServer, restart: :temporary
|
use GenServer, restart: :temporary
|
||||||
|
|
||||||
|
require Logger
|
||||||
|
|
||||||
alias Livebook.Evaluator
|
alias Livebook.Evaluator
|
||||||
|
|
||||||
@type t :: GenServer.server()
|
@type t :: GenServer.server()
|
||||||
|
|
@ -214,7 +216,15 @@ defmodule Livebook.Evaluator do
|
||||||
|
|
||||||
def handle_cast({:handle_intellisense, send_to, ref, request, evaluation_ref}, state) do
|
def handle_cast({:handle_intellisense, send_to, ref, request, evaluation_ref}, state) do
|
||||||
context = get_context(state, evaluation_ref)
|
context = get_context(state, evaluation_ref)
|
||||||
response = Livebook.Intellisense.handle_request(request, context.binding, context.env)
|
|
||||||
|
# Safely rescue from intellisense errors
|
||||||
|
response =
|
||||||
|
try do
|
||||||
|
Livebook.Intellisense.handle_request(request, context.binding, context.env)
|
||||||
|
rescue
|
||||||
|
error -> Logger.error(Exception.format(:error, error, __STACKTRACE__))
|
||||||
|
end
|
||||||
|
|
||||||
send(send_to, {:intellisense_response, ref, response})
|
send(send_to, {:intellisense_response, ref, response})
|
||||||
|
|
||||||
{:noreply, state}
|
{:noreply, state}
|
||||||
|
|
|
||||||
|
|
@ -172,6 +172,7 @@ defmodule Livebook.Intellisense do
|
||||||
|
|
||||||
defp subject_range(line, index) do
|
defp subject_range(line, index) do
|
||||||
{left, right} = String.split_at(line, index)
|
{left, right} = String.split_at(line, index)
|
||||||
|
bytes_until_index = byte_size(left)
|
||||||
|
|
||||||
left =
|
left =
|
||||||
left
|
left
|
||||||
|
|
@ -186,7 +187,7 @@ defmodule Livebook.Intellisense do
|
||||||
|> consume_until(@space ++ @operators ++ @punctuation, @closing_identifier)
|
|> consume_until(@space ++ @operators ++ @punctuation, @closing_identifier)
|
||||||
|> List.to_string()
|
|> List.to_string()
|
||||||
|
|
||||||
{index - byte_size(left), index + byte_size(right)}
|
{bytes_until_index - byte_size(left), bytes_until_index + byte_size(right)}
|
||||||
end
|
end
|
||||||
|
|
||||||
defp consume_until(acc \\ [], chars, stop, stop_include)
|
defp consume_until(acc \\ [], chars, stop, stop_include)
|
||||||
|
|
|
||||||
|
|
@ -1064,5 +1064,11 @@ defmodule Livebook.IntellisenseTest do
|
||||||
assert %{contents: [file_read]} = Intellisense.get_details(":file.read()", 8, binding, env)
|
assert %{contents: [file_read]} = Intellisense.get_details(":file.read()", 8, binding, env)
|
||||||
assert file_read =~ "Typical error reasons:"
|
assert file_read =~ "Typical error reasons:"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "properly parses unicode" do
|
||||||
|
{binding, env} = eval(do: nil)
|
||||||
|
|
||||||
|
assert nil == Intellisense.get_details("msg = '🍵'", 8, binding, env)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue