Fix branching section evaluation when the parent section is empty (#560)

* Fix branching section evaluation when the parent section is empty

* Update changelog
This commit is contained in:
Jonatan Kłosko 2021-09-23 13:20:49 +02:00 committed by GitHub
parent f81dbab474
commit fad9301ad4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 70 additions and 9 deletions

View file

@ -17,11 +17,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Improved intellisense to handle structs and sigils ([#513](https://github.com/livebook-dev/livebook/pull/513))
- Create new notebooks with an already focused code cell ([#527](https://github.com/livebook-dev/livebook/pull/527))
- Switched base Docker image from alpine to debian-slim ([#552](https://github.com/livebook-dev/livebook/pull/552))
### Fixed
- Improved Markdown and math integration by migrating to remark ([#495](https://github.com/livebook-dev/livebook/pull/495))
- Improved the evaluator process to not consume user-submitted messages from inbox ([#502](https://github.com/livebook-dev/livebook/pull/502))
- Improved sections panel UI to better handle numerous sections or long section names ([#534](https://github.com/livebook-dev/livebook/pull/534) and [#537](https://github.com/livebook-dev/livebook/pull/537))
- Fixed branching section evaluation when the parent section is empty ([#560](https://github.com/livebook-dev/livebook/pull/560)
## [v0.2.3](https://github.com/livebook-dev/livebook/tree/v0.2.3) (2021-08-12)

View file

@ -1000,15 +1000,7 @@ defmodule Livebook.Session do
"""
@spec find_prev_locator(Notebook.t(), Cell.t(), Section.t()) :: Runtime.locator()
def find_prev_locator(notebook, cell, section) do
default =
case section.parent_id do
nil ->
{container_ref_for_section(section), nil}
parent_id ->
{:ok, parent} = Notebook.fetch_section(notebook, parent_id)
{container_ref_for_section(parent), nil}
end
default = {container_ref_for_section(section), nil}
notebook
|> Notebook.parent_cells_with_section(cell.id)

View file

@ -1154,6 +1154,7 @@ defmodule Livebook.IntellisenseTest do
assert content =~ "## Examples"
end
@tag :erl_docs
test "returns full Erlang docs" do
{binding, env} = eval(do: nil)

View file

@ -2,6 +2,7 @@ defmodule Livebook.SessionTest do
use ExUnit.Case, async: true
alias Livebook.{Session, Delta, Runtime, Utils, Notebook, FileSystem}
alias Livebook.Notebook.{Section, Cell}
# Note: queueing evaluation in most of the tests below
# requires the runtime to synchronously start first,
@ -549,6 +550,70 @@ defmodule Livebook.SessionTest do
end
end
describe "find_prev_locator/3" do
test "given cell in main flow returns previous Elixir cell" do
cell1 = %{Cell.new(:elixir) | id: "c1"}
cell2 = %{Cell.new(:markdown) | id: "c2"}
section1 = %{Section.new() | id: "s1", cells: [cell1, cell2]}
cell3 = %{Cell.new(:elixir) | id: "c3"}
section2 = %{Section.new() | id: "s2", cells: [cell3]}
notebook = %{Notebook.new() | sections: [section1, section2]}
assert {:main_flow, "c1"} = Session.find_prev_locator(notebook, cell3, section2)
end
test "given cell in branching section returns previous Elixir cell in that section" do
section1 = %{Section.new() | id: "s1"}
cell1 = %{Cell.new(:elixir) | id: "c1"}
cell2 = %{Cell.new(:markdown) | id: "c2"}
cell3 = %{Cell.new(:elixir) | id: "c3"}
section2 = %{
Section.new()
| id: "s2",
parent_id: "s1",
cells: [cell1, cell2, cell3]
}
notebook = %{Notebook.new() | sections: [section1, section2]}
assert {"s2", "c1"} = Session.find_prev_locator(notebook, cell3, section2)
end
test "given cell in main flow returns nil if there is no previous cell" do
cell1 = %{Cell.new(:markdown) | id: "c1"}
section1 = %{Section.new() | id: "s1", cells: [cell1]}
cell2 = %{Cell.new(:elixir) | id: "c2"}
section2 = %{Section.new() | id: "s2", cells: [cell2]}
notebook = %{Notebook.new() | sections: [section1, section2]}
assert {:main_flow, nil} = Session.find_prev_locator(notebook, cell2, section2)
end
test "given cell in branching section returns nil in that section if there is no previous cell" do
cell1 = %{Cell.new(:markdown) | id: "c1"}
section1 = %{Section.new() | id: "s1", cells: [cell1]}
cell2 = %{Cell.new(:elixir) | id: "c2"}
section2 = %{
Section.new()
| id: "s2",
parent_id: "s1",
cells: [cell2]
}
notebook = %{Notebook.new() | sections: [section1, section2]}
assert {"s2", nil} = Session.find_prev_locator(notebook, cell2, section2)
end
end
defp start_session(opts \\ []) do
session_id = Utils.random_id()
{:ok, pid} = Session.start_link(Keyword.merge([id: session_id], opts))