Skip to content

Commit 6a47db8

Browse files
dhoeghfredrikekre
authored andcommitted
Fix 22577. Add string macros to REPLCompletion. (#23119)
* Fix 22577. Add string macros to REPLCompletion. * Add cmd macros to REPLCompletion. * retrigger ci, update to a testset * unicode tests. * also complete the unicode char
1 parent 89772d4 commit 6a47db8

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

base/repl/REPLCompletions.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,19 @@ function completes_global(x, name)
1010
return startswith(x, name) && !('#' in x)
1111
end
1212

13+
function appendmacro!(syms, macros, needle, endchar)
14+
append!(syms, s[2:end-sizeof(needle)]*endchar for s in filter(x -> endswith(x, needle), macros))
15+
end
16+
1317
function filtered_mod_names(ffunc::Function, mod::Module, name::AbstractString, all::Bool=false, imported::Bool=false)
1418
ssyms = names(mod, all, imported)
1519
filter!(ffunc, ssyms)
1620
syms = String[string(s) for s in ssyms]
21+
macros = filter(x -> startswith(x, "@" * name), syms)
22+
appendmacro!(syms, macros, "_str", "\"")
23+
appendmacro!(syms, macros, "_cmd", "`")
1724
filter!(x->completes_global(x, name), syms)
25+
return syms
1826
end
1927

2028
# REPL Symbol Completions

test/replcompletions.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ ex = quote
6565
contains=>4, `ls`=>5, 66=>7, 67=>8, ("q",3)=>11,
6666
"α"=>12, =>13)
6767
test_customdict = CustomDict(test_dict)
68+
69+
macro teststr_str(s) end
70+
macro tϵsτstρ_str(s) end
71+
macro testcmd_cmd(s) end
72+
macro tϵsτcmδ_cmd(s) end
73+
6874
end
6975
test_repl_comp_dict = CompletionFoo.test_dict
7076
test_repl_comp_customdict = CompletionFoo.test_customdict
@@ -788,3 +794,16 @@ test_dict_completion("test_repl_comp_customdict")
788794

789795
# Issue #23004: this should not throw:
790796
@test REPLCompletions.dict_identifier_key("test_dict_ℂ[\\", :other) isa Tuple
797+
798+
@testset "completion of string/cmd macros (#22577)" begin
799+
c, r, res = test_complete("ra")
800+
@test "raw\"" in c
801+
c, r, res = test_complete("CompletionFoo.tests")
802+
@test "teststr\"" in c
803+
c, r, res = test_complete("CompletionFoo.tϵsτs")
804+
@test "tϵsτstρ\"" in c
805+
c, r, res = test_complete("CompletionFoo.testc")
806+
@test "testcmd`" in c
807+
c, r, res = test_complete("CompletionFoo.tϵsτc")
808+
@test "tϵsτcmδ`" in c
809+
end

0 commit comments

Comments
 (0)