summaryrefslogtreecommitdiff
path: root/script/vm
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-03-10 17:54:42 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-03-10 17:54:42 +0800
commit32fd9f2cef67919ef37d7a6396ae0a8c7d7f224f (patch)
treeeb76f5d29360cd2cdc05ff428e9e4a7aa7f13c6b /script/vm
parent2178706a33e6f15a8cea567c352d9a567c38abb9 (diff)
downloadlua-language-server-32fd9f2cef67919ef37d7a6396ae0a8c7d7f224f.zip
update
Diffstat (limited to 'script/vm')
-rw-r--r--script/vm/compiler.lua18
-rw-r--r--script/vm/infer.lua27
2 files changed, 38 insertions, 7 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index bdd228e0..f0735ad3 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -236,6 +236,20 @@ local function getReturn(func, index, args)
if func.special == 'setmetatable' then
return getReturnOfSetMetaTable(args)
end
+ if func.special == 'pcall' and index > 1 then
+ local newArgs = {}
+ for i = 2, #args do
+ newArgs[#newArgs+1] = args[i]
+ end
+ return getReturn(args[1], index - 1, newArgs)
+ end
+ if func.special == 'xpcall' and index > 1 then
+ local newArgs = {}
+ for i = 3, #args do
+ newArgs[#newArgs+1] = args[i]
+ end
+ return getReturn(args[1], index - 1, newArgs)
+ end
local node = m.compileNode(func)
---@type vm.node.union
local result
@@ -534,6 +548,10 @@ local compilerMap = util.switch()
nodeMgr.setNode(source, m.compileNode(typeUnit))
end
end)
+ : case 'doc.type.enum'
+ : call(function (source)
+ nodeMgr.setNode(source, source)
+ end)
: case 'doc.generic.name'
: call(function (source)
nodeMgr.setNode(source, source)
diff --git a/script/vm/infer.lua b/script/vm/infer.lua
index 90c10145..95a01658 100644
--- a/script/vm/infer.lua
+++ b/script/vm/infer.lua
@@ -12,16 +12,20 @@ local viewNodeMap = util.switch()
: case 'nil'
: case 'boolean'
: case 'string'
- : case 'table'
: case 'function'
- : case 'number'
: case 'integer'
: call(function (source, options)
- if source.type == 'number' then
- options['hasNumber'] = true
- end
return source.type
end)
+ : case 'number'
+ : call(function (source, options)
+ options['hasNumber'] = true
+ return source.type
+ end)
+ : case 'table'
+ : call(function (source, options)
+ options['hasTable'] = true
+ end)
: case 'global'
: call(function (source, options)
if source.cate == 'type' then
@@ -29,6 +33,15 @@ local viewNodeMap = util.switch()
return source.name
end
end)
+ : case 'doc.type.array'
+ : call(function (source, options)
+ options['hasClass'] = true
+ return m.viewType(source.node) .. '[]'
+ end)
+ : case 'doc.type.enum'
+ : call(function (source, options)
+ return source[1]
+ end)
: getMap()
---@param node vm.node
@@ -54,8 +67,8 @@ function m.viewType(source)
if options['hasNumber'] then
views['integer'] = nil
end
- if options['hasClass'] then
- views['table'] = nil
+ if options['hasTable'] and not options['hasClass'] then
+ views['table'] = true
end
local array = {}
for view in pairs(views) do