diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-04-05 03:16:46 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-04-05 03:16:46 +0800 |
commit | 3f56e35738ecc1d8765dfb6fc89522c1a8481095 (patch) | |
tree | e9f53349eddfbffc8e51eed908cc3b4cb669d499 /script/vm | |
parent | 4d4efe71baae4c505153c40ed1a1bcbe40c1745b (diff) | |
download | lua-language-server-3f56e35738ecc1d8765dfb6fc89522c1a8481095.zip |
update
Diffstat (limited to 'script/vm')
-rw-r--r-- | script/vm/compiler.lua | 28 | ||||
-rw-r--r-- | script/vm/infer.lua | 11 |
2 files changed, 37 insertions, 2 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index b496d9cc..31713f36 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -20,17 +20,29 @@ local m = {} local searchFieldSwitch = util.switch() : case 'table' : call(function (node, key, pushResult) + local hasFiled = false for _, field in ipairs(node) do if field.type == 'tablefield' or field.type == 'tableindex' then if not key or key == guide.getKeyName(field) then + hasFiled = true pushResult(field) end end if field.type == 'tableexp' then if not key or key == field.tindex then + hasFiled = true + pushResult(field) + end + end + if field.type == 'varargs' then + if not hasFiled + and key + and key >= 1 + and math.tointeger(key) then + hasFiled = true pushResult(field) end end @@ -432,8 +444,6 @@ local function selectNode(source, list, index) local result if exp.type == 'call' then result = getReturn(exp.node, index, exp.args) - elseif exp.type == '...' then - -- TODO else result = m.compileNode(exp) end @@ -748,6 +758,13 @@ local compilerSwitch = util.switch() local node = getReturn(vararg.node, source.sindex, vararg.args) nodeMgr.setNode(source, node) end + if vararg.type == 'varargs' then + nodeMgr.setNode(source, m.compileNode(vararg)) + end + end) + : case 'varargs' + : call(function (source) + nodeMgr.setNode(source, m.compileNode(source.node)) end) : case 'call' : call(function (source) @@ -872,6 +889,10 @@ local compilerSwitch = util.switch() nodeMgr.setNode(source, globalMgr.getGlobal('type', 'any')) end end) + : case 'generic' + : call(function (source) + nodeMgr.setNode(source, source) + end) : case 'unary' : call(function (source) local valueMgr = require 'vm.value' @@ -1295,6 +1316,9 @@ end ---@param source parser.object ---@return vm.node function m.compileNode(source) + if not source then + return false + end if nodeMgr.nodeCache[source] ~= nil then return nodeMgr.nodeCache[source] end diff --git a/script/vm/infer.lua b/script/vm/infer.lua index 1b0ff800..bf6df2fb 100644 --- a/script/vm/infer.lua +++ b/script/vm/infer.lua @@ -50,6 +50,13 @@ local viewNodeSwitch = util.switch() end) : case 'table' : call(function (source, infer) + if source.type == 'table' then + if #source == 1 and source[1].type == 'varargs' then + local node = m.getInfer(source[1]):view() + return ('%s[]'):format(node) + end + end + infer._hasTable = true end) : case 'function' @@ -92,6 +99,10 @@ local viewNodeSwitch = util.switch() return source[1] end end) + : case 'generic' + : call(function (source, infer) + return ('<%s>'):format(source.proto[1]) + end) : case 'doc.generic.name' : call(function (source, infer) return ('<%s>'):format(source[1]) |