autocomplete for contents of custom type

I am trying to build some better inspection for some custom types in a scripting workflow. The working example of what I am after is from a Dict() where tab-suggestions are available for keys of a dictionary in the jupyter notebook, e.g.:

thisdict = Dict("key1" => 1, "key2" => 2)


so lets say for:

mutable struct ThisType
julia> t = ThisType([0.0, 1.0, 10.0], ["Bob", "Earl", "Pete"])

julia> t["<presstab>"] # shows me "Bob", "Earl", "Pete" 

This assumes the object can be indexed by the strings, so somehow this is related to setindex! or getindex methods?

Does anyone know what needs to be overloaded for my custom type to make this work? Is it simple? I cant figure it out though and would appreciate help!

I didn’t find simple and guaranteed way how to do it. Code bellow is how I could do something similar. It is incomplete and wrong! (But maybe it could give some inspiration to abandon idea? :stuck_out_tongue: )

julia> VERSION

julia> import Base: keys, length, start, done, next, keytype;

julia> mutable struct ThisType{K,V} <: AbstractDict{K,V}
                  function ThisType{K,V}(x, y) where {K, V} new(x, y) end

julia> length(x::ThisType{K,V}) where {K,V} = length(x.names);

julia> start(x::ThisType{K,V}) where {K,V} = start(x.names);

julia> done(x::ThisType{K,V}, y::Int64) where {K,V} = done(x.names, y);

julia> next(x::ThisType{K,V}, y::Int64) where {K,V} = next(x.names, y);

julia> keytype(x::ThisType{K,V}) where {K,V}  = V;

julia> keys(x::ThisType{K,V}) where {K,V} = x.names;

julia> t = ThisType{Float64,String}([0.0, 1.0, 10.0], ["Bob", "Earl", "Pete"])
ThisType{Float64,String} with 3 entries:
  'B' => 'o'
  'E' => 'a'
  'P' => 'e'

julia> t["    # <presstab>
"Bob"  "Earl"  "Pete"

If you insist to have this functionality then maybe you could try to change Base.REPLCompletions…

Thanks! I appreciate the reply. That seems to work…

It certainly seems like more trouble than its worth! But I will file it away for future… maybe…
Thanks again.