There is no specific way to do this. JuMP interpolates the index as something similar to "x[$(index)]", so it depends on your show method.
However, you can write a loop calling set_name to explicitly set the name for all indices:
julia> struct Item
name::String
end
julia> items = [Item("a"), Item("b")]
2-element Vector{Item}:
Item("a")
Item("b")
julia> model = Model();
julia> @variable(model, x[items])
1-dimensional DenseAxisArray{VariableRef,1,...} with index sets:
Dimension 1, Item[Item("a"), Item("b")]
And data, a 2-element Vector{VariableRef}:
x[Item("a")]
x[Item("b")]
julia> for i in items
set_name(x[i], i.name)
end
julia> x
1-dimensional DenseAxisArray{VariableRef,1,...} with index sets:
Dimension 1, Item[Item("a"), Item("b")]
And data, a 2-element Vector{VariableRef}:
a
b
julia> 2x[items[1]] + x[items[2]]
2 a + b