Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REPL: don't complete str and cmd macros when the input matches the internal name like r_ to r" #56254

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, s[1:end-4])
IanButterworth marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -1515,6 +1515,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