From 4aeef2147943ed21cd91b66fa867af9c2a52753e Mon Sep 17 00:00:00 2001 From: Shuhei Kadowaki <40514306+aviatesk@users.noreply.github.com> Date: Wed, 25 Oct 2023 15:45:45 +0900 Subject: [PATCH] [REPLCompletions] allow symbol completions within incomplete macrocall expression (#51834) fix #51827 --------- Co-authored-by: Kristoffer Carlsson (cherry picked from commit 3b1ba62bd27e0dabbd2ec0a6c000edb8138c5915) --- stdlib/REPL/src/REPLCompletions.jl | 5 +++++ stdlib/REPL/test/replcompletions.jl | 24 ++++++++++++++++++------ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/stdlib/REPL/src/REPLCompletions.jl b/stdlib/REPL/src/REPLCompletions.jl index 94ca678b8f387..b94ea3da2890b 100644 --- a/stdlib/REPL/src/REPLCompletions.jl +++ b/stdlib/REPL/src/REPLCompletions.jl @@ -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)) diff --git a/stdlib/REPL/test/replcompletions.jl b/stdlib/REPL/test/replcompletions.jl index c515ec5927dd3..63b629c5aa784 100644 --- a/stdlib/REPL/test/replcompletions.jl +++ b/stdlib/REPL/test/replcompletions.jl @@ -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))) @@ -1841,7 +1841,7 @@ 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 @@ -1849,7 +1849,7 @@ let s = "Issue36437(42)." 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 @@ -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 @@ -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 @@ -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 @@ -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