diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2023-01-13 16:28:54 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2023-01-13 16:28:54 +0800 |
commit | a3b5dcb6403bbcdd87e021f83e79c46796f68ce8 (patch) | |
tree | 51571a0dbcf4449abf9145311f4cb1da2477a13f /script/vm | |
parent | 6c92b9a7cc10971e4ec6402fe9c23b1839c58c80 (diff) | |
download | lua-language-server-a3b5dcb6403bbcdd87e021f83e79c46796f68ce8.zip |
fix
Diffstat (limited to 'script/vm')
-rw-r--r-- | script/vm/compiler.lua | 28 | ||||
-rw-r--r-- | script/vm/global.lua | 44 |
2 files changed, 31 insertions, 41 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index 18b2905e..a2c5c228 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -9,7 +9,6 @@ local vm = require 'vm.vm' ---@class parser.object ---@field _compiledNodes boolean ---@field _node vm.node ----@field package _hasBindedDocs? boolean ---@field cindex integer ---@field func parser.object @@ -21,20 +20,14 @@ function vm.bindDocs(source) if not docs then return false end - if source._hasBindedDocs ~= nil then - return source._hasBindedDocs - end - source._hasBindedDocs = false for i = #docs, 1, -1 do local doc = docs[i] if doc.type == 'doc.type' then vm.setNode(source, vm.compileNode(doc)) - source._hasBindedDocs = true return true end if doc.type == 'doc.class' then vm.setNode(source, vm.compileNode(doc)) - source._hasBindedDocs = true return true end if doc.type == 'doc.param' then @@ -43,28 +36,23 @@ function vm.bindDocs(source) node:addOptional() end vm.setNode(source, node) - source._hasBindedDocs = true return true end if doc.type == 'doc.module' then local name = doc.module if not name then - source._hasBindedDocs = true return true end local uri = rpath.findUrisByRequireName(guide.getUri(source), name)[1] if not uri then - source._hasBindedDocs = true return true end local state = files.getState(uri) local ast = state and state.ast if not ast then - source._hasBindedDocs = true return true end vm.setNode(source, vm.compileNode(ast)) - source._hasBindedDocs = true return true end end @@ -594,7 +582,7 @@ end ---@param source parser.object ---@return boolean -local function bindAs(source) +function vm.bindAs(source) local root = guide.getRoot(source) local docs = root.docs if not docs then @@ -1195,7 +1183,7 @@ local compilerSwitch = util.switch() end) : case 'paren' : call(function (source) - if bindAs(source) then + if vm.bindAs(source) then return end if source.exp then @@ -1232,7 +1220,7 @@ local compilerSwitch = util.switch() : case 'getlocal' ---@async : call(function (source) - if bindAs(source) then + if vm.bindAs(source) then return end local node = vm.traceNode(source) @@ -1251,7 +1239,7 @@ local compilerSwitch = util.switch() if vm.bindDocs(source) then return end - if guide.isGet(source) and bindAs(source) then + if guide.isGet(source) and vm.bindAs(source) then return end ---@type (string|vm.node)? @@ -1300,7 +1288,7 @@ local compilerSwitch = util.switch() end) : case 'getglobal' : call(function (source) - if bindAs(source) then + if vm.bindAs(source) then return end if source.node[1] ~= '_ENV' then @@ -1441,7 +1429,7 @@ local compilerSwitch = util.switch() : case 'call.return' ---@param source parser.object : call(function (source) - if bindAs(source) then + if vm.bindAs(source) then return end local func = source.func @@ -1725,7 +1713,7 @@ local compilerSwitch = util.switch() end) : case 'unary' : call(function (source) - if bindAs(source) then + if vm.bindAs(source) then return end if not source[1] then @@ -1735,7 +1723,7 @@ local compilerSwitch = util.switch() end) : case 'binary' : call(function (source) - if bindAs(source) then + if vm.bindAs(source) then return end if not source[1] or not source[2] then diff --git a/script/vm/global.lua b/script/vm/global.lua index 0a90829a..19474bb5 100644 --- a/script/vm/global.lua +++ b/script/vm/global.lua @@ -546,31 +546,33 @@ function vm.compileByGlobal(source) if not global then return false end - if global.cate == 'type' then - vm.setNode(source, global) - return false - end vm.setNode(source, global) - if guide.isAssign(source) then - if vm.bindDocs(source) then - return true - end - if source.value then - vm.setNode(source, vm.compileNode(source.value)) + if global.cate == 'variable' then + if guide.isAssign(source) then + if vm.bindDocs(source) then + return true + end + if source.value then + vm.setNode(source, vm.compileNode(source.value)) + return true + end + else + if vm.bindAs(source) then + return true + end + local node = vm.traceNode(source) + if node then + vm.setNode(source, node, true) + return true + end end - return true end - local node = vm.traceNode(source) - if node then - vm.setNode(source, node, true) - else - local globalBase = vm.getGlobalBase(source) - if not globalBase then - return false - end - local globalNode = vm.compileNode(globalBase) - vm.setNode(source, globalNode, true) + local globalBase = vm.getGlobalBase(source) + if not globalBase then + return false end + local globalNode = vm.compileNode(globalBase) + vm.setNode(source, globalNode, true) return true end |