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 all 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
10 changes: 10 additions & 0 deletions src/worker.jl
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,16 @@ function worker_init(f::File)
line::Integer,
)
loc = LineNumberNode(line, Symbol(file))

# handle REPL modes
if code[1] == '?'
code = "Core.eval(Main.REPL, Main.REPL.helpmode(\"$(code[2:end])\"))"
elseif code[1] == ';'
code = "Base.repl_cmd(`$(code[2:end])`, stdout)"
elseif code[1] == ']'
code = "Pkg.REPLMode.PRINTED_REPL_WARNING[]=true; Pkg.REPLMode.do_cmd(Pkg.REPLMode.MiniREPL(),\"$(code[2:end])\")"
end

try
ast = _parseall(code, filename = file, lineno = line)
@assert Meta.isexpr(ast, :toplevel)
Expand Down
19 changes: 19 additions & 0 deletions test/examples/repl_modes.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
title: REPL modes
---

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

```{julia}
;cmd /c echo OK
```

```{julia}
] status
```

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

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

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

if !Sys.iswindows()
cell = cells[2]
@test cell["outputs"][1]["text"] == "OK\n"
@test cell["outputs"][1]["output_type"] == "stream"
@test cell["outputs"][1]["name"] == "stdout"
else
# https://github.com/JuliaLang/julia/issues/23597
cell = cells[4]
@test contains(cell["outputs"][1]["text"], "OK")
end

cell = cells[6]
@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[8]
@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