Skip to content

Conversation

f-ell
Copy link

@f-ell f-ell commented Aug 14, 2025

Tuple types as function parameters are incorrectly parsed as multiple parameters when generating the function signature. This breaks highlighting for the currently active function parameter.

MWE, generated highlight denoted by <...>:

---@param a [any, any]
---@param b any
function X(a, b) end

X({ 1, 2 }|, 3)
-- expected: function X(<a: [any, any]>, b: any)
-- actual:   function X(<a: [any>, any], b: any)

X({ 1, 2 }, 3|)
-- expected: function X(a: [any, any], <b: any>)
-- actual:   function X(a: [any, <any]>, b: any)

Any square brackets are blindly replaced with _ when generating the signature. This works for array types (e.g. any[], which becomes any__), but breaks when scanning for the next parameter delimiter inside of tuples (e.g. [any, any], which becomes _any, any_). Removing matching brackets via %b[] instead keeps the same behaviour for array types, but blanks out the entire tuple for tuple types (i.e. [any, any] becomes __________).

The only potential problem I see with this approach are dictionaries, which may also contain square brackets. These are substituted before attempting to match square brackets however, so this should not cause any issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant