Page 1 of 1

Use string unions instead of generic string

Posted: Thu Dec 28, 2023 6:30 am
by _CodeGreen
There are a number of places where things like function parameters and concept fields have a type of string, but can only be strings from a defined list.
Would it be possible to make those unions, that way they show up in the autocomplete list when using FMTK + LuaLS?
It's not the end of the world because they still show up in the tooltip, but it would be nice to not have to type some of the longer ones out.

Examples:
LuaItemStack::get_mapper() and set_mapper()
TrainPathFinderRequest::type
ElemID::type
There are plenty more, I won't list them for brevity.

Re: Use string unions instead of generic string

Posted: Thu Dec 28, 2023 5:53 pm
by Bilka
Thanks for noting this, I fixed the listed methods/attributes and checked and fixed the following classes for the next release (1.1.102):
LuaItemStack
LuaStyle
LuaGuiElement
LuaEntity
LuaEntityPrototype
LuaItemPrototype
LuaLogisticNetwork
LuaGameScript
ItemPrototypeFilters
EntityPrototypeFilters
every type on https://lua-api.factorio.com/latest/concepts.html except the rest of the prototype and event filters.

For other types I'd appreciate if you could note instances when you come across them (either here or in new threads, doesn't matter). The above list of fixes is based what I found with a few searches and the classes that I had noted down already in my own notes, but I expect that I missed a bunch of things.

Re: Use string unions instead of generic string

Posted: Tue Jan 09, 2024 6:01 am
by _CodeGreen
Thanks for fixing those!

I went through every class searching for [or "] and found a couple more:
LuaCustomInputPrototype::consuming
LuaFluidBoxPrototype::production_type
LuaRendering::set_alignment
LuaRendering::set_vertical_alignment
LuaSurface::create_entity.type for underground-belt

Re: Use string unions instead of generic string

Posted: Tue Jan 09, 2024 7:38 pm
by Bilka
Thanks, those are good finds! Fixed for the next release (1.1.102).
I found a few more on LuaRendering (get_type and the rest of the alignment methods) and on LuaSurface, there it was mostly ForceIdentification being listed as only string or Force.