Skip to content

Question: How to document an array of functions which have a return type? #3370

@Eyrim

Description

@Eyrim

Issue Description

Hi!

I apologise if this is the wrong place, or this is documented somewhere. I've looked through the documentation website, and the Github issues on this repo and not found anything. But feel free to redirect me :).

I have a third party field which I need to set in multiple places, but it doesn't provide an insert-esque function so I'm writing a function which takes an array of functions as callbacks so it can all be done in one place, I've attached the idea if that is helpful at all.

But the bottom line is, I want to document that array of functions appropriately. This is the type signature I would expect in other languages:

(Key, is the return type of each function in my array).

Java
: ArrayList<Function<Wezterm, Key>>

Rust (in a language-nuance free world)
: Vec<Fn(Wezterm) -> Key>

etc.

I've tried:

---@field setup_functions { fun(wezterm: Wezterm): Key } []
---@field setup_functions { [integer]: fun(wezterm: Wezterm): Key } [] (This was misinterpreting #2367)
---@field setup_functions []fun(wezterm: Wezterm): Key

Is this possible, or supported?

(I'm by no means a lua expert, so this might sound completely insane, if there is a better way that jumps out you screaming, then by all means feel free to share lol)

---@class Keys
local module = {}
---
---@class Keys.config
---@field leader_setup_function fun(): LeaderKey
---@field setup_functions {  fun(wezterm: Wezterm): Key } []
local _ = {}

---TODO
---@param wezterm Wezterm
---@param config Config
---@param key_config Keys.config
function module.setup(wezterm, config, key_config)
    config.leader = key_config.leader_setup_function()
    ---The keys we're creating mappings for
    ---
    ---This array has an insert function, using table.insert even though arrays don't have an insert for some reason
    ---@type Key[]
    local keys = { insert = table.insert }

    for _, fun in pairs(key_config.setup_functions) do
        fun(wezterm)
    end
end

---comment
---@param key string
---@param mods string
---@return fun(): LeaderKey
function module.leader(key, mods)
    return function()
        return {
            key = key,
            mods = mods
        }
    end
end

I've put this down as documentation, because I would expect this to be supported, and I couldn't find it in the documentation. Implying a gap (or me being blind), apologies if incorrectly tagged.

Additional Notes

No response

Metadata

Metadata

Assignees

Labels

documentationHas to do with documentation either in the wiki or in the repo

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions