|
1 | 1 | ---@class vm |
2 | 2 | local vm = require 'vm.vm' |
3 | 3 | local guide = require 'parser.guide' |
| 4 | +local util = require 'utility' |
4 | 5 |
|
5 | 6 | ---@param arg parser.object |
6 | 7 | ---@return parser.object? |
@@ -360,18 +361,28 @@ function vm.getExactMatchedFunctions(func, args) |
360 | 361 | if not args or not funcs then |
361 | 362 | return funcs |
362 | 363 | end |
| 364 | + if #funcs == 1 then |
| 365 | + return funcs |
| 366 | + end |
363 | 367 | local uri = guide.getUri(func) |
364 | | - local result = {} |
365 | | - for _, n in ipairs(funcs) do |
366 | | - if not vm.isVarargFunctionWithOverloads(n) |
367 | | - and isAllParamMatched(uri, args, n.args) then |
368 | | - result[#result+1] = n |
| 368 | + local needRemove |
| 369 | + for i, n in ipairs(funcs) do |
| 370 | + if vm.isVarargFunctionWithOverloads(n) |
| 371 | + or not isAllParamMatched(uri, args, n.args) then |
| 372 | + if not needRemove then |
| 373 | + needRemove = {} |
| 374 | + end |
| 375 | + needRemove[#needRemove+1] = i |
369 | 376 | end |
370 | 377 | end |
371 | | - if #result == 0 then |
| 378 | + if not needRemove then |
| 379 | + return funcs |
| 380 | + end |
| 381 | + if #needRemove == #funcs then |
372 | 382 | return nil |
373 | 383 | end |
374 | | - return result |
| 384 | + util.tableMultiRemove(funcs, needRemove) |
| 385 | + return funcs |
375 | 386 | end |
376 | 387 |
|
377 | 388 | ---@param func parser.object |
@@ -414,23 +425,31 @@ function vm.isVarargFunctionWithOverloads(func) |
414 | 425 | if not func.args then |
415 | 426 | return false |
416 | 427 | end |
| 428 | + if func._varargFunction ~= nil then |
| 429 | + return func._varargFunction |
| 430 | + end |
417 | 431 | if func.args[1] and func.args[1].type == 'self' then |
418 | 432 | if not func.args[2] or func.args[2].type ~= '...' then |
| 433 | + func._varargFunction = false |
419 | 434 | return false |
420 | 435 | end |
421 | 436 | else |
422 | 437 | if not func.args[1] or func.args[1].type ~= '...' then |
| 438 | + func._varargFunction = false |
423 | 439 | return false |
424 | 440 | end |
425 | 441 | end |
426 | 442 | if not func.bindDocs then |
| 443 | + func._varargFunction = false |
427 | 444 | return false |
428 | 445 | end |
429 | 446 | for _, doc in ipairs(func.bindDocs) do |
430 | 447 | if doc.type == 'doc.overload' then |
| 448 | + func._varargFunction = true |
431 | 449 | return true |
432 | 450 | end |
433 | 451 | end |
| 452 | + func._varargFunction = false |
434 | 453 | return false |
435 | 454 | end |
436 | 455 |
|
|
0 commit comments