Skip to content

Commit

Permalink
minor refactors on REPLCompletions.jl
Browse files Browse the repository at this point in the history
Those I found while working on #52952.
  • Loading branch information
aviatesk committed Jan 18, 2024
1 parent 19f1c75 commit 5f3a380
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions stdlib/REPL/src/REPLCompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ function complete_any_methods(ex_org::Expr, callee_module::Module, context_modul
isa(c, TextCompletion) && return false
isa(c, MethodCompletion) || return true
sig = Base.unwrap_unionall(c.method.sig)::DataType
return !all(T -> T === Any || T === Vararg{Any}, sig.parameters[2:end])
return !all(@nospecialize(T) -> T === Any || T === Vararg{Any}, sig.parameters[2:end])
end
end

Expand Down Expand Up @@ -1439,7 +1439,7 @@ function shell_completions(string, pos)
r = pos+1:pos
paths, dir, success = complete_path("", use_envpath=false, shell_escape=true)
return paths, r, success
elseif all(arg -> arg isa AbstractString, ex.args)
elseif all(@nospecialize(arg) -> arg isa AbstractString, ex.args)
# Join these and treat this as a path
path::String = join(ex.args)
r = last_arg_start:pos
Expand Down Expand Up @@ -1518,22 +1518,28 @@ function UndefVarError_hint(io::IO, ex::UndefVarError)
else
scope = undef
end
warnfor(m, var) = Base.isbindingresolved(m, var) && (Base.isexported(m, var) || Base.ispublic(m, var)) && (print(io, "\nHint: a global variable of this name also exists in $m."); true)
if scope !== Base && !warnfor(Base, var)
if scope !== Base && !_UndefVarError_warnfor(Base, var)
warned = false
for m in Base.loaded_modules_order
m === Core && continue
m === Base && continue
m === Main && continue
m === scope && continue
warned = warnfor(m, var) || warned
warned = _UndefVarError_warnfor(m, var) || warned
end
warned = warned || warnfor(Core, var)
warned = warned || warnfor(Main, var)
warned = warned || _UndefVarError_warnfor(Core, var)
warned = warned || _UndefVarError_warnfor(Main, var)
end
nothing
end

function _UndefVarError_warnfor(io::IO, m::Module, var::Symbol)
Base.isbindingresolved(m, var) || return false
(Base.isexported(m, var) || Base.ispublic(m, var)) || return false
print(io, "\nHint: a global variable of this name also exists in $m.")
return true
end

function __init__()
Base.Experimental.register_error_hint(UndefVarError_hint, UndefVarError)
COMPLETION_WORLD[] = Base.get_world_counter()
Expand Down

0 comments on commit 5f3a380

Please sign in to comment.