Skip to content

Commit

Permalink
REPL: don't complete str and cmd macros when the input matches the in…
Browse files Browse the repository at this point in the history
…ternal name like `r_` to `r"` (#56254)
  • Loading branch information
IanButterworth authored Oct 23, 2024
1 parent 28b0abd commit 4236a33
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
13 changes: 13 additions & 0 deletions stdlib/REPL/src/REPLCompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,19 @@ function append_filtered_mod_names!(ffunc::Function, suggestions::Vector{Complet
ssyms = names(mod; all=true, imported, usings)
filter!(ffunc, ssyms)
macros = filter(x -> startswith(String(x), "@" * name), ssyms)

# don't complete string and command macros when the input matches the internal name like `r_` to `r"`
if !startswith(name, "@")
filter!(macros) do m
s = String(m)
if endswith(s, "_str") || endswith(s, "_cmd")
occursin(name, first(s, length(s)-4))
else
true
end
end
end

syms = String[sprint((io,s)->Base.show_sym(io, s; allow_macroname=true), s) for s in ssyms if completes_global(String(s), name)]
appendmacro!(syms, macros, "_str", "\"")
appendmacro!(syms, macros, "_cmd", "`")
Expand Down
10 changes: 10 additions & 0 deletions stdlib/REPL/test/replcompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1546,6 +1546,16 @@ end
@test "testcmd`" in c
c, r, res = test_complete("CompletionFoo.tϵsτc")
@test "tϵsτcmδ`" in c

# Issue #56071: don't complete string and command macros when the input matches the internal name like `r_` to `r"`
c, r, res = test_complete("CompletionFoo.teststr_")
@test isempty(c)
c, r, res = test_complete("CompletionFoo.teststr_s")
@test isempty(c)
c, r, res = test_complete("CompletionFoo.testcmd_")
@test isempty(c)
c, r, res = test_complete("CompletionFoo.testcmd_c")
@test isempty(c)
end

@testset "Keyword-argument completion" begin
Expand Down

0 comments on commit 4236a33

Please sign in to comment.