Skip to content

Commit

Permalink
fixup! JuliaLang#52953, follow up the refactor on REPLCompletions.jl (J…
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk authored Jan 18, 2024
1 parent 607b2b9 commit 3a63f25
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
9 changes: 5 additions & 4 deletions stdlib/REPL/src/REPLCompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1479,17 +1479,18 @@ function UndefVarError_hint(io::IO, ex::UndefVarError)
else
scope = undef
end
if scope !== Base && !_UndefVarError_warnfor(Base, var)
if scope !== Base && !_UndefVarError_warnfor(io, Base, var)
warned = false
for m in Base.loaded_modules_order
m === Core && continue
m === Base && continue
m === Main && continue
m === scope && continue
warned = _UndefVarError_warnfor(m, var) || warned
warned |= _UndefVarError_warnfor(io, m, var)
end
warned = warned || _UndefVarError_warnfor(Core, var)
warned = warned || _UndefVarError_warnfor(Main, var)
warned ||
_UndefVarError_warnfor(io, Core, var) ||
_UndefVarError_warnfor(io, Main, var)
end
nothing
end
Expand Down
21 changes: 21 additions & 0 deletions stdlib/REPL/test/repl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1675,6 +1675,27 @@ fake_repl() do stdin_write, stdout_read, repl
@test contains(txt, "Some type information was truncated. Use `show(err)` to see complete types.")
end

try # test the functionality of `UndefVarError_hint` against `Base.remove_linenums!`
@assert isempty(Base.Experimental._hint_handlers)
Base.Experimental.register_error_hint(REPL.REPLCompletions.UndefVarError_hint, UndefVarError)

# check the requirement to trigger the hint via `UndefVarError_hint`
@test !isdefined(Main, :remove_linenums!) && Base.ispublic(Base, :remove_linenums!)

fake_repl() do stdin_write, stdout_read, repl
backend = REPL.REPLBackend()
repltask = @async REPL.run_repl(repl; backend)
write(stdin_write,
"remove_linenums!\n\"ZZZZZ\"\n")
txt = readuntil(stdout_read, "ZZZZZ")
write(stdin_write, '\x04')
wait(repltask)
@test occursin("Hint: a global variable of this name also exists in Base.", txt)
end
finally
empty!(Base.Experimental._hint_handlers)
end

# Hints for tab completes

fake_repl() do stdin_write, stdout_read, repl
Expand Down

0 comments on commit 3a63f25

Please sign in to comment.