Skip to content

Commit 4236a33

Browse files
REPL: don't complete str and cmd macros when the input matches the internal name like r_ to r" (#56254)
1 parent 28b0abd commit 4236a33

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

stdlib/REPL/src/REPLCompletions.jl

+13
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,19 @@ function append_filtered_mod_names!(ffunc::Function, suggestions::Vector{Complet
141141
ssyms = names(mod; all=true, imported, usings)
142142
filter!(ffunc, ssyms)
143143
macros = filter(x -> startswith(String(x), "@" * name), ssyms)
144+
145+
# don't complete string and command macros when the input matches the internal name like `r_` to `r"`
146+
if !startswith(name, "@")
147+
filter!(macros) do m
148+
s = String(m)
149+
if endswith(s, "_str") || endswith(s, "_cmd")
150+
occursin(name, first(s, length(s)-4))
151+
else
152+
true
153+
end
154+
end
155+
end
156+
144157
syms = String[sprint((io,s)->Base.show_sym(io, s; allow_macroname=true), s) for s in ssyms if completes_global(String(s), name)]
145158
appendmacro!(syms, macros, "_str", "\"")
146159
appendmacro!(syms, macros, "_cmd", "`")

stdlib/REPL/test/replcompletions.jl

+10
Original file line numberDiff line numberDiff line change
@@ -1546,6 +1546,16 @@ end
15461546
@test "testcmd`" in c
15471547
c, r, res = test_complete("CompletionFoo.tϵsτc")
15481548
@test "tϵsτcmδ`" in c
1549+
1550+
# Issue #56071: don't complete string and command macros when the input matches the internal name like `r_` to `r"`
1551+
c, r, res = test_complete("CompletionFoo.teststr_")
1552+
@test isempty(c)
1553+
c, r, res = test_complete("CompletionFoo.teststr_s")
1554+
@test isempty(c)
1555+
c, r, res = test_complete("CompletionFoo.testcmd_")
1556+
@test isempty(c)
1557+
c, r, res = test_complete("CompletionFoo.testcmd_c")
1558+
@test isempty(c)
15491559
end
15501560

15511561
@testset "Keyword-argument completion" begin

0 commit comments

Comments
 (0)