Skip to content

Commit 6be0afc

Browse files
REPL: don't complete str and cmd macros when the input matches the internal name like r_ to r" (#56254)
(cherry picked from commit 4236a33)
1 parent 32d97c4 commit 6be0afc

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

stdlib/REPL/src/REPLCompletions.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,19 @@ function filtered_mod_names(ffunc::Function, mod::Module, name::AbstractString,
140140
all || filter!(Base.Fix1(Base.isexported, mod), ssyms)
141141
filter!(ffunc, ssyms)
142142
macros = filter(x -> startswith(String(x), "@" * name), ssyms)
143+
144+
# don't complete string and command macros when the input matches the internal name like `r_` to `r"`
145+
if !startswith(name, "@")
146+
filter!(macros) do m
147+
s = String(m)
148+
if endswith(s, "_str") || endswith(s, "_cmd")
149+
occursin(name, first(s, length(s)-4))
150+
else
151+
true
152+
end
153+
end
154+
end
155+
143156
syms = String[sprint((io,s)->Base.show_sym(io, s; allow_macroname=true), s) for s in ssyms if completes_global(String(s), name)]
144157
appendmacro!(syms, macros, "_str", "\"")
145158
appendmacro!(syms, macros, "_cmd", "`")

stdlib/REPL/test/replcompletions.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,6 +1529,16 @@ test_dict_completion("test_repl_comp_customdict")
15291529
@test "testcmd`" in c
15301530
c, r, res = test_complete("CompletionFoo.tϵsτc")
15311531
@test "tϵsτcmδ`" in c
1532+
1533+
# Issue #56071: don't complete string and command macros when the input matches the internal name like `r_` to `r"`
1534+
c, r, res = test_complete("CompletionFoo.teststr_")
1535+
@test isempty(c)
1536+
c, r, res = test_complete("CompletionFoo.teststr_s")
1537+
@test isempty(c)
1538+
c, r, res = test_complete("CompletionFoo.testcmd_")
1539+
@test isempty(c)
1540+
c, r, res = test_complete("CompletionFoo.testcmd_c")
1541+
@test isempty(c)
15321542
end
15331543

15341544
@testset "Keyword-argument completion" begin

0 commit comments

Comments
 (0)