local core = require 'core.signature' local files = require 'files' local catch = require 'catch' rawset(_G, 'TEST', true) ---@diagnostic disable: await-in-sync function TEST(script) return function (expect) local newScript, catched1 = catch(script, '?') files.setText('', newScript) local hovers = core('', catched1['?'][1][1]) if hovers then assert(#hovers == #expect) for i, hover in ipairs(hovers) do local newExpect, catched2 = catch(expect[i], '!') local arg = hover.params[hover.index] assert(newExpect == hover.label) if arg then assert(catched2['!'][1] ~= nil) assert(catched2['!'][1][1] == arg.label[1]) assert(catched2['!'][1][2] == arg.label[2]) else assert(#catched2['!'] == 0) end end else assert(expect == nil) end files.remove('') end end TEST [[ local function x(a, b) end x( ]] {'function x(, b: any)'} TEST [[ local function x(a, b) end x() ]] {'function x(, b: any)'} TEST [[ local function x(a, b) end x(xxx) ]] {'function x(, b: any)'} TEST [[ local function x(a, b) end x(xxx, ) ]] {'function x(a: any, )'} TEST [[ function mt:f(a) end mt:f( ]] {'(method) mt:f()'} TEST [[ local function x(a, b) return 1 end x( ]] {'function x(, b: any)'} TEST [[ local function x(a, ...) return 1 end x(1, 2, 3, ]] {'function x(a: any, )'} TEST [[ (''):sub( ]] {'(method) string:sub(, j?: integer)'} TEST [[ (''):sub(1) ]] (nil) TEST [[ local function f(a, b, c) end f(1, 'string') ]] {'function f(a: any, , c: any)'} TEST [[ pcall(function () end) ]] (nil) TEST [[ table.unpack {} ]] (nil) TEST [[ ---@type fun(x: number, y: number):boolean local zzzz zzzz() ]] {'function zzzz(, y: number)'} TEST [[ ('abc'):format(f()) ]] (nil) TEST [[ function Foo(param01, param02) end Foo() ]] {'function Foo(, param02: any)'} TEST [[ function f1(a, b) end function f2(c, d) end f2(f1(),) ]] {'function f2(c: any, )'} TEST [[ local function f(a, b, c) end f({},) ]] {'function f(a: any, , c: any)'} TEST [[ for _ in pairs() do end ]] {'function pairs(!>)'} TEST [[ function m:f() end m.f() ]] {'function m.f()'} TEST [[ ---@alias nnn table ---@param x nnn local function f(x, y, z) end f() ]] {'function f(!>, y: any, z: any)'} TEST [[ local function x(a, b) end x( aaaa , 2) ]] {"function x(, b: any)"} TEST [[ local function x(a, b) end x( aaaa , 2) ]] {'function x(, b: any)'} TEST [[ local function x(a, b) end x(aaaa , 2) ]] {'function x(a: any, )'} TEST [[ local function x(a, b) end x(aaaa , 2 ) ]] {'function x(a: any, )'} TEST [[ local fooC ---test callback ---@param callback fun(x:number, s:string):nil @callback ---@param par number @par function fooC(callback, par) end fooC(function (x, s) end,) ]] {'function fooC(callback: fun(x: number, s: string):nil, )'} TEST [[ (function (a, b) end)() ]] {'function (, b: any)'} TEST [[ function X() end ---@param a number function X(a) end ---@param a number ---@param b number function X(a, b) end X() ]] { 'function X()', 'function X()', 'function X(, b: number)', } TEST [[ function X() end ---@param a number function X(a) end ---@param a number ---@param b number function X(a, b) end X() ]] { 'function X()', 'function X(, b: number)', } TEST [[ function X() end ---@param a number function X(a) end ---@param a number ---@param b number function X(a, b) end X(1, ) ]] { 'function X(a: number, )', } TEST [[ function X() end ---@param a number function X(a) end ---@param a number ---@param b number function X(a, b) end X(1, ) ]] { 'function X(a: number, )', }