Skip to content

Autocomplete for keys of custom non-dictionary type #55074

@artememelin

Description

@artememelin

I'm faced with a problem that I need to create a new custom type that will inherit from the AbstractVector, but will also contain the keys/names of the corresponding elements, like this:

struct MyType{T} <: AbstractVector{T}
    names::Vector{String}
    values::Vector{T}
end

Base.size(x::MyType) = size(x.values)

And accordingly, access to elements should be carried out both by indexes and by names:

function Base.getindex(x::MyType, ind...)
    return x.values[ind...]
end

function Base.getindex(x::MyType, key::AbstractString)
    return x[findall(==(key), x.names)...]
end

And finally, I would like to receive these keys as a hint as a result of auto-completion (TAB key in REPL):

julia> my_container = MyType{Int64}(["key_1", "key_2"], [1, 2])

julia> my_container["key_<TAB>
"key_1"  "key_2"

Is there currently any way to implement this behavior?

I found several threads with almost no answers on this topic:

Metadata

Metadata

Assignees

No one assigned

    Labels

    REPLJulia's REPL (Read Eval Print Loop)completionsTab and autocompletion in the replfeatureIndicates new feature / enhancement requests

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions