Skip to content

Commit

Permalink
Add macrocall cell_id to LineNumberNodes inside expanded expr (#2241)
Browse files Browse the repository at this point in the history
* Add function to update disabled_cells_dependency

* update disabled/skipped dependency inside load_notebook

* add a test

* append macrocall cell_id inside macro expr

* Revert "Add function to update disabled_cells_dependency"

This reverts commit f659cf9.

* Revert "update disabled/skipped dependency inside load_notebook"

This reverts commit 897604e.

* Revert "add a test"

This reverts commit 5b59062.

* Correctly handle jump to link in stacktraces

* move LineNumberNode processing to replace_pluto_properties_in_expr

* add tests for methods deletion from macros
  • Loading branch information
disberd authored Aug 17, 2022
1 parent 2158cab commit 72555ed
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"
Memoize = "c03570c3-d221-55d1-a50c-7939bbd78826"

[targets]
test = ["DataFrames", "OffsetArrays", "Random", "Sockets", "Test", "TimerOutputs"]
test = ["DataFrames", "OffsetArrays", "Random", "Sockets", "Test", "TimerOutputs", "Memoize"]
2 changes: 1 addition & 1 deletion frontend/components/ErrorMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { html, useContext, useState } from "../imports/Preact.js"
const StackFrameFilename = ({ frame, cell_id }) => {
const sep_index = frame.file.indexOf("#==#")
if (sep_index != -1) {
const frame_cell_id = frame.file.substr(sep_index + 4)
const frame_cell_id = frame.file.substr(sep_index + 4, 36)
const a = html`<a
href="#"
onclick=${(e) => {
Expand Down
12 changes: 11 additions & 1 deletion src/runner/PlutoRunner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,17 @@ else
m
end
replace_pluto_properties_in_expr(other; kwargs...) = other
function replace_pluto_properties_in_expr(ln::LineNumberNode; cell_id, kwargs...) # See https://github.com/fonsp/Pluto.jl/pull/2241
file = string(ln.file)
out = if endswith(file, string(cell_id))
# We already have the correct cell_id in this LineNumberNode
ln
else
# We append to the LineNumberNode file #@#==# + cell_id
LineNumberNode(ln.line, Symbol(file * "#@#==#$(cell_id)"))
end
return out
end

"Similar to [`replace_pluto_properties_in_expr`](@ref), but just checks for existance and doesn't check for [`GiveMeCellID`](@ref)"
has_hook_style_pluto_properties_in_expr(::GiveMeRerunCellFunction) = true
Expand Down Expand Up @@ -253,7 +264,6 @@ module CantReturnInPluto
replace_returns_with_error_in_interpolation(ex) = ex
end


function try_macroexpand(mod, cell_uuid, expr)
# Remove the precvious cached expansion, so when we error somewhere before we update,
# the old one won't linger around and get run accidentally.
Expand Down
48 changes: 48 additions & 0 deletions test/MacroAnalysis.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Test
import UUIDs
import Pluto: PlutoRunner, Notebook, WorkspaceManager, Cell, ServerSession, ClientSession, update_run!
import Memoize: @memoize

@testset "Macro analysis" begin
🍭 = ServerSession()
Expand Down Expand Up @@ -872,4 +873,51 @@ import Pluto: PlutoRunner, Notebook, WorkspaceManager, Cell, ServerSession, Clie
@test !occursin("An empty conjugate", bool.output.body)
@test occursin("complex conjugate", bool.output.body)
end

@testset "Delete methods from macros" begin
🍭 = ServerSession()
🍭.options.evaluation.workspace_use_distributed = false

fakeclient = ClientSession(:fake, nothing)
🍭.connected_clients[fakeclient.id] = fakeclient

notebook = Notebook([
Cell("using Memoize"),
Cell("""
macro user_defined()
quote
struct ASD end
custom_func(::ASD) = "ASD"
end |> esc
end
"""),
Cell("@user_defined"),
Cell("methods(custom_func)"),
Cell("""
@memoize function memoized_func(a)
println("Running")
2a
end
"""),
Cell("methods(memoized_func)"),
])
cell(idx) = notebook.cells[idx]

update_run!(🍭, notebook, notebook.cells)

@test :custom_func ∈ notebook.topology.nodes[cell(3)].funcdefs_without_signatures
@test cell(4) |> noerror
@test :memoized_func ∈ notebook.topology.nodes[cell(5)].funcdefs_without_signatures
@test cell(6) |> noerror

cell(3).code = "#=$(cell(3).code)=#"
cell(5).code = "#=$(cell(5).code)=#"

update_run!(🍭, notebook, notebook.cells)

@test :custom_func βˆ‰ notebook.topology.nodes[cell(3)].funcdefs_without_signatures
@test occursinerror("UndefVarError: custom_func", cell(4))
@test :memoized_func βˆ‰ notebook.topology.nodes[cell(5)].funcdefs_without_signatures
@test occursinerror("UndefVarError: memoized_func", cell(6))
end
end

0 comments on commit 72555ed

Please sign in to comment.