# autocomplete for contents of custom type

**URL:** <https://discourse.julialang.org/t/autocomplete-for-contents-of-custom-type/8304>\
**Category:** General Usage\
**Tags:** question\
**Created:** [January 12, 2018, 5:33am UTC](https://discourse.julialang.org/t/autocomplete-for-contents-of-custom-type/8304 "2018-01-12T05:33:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rmar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rmar/32/3020_2.png) [@rmar](https://discourse.julialang.org/u/rmar)\
**Post date:** [January 12, 2018, 5:33am UTC](https://discourse.julialang.org/t/autocomplete-for-contents-of-custom-type/8304/1 "2018-01-12T05:33:03Z")

</div>

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.:

```julia
thisdict = Dict("key1" => 1, "key2" => 2)
thisdict["<presstab>"]

```

shows  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/a/1/a1839ac362a4fda2a1ae48da0248a8d31234fcba.png)

so lets say for:

```julia
mutable struct ThisType
    v::Vector{Float64}
    names::Vector{String}
end

```

```julia
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!  
Thanks.

---

<div class="post-metadata">

**Author:** ![Liso](https://avatars.discourse-cdn.com/v4/letter/l/898d66/32.png) [@Liso](https://discourse.julialang.org/u/Liso)\
**Post date:** [January 12, 2018, 10:24am UTC](https://discourse.julialang.org/t/autocomplete-for-contents-of-custom-type/8304/2 "2018-01-12T10:24:02Z")

</div>

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? 😛 )

```julia
julia> VERSION
v"0.7.0-DEV.3373"

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

julia> mutable struct ThisType{K,V} <: AbstractDict{K,V}
                  v::Vector{K}
                  names::Vector{V}
                  function ThisType{K,V}(x, y) where {K, V} new(x, y) end
              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…

---

<div class="post-metadata">

**Author:** ![rmar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rmar/32/3020_2.png) [@rmar](https://discourse.julialang.org/u/rmar)\
**Post date:** [January 12, 2018, 12:59pm UTC](https://discourse.julialang.org/t/autocomplete-for-contents-of-custom-type/8304/3 "2018-01-12T12:59:49Z")

</div>

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

> [@Liso](#):
>
> inspiration to abandon idea? 😛 )

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