Skip to content

Commit

Permalink
πŸ’ Fix #119
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsp committed May 20, 2020
1 parent 2d2c6f1 commit 1ee7804
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = "Pluto"
uuid = "c3e4b0f8-55cb-11ea-2926-15256bba5781"
license = "MIT"
authors = ["Fons van der Plas <[email protected]>", "MikoΕ‚aj Bochenski <[email protected]>"]
version = "0.9.0"
version = "0.9.1"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Expand Down
9 changes: 3 additions & 6 deletions assets/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class PlutoConnection {
return crypto.getRandomValues(new Uint32Array(1))[0].toString(36)
}

send(messageType, body, cellID = undefined, notebookID = undefined, createPromise = false) {
send(messageType, body, cellID = undefined, createPromise = false) {
const requestID = this.getUniqueShortID()

var toSend = {
Expand All @@ -53,9 +53,6 @@ class PlutoConnection {
if (this.notebookID) {
toSend.notebookID = this.notebookID
}
if (notebookID) {
toSend.notebookID = notebookID
}
if (cellID) {
toSend.cellID = cellID
}
Expand All @@ -78,8 +75,8 @@ class PlutoConnection {
return p
}

sendreceive(messageType, body, cellID = undefined, notebookID = undefined) {
return this.send(messageType, body, cellID, notebookID, true)
sendreceive(messageType, body, cellID = undefined) {
return this.send(messageType, body, cellID, true)
}

handleMessage(event) {
Expand Down
8 changes: 4 additions & 4 deletions assets/editor.css
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,10 @@ trafficlight {

/* in ascending order of severity: */

cell.code-folded>trafficlight {
background: none;
}

@media screen and (any-pointer: fine) {
cell:hover>trafficlight {
background: rgba(0, 0, 0, .1);
Expand All @@ -571,10 +575,6 @@ trafficlight {
}
}

cell.code-folded>trafficlight {
background: none;
}

cell.output-notinsync>trafficlight,
cell.code-differs>trafficlight {
background: hsla(46, 70%, 37%, 0.68);
Expand Down
6 changes: 3 additions & 3 deletions assets/editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
<script src="assets/client.js" defer></script>
<script src="assets/filepicker.js" defer></script>

<link rel="stylesheet" href="assets/editor.css" type="text/css" />
<link rel="stylesheet" href="assets/hide-ui.css" type="text/css" media="print" />

<script src="https://cdn.jsdelivr.net/npm/@observablehq/[email protected]/dist/stdlib.js" defer></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/codemirror.min.js" defer></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/mode/julia/julia.min.js" defer></script>
Expand All @@ -31,7 +28,10 @@
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/lib/codemirror.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/addon/hint/show-hint.min.css">


<link rel="stylesheet" href="assets/editor.css" type="text/css" />
<link rel="stylesheet" href="assets/treeview.css" />
<link rel="stylesheet" href="assets/hide-ui.css" type="text/css" media="print" />
<!-- The instant feedback form at the bottom of the page uses Google Firestore to save feedback and statistics. We DO NOT use Google Analytics, and NO DATA is sent except for data entered in the feedback form and anonymous statistics. See /statistics-info for more details. -->
<script src="https://www.gstatic.com/firebasejs/7.13.1/firebase-app.js" defer></script>
<script src="https://www.gstatic.com/firebasejs/7.13.1/firebase-firestore.js" defer></script>
Expand Down
4 changes: 3 additions & 1 deletion assets/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ function updateLocalCellOutput(cellNode, msg) {
// to execute all scripts in the output html:
try {
Array.from(containerNode.querySelectorAll("script")).map((script) => {
containerNode.currentScript = script
if (script.src != "") {
if (!Array.from(document.head.querySelectorAll("script")).map(s => s.src).includes(script)) {
const tag = document.createElement("script")
Expand Down Expand Up @@ -810,6 +811,7 @@ function updateDocQuery(query = undefined) {
if (u.message.status == "πŸ‘") {
doc.querySelector("header").innerText = query
doc.querySelector("section").innerHTML = u.message.doc
MathJax.typeset([doc.querySelector("section")])
}
})
}
Expand Down Expand Up @@ -885,7 +887,7 @@ function rewrittenError(old_raw) {
}

function errorHint(e) {
const cellNode = e.target.parentElement.parentElement.parentElement.parentElement.parentElement
const cellNode = e.path.find(el => el.tagName == "CELL")
wrapInBlock(window.codeMirrors[cellNode.id], "begin")
requestChangeRemoteCell(cellNode.id)
e.preventDefault()
Expand Down
11 changes: 10 additions & 1 deletion src/react/Parse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,16 @@ function parse_custom(notebook::Notebook, cell::Cell)::Expr
ex
end
else
Meta.parse(rstrip(cell.code, ['\r', '\n', '\t', ' ']), raise=false)
# Meta.parse returns the "extra token..." like we want, but also in cases like "\n\nx = 1\n# comment", so we need to do the multiple expressions check ourselves after all
parsed1, next_ind1 = Meta.parse(cell.code, 1, raise=false)
parsed2, next_ind2 = Meta.parse(cell.code, next_ind1, raise=false)

if parsed2 === nothing
# only whitespace or comments after the first expression
parsed1
else
Expr(:error, "extra token after end of expression")
end
end

# 2.
Expand Down
27 changes: 20 additions & 7 deletions src/runner/PlutoRunner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -384,23 +384,32 @@ end
###

# We define a minimal JSON serializer here so that the notebook process does not need to depend on JSON.jl
# Performance is about 0.5-1.0x JSON.jl
# Performance is about 0.5-1.0x JSON.jl, but that's okay since it is only used for special output types like stack traces
# Not designed/tested for use outside of Pluto

struct ReplacePipe <: IO
outstream::IO
end

# to get these character codes:
# [c => UInt8(c) for c in "\"\\/\b\f\n\r\t"]
# we can do this escaping per-byte because UTF-8 is backwards compatible with ASCII, i.e. these special characters are never part of a UTF-8 encoded character other than the ASCII characters they represent. Cool!
function Base.write(rp::ReplacePipe, x::UInt8)
if x == '"' || x== '\\'
if x == 0x22 || x== 0x5c || x== 0x2f # https://www.json.org/json-en.html
write(rp.outstream, '\\')
write(rp.outstream, x)
elseif x < 0x10 # ish
write(rp.outstream, escape_string(String([Char(x)]))) # the Julia escaping 'happens' to coincide with what we want
else
write(rp.outstream, x)
end
write(rp.outstream, x)
end
function sanitize_pipe(func::Function, outstream::IO, args...)
func(ReplacePipe(outstream), args...)
end


function json(io, arr::Array)
function json(io, arr::AbstractArray)
write(io, '[')
len = length(arr)
for (i, val) in enumerate(arr)
Expand All @@ -421,11 +430,15 @@ function json(io, d::Dict{Symbol, T}) where T
write(io, '}')
end

function json(io, val::Any)
sanitize_pipe(show, io, val)
function json(io, str::T) where T<:AbstractString
write(io, '"')
sanitize_pipe(write, io, str)
write(io, '"')
end


function json(io, val::Any)
show(io, val)
end

###
# REPL THINGS
Expand Down
15 changes: 11 additions & 4 deletions test/React.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,13 @@ ENV["PLUTO_WORKSPACE_USE_DISTRIBUTED"] = "false"
ENV["PLUTO_WORKSPACE_USE_DISTRIBUTED"] = "false"

begin
escape_me = "16 \\ \" ' / \b \f \n \r \t πŸ’© \$"
notebook = Notebook([
Cell("a\\"),
Cell("1 = 2"),

Cell("b = 3.0\nb = 3"),
Cell("\n\n\nc = 4\n\n"),
Cell("\n# uhm\n\nc = 4\n\n# wowie \n\n"),
Cell("d = 5;"),
Cell("e = 6; f = 6"),
Cell("g = 7; h = 7;"),
Expand All @@ -97,8 +98,9 @@ ENV["PLUTO_WORKSPACE_USE_DISTRIBUTED"] = "false"

Cell("sqrt(-12)"),
Cell("\n\nsqrt(-13)"),
Cell("function w(x)\n\tsqrt(x)\nend"),
Cell("\"Something very exciting!\"\nfunction w(x)\n\tsqrt(x)\nend"),
Cell("w(-15)"),
Cell("error(" * sprint(Base.print_quoted, escape_me) * ")")
])
fakeclient.connected_notebook = notebook

Expand Down Expand Up @@ -142,7 +144,7 @@ ENV["PLUTO_WORKSPACE_USE_DISTRIBUTED"] = "false"
end

@testset "Stack traces" begin
@test_nowarn run_reactive!(notebook, notebook.cells[12:15])
@test_nowarn run_reactive!(notebook, notebook.cells[12:16])

@test occursin("DomainError", notebook.cells[12].error_repr)
let
Expand Down Expand Up @@ -176,7 +178,7 @@ ENV["PLUTO_WORKSPACE_USE_DISTRIBUTED"] = "false"
@test length(st["stacktrace"]) == 5

if Pluto.can_insert_filename
@test st["stacktrace"][4]["line"] == 2
@test st["stacktrace"][4]["line"] == 3
@test occursin(notebook.cells[14].uuid |> string, st["stacktrace"][4]["file"])
@test occursin(notebook.path |> basename, st["stacktrace"][4]["file"])

Expand All @@ -188,6 +190,11 @@ ENV["PLUTO_WORKSPACE_USE_DISTRIBUTED"] = "false"
end
end

let
st = Pluto.JSON.parse(notebook.cells[16].error_repr)
@test occursin(escape_me, st["msg"])
end

end
WorkspaceManager.unmake_workspace(notebook)
end
Expand Down

3 comments on commit 1ee7804

@fonsp
Copy link
Owner Author

@fonsp fonsp commented on 1ee7804 May 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fonsp
Copy link
Owner Author

@fonsp fonsp commented on 1ee7804 May 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/15075

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.9.1 -m "<description of version>" 1ee7804f394f704281c91c25d3523bbfce4e148e
git push origin v0.9.1

Please sign in to comment.