summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
authorTom Lau <tomandfatboy@gmail.com>2024-09-06 10:56:07 +0800
committerTom Lau <tomandfatboy@gmail.com>2024-09-07 10:34:44 +0800
commit4e616bb1f773b430f1997ec675f8336ad8f1803b (patch)
treecb532440a81dc00b91e81cd71b0455102603d899 /script
parentc9d819305b6f88b53de294d54c820681518430c8 (diff)
downloadlua-language-server-4e616bb1f773b430f1997ec675f8336ad8f1803b.zip
fix: ignore function's auto infer type when there is only `@overload`
Diffstat (limited to 'script')
-rw-r--r--script/vm/function.lua31
1 files changed, 31 insertions, 0 deletions
diff --git a/script/vm/function.lua b/script/vm/function.lua
index 7a15ac5a..21a432c1 100644
--- a/script/vm/function.lua
+++ b/script/vm/function.lua
@@ -359,6 +359,7 @@ end
---@return number
local function calcFunctionMatchScore(uri, args, func)
if vm.isVarargFunctionWithOverloads(func)
+ or vm.isFunctionWithOnlyOverloads(func)
or not isAllParamMatched(uri, args, func.args)
then
return -1
@@ -490,6 +491,36 @@ function vm.isVarargFunctionWithOverloads(func)
return false
end
+---@param func table
+---@return boolean
+function vm.isFunctionWithOnlyOverloads(func)
+ if func.type ~= 'function' then
+ return false
+ end
+ if func._onlyOverloadFunction ~= nil then
+ return func._onlyOverloadFunction
+ end
+
+ if not func.bindDocs then
+ func._onlyOverloadFunction = false
+ return false
+ end
+ local hasOverload = false
+ for _, doc in ipairs(func.bindDocs) do
+ if doc.type == 'doc.overload' then
+ hasOverload = true
+ elseif doc.type == 'doc.param'
+ or doc.type == 'doc.return'
+ then
+ -- has specified @param or @return, thus not only @overload
+ func._onlyOverloadFunction = false
+ return false
+ end
+ end
+ func._onlyOverloadFunction = hasOverload
+ return true
+end
+
---@param func parser.object
---@return boolean
function vm.isEmptyFunction(func)