Skip to content

Commit

Permalink
[REPLCompletions] allow symbol completions within incomplete macrocal…
Browse files Browse the repository at this point in the history
…l expression (#51834)

fix #51827

---------

Co-authored-by: Kristoffer Carlsson <kcarlsson89@gmail.com>
(cherry picked from commit 3b1ba62)
  • Loading branch information
aviatesk authored and KristofferC committed Nov 27, 2023
1 parent 5c9602e commit 4aeef21
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
5 changes: 5 additions & 0 deletions stdlib/REPL/src/REPLCompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,11 @@ function complete_identifiers!(suggestions::Vector{Completion}, @nospecialize(ff
if isinfix
ex = ex.args[end]
end
elseif isexpr(ex, :macrocall) && length(ex.args) > 1
# allow symbol completions within potentially incomplete macrocalls
if s[end] '`' && s[end] ')'
ex = ex.args[end]
end
end
end
append!(suggestions, complete_symbol(ex, name, ffunc, context_module))
Expand Down
24 changes: 18 additions & 6 deletions stdlib/REPL/test/replcompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ end
test_complete(s) = map_completion_text(@inferred(completions(s, lastindex(s))))
test_scomplete(s) = map_completion_text(@inferred(shell_completions(s, lastindex(s))))
test_bslashcomplete(s) = map_completion_text(@inferred(bslash_completions(s, lastindex(s)))[2])
test_complete_context(s, m) = map_completion_text(@inferred(completions(s,lastindex(s), m)))
test_complete_context(s, m=@__MODULE__) = map_completion_text(@inferred(completions(s,lastindex(s), m)))
test_complete_foo(s) = test_complete_context(s, Main.CompletionFoo)
test_complete_noshift(s) = map_completion_text(@inferred(completions(s, lastindex(s), Main, false)))

Expand Down Expand Up @@ -1841,15 +1841,15 @@ function Base.getproperty(v::Issue36437, s::Symbol)
end

let s = "Issue36437(42)."
c, r, res = test_complete_context(s, @__MODULE__)
c, r, res = test_complete_context(s)
@test res
for n in ("a", "b", "c")
@test n in c
end
end

let s = "Some(Issue36437(42)).value."
c, r, res = test_complete_context(s, @__MODULE__)
c, r, res = test_complete_context(s)
@test res
for n in ("a", "b", "c")
@test n in c
Expand All @@ -1858,7 +1858,7 @@ end

# aggressive concrete evaluation on mutable allocation in `repl_frame`
let s = "Ref(Issue36437(42))[]."
c, r, res = test_complete_context(s, @__MODULE__)
c, r, res = test_complete_context(s)
@test res
for n in ("a", "b", "c")
@test n in c
Expand All @@ -1868,7 +1868,7 @@ end

const global_xs = [Some(42)]
let s = "pop!(global_xs)."
c, r, res = test_complete_context(s, @__MODULE__)
c, r, res = test_complete_context(s)
@test res
@test "value" in c
end
Expand Down Expand Up @@ -1900,7 +1900,7 @@ end

Issue49892(x) = x
let s = "Issue49892(fal"
c, r, res = test_complete_context(s, @__MODULE__)
c, r, res = test_complete_context(s)
@test res
for n in ("false", "falses")
@test n in c
Expand All @@ -1920,3 +1920,15 @@ for (s, compl) in (("2*CompletionFoo.nam", "named"),
c, r = test_complete(s)
@test only(c) == compl
end

# allows symbol completion within incomplete :macrocall
# https://github.com/JuliaLang/julia/issues/51827
macro issue51827(args...)
length(args) 2 || error("@issue51827: incomplete arguments")
return args
end
let s = "@issue51827 Base.ac"
c, r, res = test_complete_context(s)
@test res
@test "acquire" in c
end

0 comments on commit 4aeef21

Please sign in to comment.