|
1 | 1 | Base.Experimental.@optlevel 1 |
2 | 2 |
|
3 | | -using FileWatching, REPL, UUIDs |
| 3 | +using FileWatching, UUIDs |
4 | 4 | using LibGit2: LibGit2 |
5 | 5 | using Base: PkgId |
6 | 6 | using Base.Meta: isexpr |
@@ -42,6 +42,13 @@ function is_master_worker end |
42 | 42 |
|
43 | 43 | ## END abstract Distributed API |
44 | 44 |
|
| 45 | +# These functions will be set/defined by the REPL extension if it's loaded |
| 46 | +maybe_set_prompt_color::Function = Returns(nothing) |
| 47 | +add_definitions_from_repl::Function = Returns(nothing) |
| 48 | +# Unlike the above variables we declare this function in Revise for convenience |
| 49 | +# because it's used in the tests. |
| 50 | +function revise_first end |
| 51 | + |
45 | 52 | """ |
46 | 53 | Revise.active[] |
47 | 54 |
|
@@ -873,7 +880,6 @@ function revise(; throw::Bool=false) |
873 | 880 |
|
874 | 881 | nothing |
875 | 882 | end |
876 | | -revise(::REPL.REPLBackend) = revise() |
877 | 883 |
|
878 | 884 | """ |
879 | 885 | revise(mod::Module; force::Bool=true) |
@@ -1150,7 +1156,11 @@ function get_def(method::Method; modified_files=revision_queue) |
1150 | 1156 | filename = fixpath(String(method.file)) |
1151 | 1157 | if startswith(filename, "REPL[") |
1152 | 1158 | isdefined(Base, :active_repl) || return false |
1153 | | - fi = add_definitions_from_repl(filename) |
| 1159 | + fi = add_definitions_from_repl(filename)::Union{Nothing, FileInfo} |
| 1160 | + if isnothing(fi) |
| 1161 | + return false |
| 1162 | + end |
| 1163 | + |
1154 | 1164 | hassig = false |
1155 | 1165 | for (_, exs) in fi.modexsigs |
1156 | 1166 | for siginfos in values(exs) |
@@ -1224,21 +1234,6 @@ function get_expressions(id::PkgId, filename) |
1224 | 1234 | return fi.modexsigs |
1225 | 1235 | end |
1226 | 1236 |
|
1227 | | -function add_definitions_from_repl(filename::String) |
1228 | | - hist_idx = parse(Int, filename[6:end-1]) |
1229 | | - hp = (Base.active_repl::REPL.LineEditREPL).interface.modes[1].hist::REPL.REPLHistoryProvider |
1230 | | - src = hp.history[hp.start_idx+hist_idx] |
1231 | | - id = PkgId(nothing, "@REPL") |
1232 | | - pkgdata = pkgdatas[id] |
1233 | | - mod_exs_sigs = ModuleExprsSigs(Main::Module) |
1234 | | - parse_source!(mod_exs_sigs, src, filename, Main::Module) |
1235 | | - instantiate_sigs!(mod_exs_sigs) |
1236 | | - fi = FileInfo(mod_exs_sigs) |
1237 | | - push!(pkgdata, filename=>fi) |
1238 | | - return fi |
1239 | | -end |
1240 | | -add_definitions_from_repl(filename::AbstractString) = add_definitions_from_repl(convert(String, filename)::String) |
1241 | | - |
1242 | 1237 | function update_stacktrace_lineno!(trace) |
1243 | 1238 | local nrep |
1244 | 1239 | for i = 1:length(trace) |
@@ -1289,60 +1284,6 @@ function method_location(method::Method) |
1289 | 1284 | return method.file, method.line |
1290 | 1285 | end |
1291 | 1286 |
|
1292 | | -# Set the prompt color to indicate the presence of unhandled revision errors |
1293 | | -const original_repl_prefix = Ref{Union{String,Function,Nothing}}(nothing) |
1294 | | -function maybe_set_prompt_color(color) |
1295 | | - if isdefined(Base, :active_repl) |
1296 | | - repl = Base.active_repl |
1297 | | - if isa(repl, REPL.LineEditREPL) |
1298 | | - if color === :warn |
1299 | | - # First save the original setting |
1300 | | - if original_repl_prefix[] === nothing |
1301 | | - original_repl_prefix[] = repl.mistate.current_mode.prompt_prefix |
1302 | | - end |
1303 | | - repl.mistate.current_mode.prompt_prefix = "\e[33m" # yellow |
1304 | | - else |
1305 | | - color = original_repl_prefix[] |
1306 | | - color === nothing && return nothing |
1307 | | - repl.mistate.current_mode.prompt_prefix = color |
1308 | | - original_repl_prefix[] = nothing |
1309 | | - end |
1310 | | - end |
1311 | | - end |
1312 | | - return nothing |
1313 | | -end |
1314 | | - |
1315 | | -# `revise_first` gets called by the REPL prior to executing the next command (by having been pushed |
1316 | | -# onto the `ast_transform` list). |
1317 | | -# This uses invokelatest not for reasons of world age but to ensure that the call is made at runtime. |
1318 | | -# This allows `revise_first` to be compiled without compiling `revise` itself, and greatly |
1319 | | -# reduces the overhead of using Revise. |
1320 | | -function revise_first(ex) |
1321 | | - # Special-case `exit()` (issue #562) |
1322 | | - if isa(ex, Expr) |
1323 | | - exu = unwrap(ex) |
1324 | | - if isexpr(exu, :block, 2) |
1325 | | - arg1 = exu.args[1] |
1326 | | - if isexpr(arg1, :softscope) |
1327 | | - exu = exu.args[2] |
1328 | | - end |
1329 | | - end |
1330 | | - if isa(exu, Expr) |
1331 | | - exu.head === :call && length(exu.args) == 1 && exu.args[1] === :exit && return ex |
1332 | | - lhsrhs = LoweredCodeUtils.get_lhs_rhs(exu) |
1333 | | - if lhsrhs !== nothing |
1334 | | - lhs, _ = lhsrhs |
1335 | | - if isexpr(lhs, :ref) && length(lhs.args) == 1 |
1336 | | - arg1 = lhs.args[1] |
1337 | | - isexpr(arg1, :(.), 2) && arg1.args[1] === :Revise && is_quotenode_egal(arg1.args[2], :active) && return ex |
1338 | | - end |
1339 | | - end |
1340 | | - end |
1341 | | - end |
1342 | | - # Check for queued revisions, and if so call `revise` first before executing the expression |
1343 | | - return Expr(:toplevel, :($isempty($revision_queue) || $(Base.invokelatest)($revise)), ex) |
1344 | | -end |
1345 | | - |
1346 | 1287 | steal_repl_backend(_...) = @warn """ |
1347 | 1288 | `steal_repl_backend` has been removed from Revise, please update your `~/.julia/config/startup.jl`. |
1348 | 1289 | See https://timholy.github.io/Revise.jl/stable/config/ |
@@ -1375,7 +1316,7 @@ end |
1375 | 1316 |
|
1376 | 1317 | init_worker(p::Int) = init_worker(DistributedWorker(p)) |
1377 | 1318 |
|
1378 | | -active_repl_backend_available() = isdefined(Base, :active_repl_backend) && Base.active_repl_backend !== nothing |
| 1319 | +should_enable_revise() = get(ENV, "JULIA_REVISE", "auto") == "auto" |
1379 | 1320 |
|
1380 | 1321 | function __init__() |
1381 | 1322 | ccall(:jl_generating_output, Cint, ()) == 1 && return nothing |
@@ -1452,35 +1393,13 @@ function __init__() |
1452 | 1393 | push!(Base.include_callbacks, watch_includes) |
1453 | 1394 | push!(Base.package_callbacks, watch_package_callback) |
1454 | 1395 |
|
1455 | | - mode = get(ENV, "JULIA_REVISE", "auto") |
1456 | | - if mode == "auto" |
1457 | | - pushfirst!(REPL.repl_ast_transforms, revise_first) |
1458 | | - # #664: once a REPL is started, it no longer interacts with REPL.repl_ast_transforms |
1459 | | - if active_repl_backend_available() |
1460 | | - push!(Base.active_repl_backend.ast_transforms, revise_first) |
1461 | | - else |
1462 | | - # wait for active_repl_backend to exist |
1463 | | - # #719: do this async in case Revise is being loaded from startup.jl |
1464 | | - t = @async begin |
1465 | | - iter = 0 |
1466 | | - while !active_repl_backend_available() && iter < 20 |
1467 | | - sleep(0.05) |
1468 | | - iter += 1 |
1469 | | - end |
1470 | | - if active_repl_backend_available() |
1471 | | - push!(Base.active_repl_backend.ast_transforms, revise_first) |
1472 | | - end |
1473 | | - end |
1474 | | - isdefined(Base, :errormonitor) && Base.errormonitor(t) |
1475 | | - end |
1476 | | - |
1477 | | - if isdefined(Main, :Atom) |
1478 | | - Atom = getfield(Main, :Atom) |
1479 | | - if Atom isa Module && isdefined(Atom, :handlers) |
1480 | | - setup_atom(Atom) |
1481 | | - end |
| 1396 | + if should_enable_revise() && isdefined(Main, :Atom) |
| 1397 | + Atom = getfield(Main, :Atom) |
| 1398 | + if Atom isa Module && isdefined(Atom, :handlers) |
| 1399 | + setup_atom(Atom) |
1482 | 1400 | end |
1483 | 1401 | end |
| 1402 | + |
1484 | 1403 | return nothing |
1485 | 1404 | end |
1486 | 1405 |
|
|
0 commit comments