Skip to content

Commit

Permalink
Fix 22577. Add string macros to REPLCompletion. (JuliaLang#23119)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
dhoegh authored and fredrikekre committed Aug 29, 2017
1 parent 89772d4 commit 6a47db8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
8 changes: 8 additions & 0 deletions base/repl/REPLCompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,19 @@ function completes_global(x, name)
return startswith(x, name) && !('#' in x)
end

function appendmacro!(syms, macros, needle, endchar)
append!(syms, s[2:end-sizeof(needle)]*endchar for s in filter(x -> endswith(x, needle), macros))
end

function filtered_mod_names(ffunc::Function, mod::Module, name::AbstractString, all::Bool=false, imported::Bool=false)
ssyms = names(mod, all, imported)
filter!(ffunc, ssyms)
syms = String[string(s) for s in ssyms]
macros = filter(x -> startswith(x, "@" * name), syms)
appendmacro!(syms, macros, "_str", "\"")
appendmacro!(syms, macros, "_cmd", "`")
filter!(x->completes_global(x, name), syms)
return syms
end

# REPL Symbol Completions
Expand Down
19 changes: 19 additions & 0 deletions test/replcompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ ex = quote
contains=>4, `ls`=>5, 66=>7, 67=>8, ("q",3)=>11,
"α"=>12, =>13)
test_customdict = CustomDict(test_dict)

macro teststr_str(s) end
macro tϵsτstρ_str(s) end
macro testcmd_cmd(s) end
macro tϵsτcmδ_cmd(s) end

end
test_repl_comp_dict = CompletionFoo.test_dict
test_repl_comp_customdict = CompletionFoo.test_customdict
Expand Down Expand Up @@ -788,3 +794,16 @@ test_dict_completion("test_repl_comp_customdict")

# Issue #23004: this should not throw:
@test REPLCompletions.dict_identifier_key("test_dict_ℂ[\\", :other) isa Tuple

@testset "completion of string/cmd macros (#22577)" begin
c, r, res = test_complete("ra")
@test "raw\"" in c
c, r, res = test_complete("CompletionFoo.tests")
@test "teststr\"" in c
c, r, res = test_complete("CompletionFoo.tϵsτs")
@test "tϵsτstρ\"" in c
c, r, res = test_complete("CompletionFoo.testc")
@test "testcmd`" in c
c, r, res = test_complete("CompletionFoo.tϵsτc")
@test "tϵsτcmδ`" in c
end

0 comments on commit 6a47db8

Please sign in to comment.