Skip to content

Commit 53adba9

Browse files
IanButterworthKristofferC
authored andcommitted
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 40f67ef commit 53adba9

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
@@ -138,6 +138,19 @@ function filtered_mod_names(ffunc::Function, mod::Module, name::AbstractString,
138138
ssyms = names(mod, all = all, imported = imported)
139139
filter!(ffunc, ssyms)
140140
macros = filter(x -> startswith(String(x), "@" * name), ssyms)
141+
142+
# don't complete string and command macros when the input matches the internal name like `r_` to `r"`
143+
if !startswith(name, "@")
144+
filter!(macros) do m
145+
s = String(m)
146+
if endswith(s, "_str") || endswith(s, "_cmd")
147+
occursin(name, first(s, length(s)-4))
148+
else
149+
true
150+
end
151+
end
152+
end
153+
141154
syms = String[sprint((io,s)->Base.show_sym(io, s; allow_macroname=true), s) for s in ssyms if completes_global(String(s), name)]
142155
appendmacro!(syms, macros, "_str", "\"")
143156
appendmacro!(syms, macros, "_cmd", "`")

stdlib/REPL/test/replcompletions.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,6 +1474,16 @@ test_dict_completion("test_repl_comp_customdict")
14741474
@test "testcmd`" in c
14751475
c, r, res = test_complete("CompletionFoo.tϵsτc")
14761476
@test "tϵsτcmδ`" in c
1477+
1478+
# Issue #56071: don't complete string and command macros when the input matches the internal name like `r_` to `r"`
1479+
c, r, res = test_complete("CompletionFoo.teststr_")
1480+
@test isempty(c)
1481+
c, r, res = test_complete("CompletionFoo.teststr_s")
1482+
@test isempty(c)
1483+
c, r, res = test_complete("CompletionFoo.testcmd_")
1484+
@test isempty(c)
1485+
c, r, res = test_complete("CompletionFoo.testcmd_c")
1486+
@test isempty(c)
14771487
end
14781488

14791489
@testset "Keyword-argument completion" begin

0 commit comments

Comments
 (0)