summaryrefslogtreecommitdiff
path: root/script/vm/infer.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-03-10 21:03:07 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-03-10 21:03:07 +0800
commit8a7c94965cf6c632b3b85956f0e64928df8dc42d (patch)
treed1fe2fba7af02d740acd0b83c8de46b0ea236fab /script/vm/infer.lua
parent04601c7da4a485d84be5e0b9864acf27f978c275 (diff)
downloadlua-language-server-8a7c94965cf6c632b3b85956f0e64928df8dc42d.zip
update
Diffstat (limited to 'script/vm/infer.lua')
-rw-r--r--script/vm/infer.lua40
1 files changed, 40 insertions, 0 deletions
diff --git a/script/vm/infer.lua b/script/vm/infer.lua
index 80558eaf..bcbd2935 100644
--- a/script/vm/infer.lua
+++ b/script/vm/infer.lua
@@ -28,6 +28,14 @@ local viewNodeMap = util.switch()
: call(function (source, options)
options['hasTable'] = true
end)
+ : case 'local'
+ : call(function (source, options)
+ if source.parent == 'funcargs' then
+ options['isParam'] = true
+ else
+ options['isLocal'] = true
+ end
+ end)
: case 'global'
: call(function (source, options)
if source.cate == 'type' then
@@ -52,6 +60,33 @@ local viewNodeMap = util.switch()
: call(function (source, options)
return ('%q'):format(source[1])
end)
+ : case 'doc.type.function'
+ : call(function (source, options)
+ local args = {}
+ local rets = {}
+ local argView = ''
+ local regView = ''
+ for i, arg in ipairs(source.args) do
+ args[i] = string.format('%s%s: %s'
+ , arg.name[1]
+ , arg.optional and '?' or ''
+ , m.viewType(arg)
+ )
+ end
+ if #args > 0 then
+ argView = table.concat(args, ', ')
+ end
+ for i, ret in ipairs(source.returns) do
+ rets[i] = string.format('%s%s'
+ , m.viewType(ret)
+ , ret.optional and '?' or ''
+ )
+ end
+ if #rets > 0 then
+ regView = ':' .. table.concat(rets, ', ')
+ end
+ return ('fun(%s)%s'):format(argView, regView)
+ end)
: getMap()
---@param node vm.node
@@ -119,6 +154,11 @@ end
---@return string
function m.viewType(source)
local views = m.getViews(source)
+
+ if views['any'] then
+ return 'any'
+ end
+
if not next(views) then
return 'unknown'
end