Benjamin-Dobell / IntelliJ-Luanalysis

Type-safe Lua IDE — IntelliJ IDEA plugin
Apache License 2.0
154 stars 21 forks source link

Alternative way to add overloads #58

Open pouwelsjochem opened 3 years ago

pouwelsjochem commented 3 years ago

Environment

name version
IDEA version IC2020.3
Luanalysis version 1.2.2
OS MacOS Big Sur

What happens?

As of now, function overloads always need to be added by using the @overload annotation. But this annotation requires you to copy&paste most of your signature.

What were you expecting to happen?

Most of my overloads are actually optional parameters, it would be nice if there was a way to indicate optional parameters in a different way so overloads are added automatically.

See below for several examples how I think the syntax could look like:

current situation

---@param _duration number
---@param _easing EasingFunction
---@param _delta boolean
---@param _properties table
---@optional _options table<string, number>
---@param _onComplete TransitionOnCompleteFunction
---@return TransitionHandle|nil
---@overload fun(_obj, _duration:number, _easing:EasingFunction, _delta:boolean, _properties:table<string, number>):TransitionHandle|nil
---@overload fun(_obj, _duration:number, _easing:EasingFunction, _delta:boolean, _properties:table<string, number>, _options:table):TransitionHandle|nil
---@overload fun(_obj, _duration:number, _easing:EasingFunction, _delta:boolean, _properties:table<string, number>, _onComplete:TransitionOnCompleteFunction):TransitionHandle|nil
---@overload fun(_obj, _duration:number, _easing:EasingFunction, _delta:boolean, _properties:table<string, number>, _options:table, _onComplete:TransitionOnCompleteFunction):TransitionHandle|nil
local function createToTransition(_obj, _duration, _easing, _delta, _properties, _options, _onComplete)

void type parameters

---@param _duration number
---@param _easing EasingFunction
---@param _delta boolean
---@param _properties table
---@param _options void|table<string, number>
---@param _onComplete void|TransitionOnCompleteFunction
---@return TransitionHandle|nil
local function createToTransition(_obj, _duration, _easing, _delta, _properties, _options, _onComplete) end

suffixed or prefixed parameters

---@param _duration number
---@param _easing EasingFunction
---@param _delta boolean
---@param _properties table
---@param _options table<string, number>?
---@param _onComplete TransitionOnCompleteFunction?
---@return TransitionHandle|nil
local function createToTransition(_obj, _duration, _easing, _delta, _properties, _options, _onComplete) end

@optionalparam annotation

---@param _duration number
---@param _easing EasingFunction
---@param _delta boolean
---@param _properties table
---@optionalparam _options table<string, number>?
---@optionalparam _onComplete TransitionOnCompleteFunction?
---@return TransitionHandle|nil
local function createToTransition(_obj, _duration, _easing, _delta, _properties, _options, _onComplete) end
adriweb commented 3 years ago

The ? at the end of the type might be problematic in case of complex type (foo|bar? isn't quite clear... let alone if there's a description afterwards). Other propositions: