Skip to content
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
6 changes: 6 additions & 0 deletions stdlib/REPL/src/REPLCompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ function get_value(sym::Expr, fn)
end
get_value(sym::Symbol, fn) = isdefined(fn, sym) ? (getfield(fn, sym), true) : (nothing, false)
get_value(sym::QuoteNode, fn) = isdefined(fn, sym.value) ? (getfield(fn, sym.value), true) : (nothing, false)
get_value(sym::GlobalRef, fn) = get_value(sym.name, sym.mod)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this method because Core.@cmd macro will be lowered with GlobalRef, but this one looks a bit weird since it totally ignores the context fn.
Maybe special-casing it inside isexpr(sym, :macrocall) block within get_type looks better ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like the correct thing to do to me. Of course, we would expect all GlobalRefs emitted by the parser to actually exist, but I don't think being more defensive here hurts.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, then I will leave this as is.

get_value(sym, fn) = (sym, true)

# Return the value of a getfield call expression
Expand Down Expand Up @@ -456,6 +457,11 @@ function get_type(sym::Expr, fn::Module)
# try to analyze nests of calls. if this fails, try using the expanded form.
val, found = try_get_type(sym, fn)
found && return val, found
# https://github.com/JuliaLang/julia/issues/27184
if isexpr(sym, :macrocall)
_, found = get_type(first(sym.args), fn)
found || return Any, false
end
return try_get_type(Meta.lower(fn, sym), fn)
end

Expand Down
7 changes: 7 additions & 0 deletions stdlib/REPL/test/replcompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1109,3 +1109,10 @@ let s = "test_dict[\"ab"
c, r = test_complete_context(s)
@test c == Any["\"abc\"", "\"abcd\""]
end

# https://github.com/JuliaLang/julia/issues/27184
let
(test_complete("@noexist."); @test true)
(test_complete("Main.@noexist."); @test true)
(test_complete("@Main.noexist."); @test true)
end