IntelliJ-Luanalysis
IntelliJ-Luanalysis copied to clipboard
Suggest/complete primitive indexed fields
Presently only named fields are suggested/completed.
For example:
---@class Vector
---@field x number
---@field y number
---@field [1] number
---@field [2] number
---@type Vector
local myVector
myVector.--<cursor here>
This will display a completion prompt that only includes the members x
and y
. However, it could also suggest [1]
and [2]
and upon completion delete the period.
Additionally, index expressions using brackets could similar be completed e.g.
myVector[--<cursor here>
If we're going to be completing all fields in brackets then we'll presumably want to prioritise primitive indexed fields over regular named fields and vice versa when completing fields after a period.
See https://github.com/Benjamin-Dobell/IntelliJ-Luanalysis/issues/27 for initial report.
Considerations / Additional Thoughts
We're only going to be completing primitives, but what about aliases? e.g.
---@alias Color "Red" | "Blue"
---@class Palette
---@field [Color] number
---@type Palette
local palette
palette.--<cursor here>
Should we suggest "Red" and "Blue"?
We certainly can, however completion prompts ought to be very responsive, so minimising work is a good idea 😕
It would also be useful to have aliases auto-complete when used as an explicit argument to a function
---@alias Color "Red" | "Blue"
---@param color Color
function setColor(color) end
setColor(" --<suggest Color aliases>
---@param color Color | string
function setCustomColor(color) end
setCustomColor(" --<also suggest Color aliases>