Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support REPL modes #121

Merged
merged 6 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/worker.jl
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,34 @@ function worker_init(f::File)
line::Integer,
)
loc = LineNumberNode(line, Symbol(file))

# inspired by IJulia/execute_request()
# a cell beginning with "? ..." is interpreted as a help request
hcode = replace(code, r"^\s*\?" => "")
if hcode != code
code = string(
"import REPL; Core.eval(REPL, REPL.helpmode(\"",
chomp(hcode),
"\"))",
)
end

# "; ..." cells are interpreted as shell commands for run
hcode = replace(code, r"^\s*;" => "")
if hcode != code
code = string("Base.repl_cmd(`", chomp(hcode), "`, stdout)")
end

# "] ..." cells are interpreted as pkg shell commands
hcode = replace(code, r"^\]" => "")
if hcode != code
code = string(
"Pkg.REPLMode.PRINTED_REPL_WARNING[]=true; Pkg.REPLMode.do_cmd(Pkg.REPLMode.MiniREPL(),\"",
chomp(hcode),
"\")",
)
end

MichaelHatherly marked this conversation as resolved.
Show resolved Hide resolved
try
ast = _parseall(code, filename = file, lineno = line)
@assert Meta.isexpr(ast, :toplevel)
Expand Down
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
JSONSchema = "7d188eb4-7ad8-530c-ae41-71a32a6d4692"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
NodeJS_18_jll = "c1e1d063-8311-5f52-a749-c7b05e91ae37"
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
MichaelHatherly marked this conversation as resolved.
Show resolved Hide resolved
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
quarto_jll = "b7163347-bfae-5fd9-aba4-19f139889d78"
15 changes: 15 additions & 0 deletions test/examples/repl_modes.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
title: REPL modes
---

```{julia}
;echo OK
```

```{julia}
] status
```

```{julia}
?Int64
```
33 changes: 33 additions & 0 deletions test/testsets/repl_modes.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
include("../utilities/prelude.jl")

test_example(joinpath(@__DIR__, "../examples/repl_modes.qmd")) do json

cells = json["cells"]
@test length(cells) == 6

cell = cells[2]
@test cell["outputs"][1]["text"] == "OK\n"
@test cell["outputs"][1]["output_type"] == "stream"
@test cell["outputs"][1]["name"] == "stdout"

cell = cells[4]
@test cell["outputs"][1]["output_type"] == "stream"
@test cell["outputs"][1]["name"] == "stdout"
@test contains(cell["outputs"][1]["text"], "Status")
@test contains(cell["outputs"][1]["text"], "Project.toml")

cell = cells[6]
@test cell["outputs"][1]["output_type"] == "stream"
@test cell["outputs"][1]["name"] == "stdout"
@test contains(cell["outputs"][1]["text"], "search")

@test cell["outputs"][2]["output_type"] == "execute_result"
@test contains(cell["outputs"][2]["data"]["text/plain"], "64-bit signed integer type")
@test contains(
cell["outputs"][2]["data"]["text/markdown"],
"64-bit signed integer type",
)
@test contains(cell["outputs"][2]["data"]["text/html"], "64-bit signed integer type")
@test contains(cell["outputs"][2]["data"]["text/latex"], "64-bit signed integer type")

end
Loading