diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-04-14 21:13:54 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-04-14 21:13:54 +0800 |
commit | 7df9f807faf27e3faea33842ed599963e00cdb0b (patch) | |
tree | 7fab4bda4680a994c5a46b4f695c5cd957411042 /script/vm/compiler.lua | |
parent | 9c084cd0bf6b83bb235a60dd2353b775c379ac6e (diff) | |
download | lua-language-server-7df9f807faf27e3faea33842ed599963e00cdb0b.zip |
cleanup
Diffstat (limited to 'script/vm/compiler.lua')
-rw-r--r-- | script/vm/compiler.lua | 58 |
1 files changed, 44 insertions, 14 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index 1b786cb8..531a0cd2 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -14,6 +14,7 @@ local vm = require 'vm.vm' ---@field _compiledNodes boolean ---@field _node vm.node ---@field _localBase table +---@field _globalBase table local searchFieldSwitch = util.switch() : case 'table' @@ -117,12 +118,22 @@ local searchFieldSwitch = util.switch() end local global = globalMgr.getGlobal('variable', node.name, key) if global then - pushResult(global) + for _, set in ipairs(global:getSets(suri)) do + pushResult(set) + end + for _, get in ipairs(global:getGets(suri)) do + pushResult(get) + end end else local globals = globalMgr.getFields('variable', node.name) for _, global in ipairs(globals) do - pushResult(global) + for _, set in ipairs(global:getSets(suri)) do + pushResult(set) + end + for _, get in ipairs(global:getGets(suri)) do + pushResult(get) + end end end end @@ -1545,38 +1556,57 @@ end ---@param source vm.object local function compileByGlobal(source) - local globalNode = source._globalNode - if not globalNode then + local global = source._globalNode + if not global then return end + local root = guide.getRoot(source) local uri = guide.getUri(source) - vm.setNode(source, globalNode) - if globalNode.cate == 'variable' then + if not root._globalBase then + root._globalBase = {} + end + local name = global:asKeyName() + if not root._globalBase[name] then + root._globalBase[name] = { + type = 'globalbase', + parent = root, + } + end + local globalNode = vm.getNode(root._globalBase[name]) + if globalNode then + vm.setNode(source, globalNode, true) + return + end + globalNode = vm.createNode(global) + vm.setNode(root._globalBase[name], globalNode, true) + vm.setNode(source, globalNode, true) + + if global.cate == 'variable' then local hasMarkDoc - for _, set in ipairs(globalNode:getSets(uri)) do + for _, set in ipairs(global:getSets(uri)) do if set.bindDocs then if bindDocs(set) then - vm.setNode(source, vm.compileNode(set)) + globalNode:merge(vm.compileNode(set)) hasMarkDoc = true end end end - for _, set in ipairs(globalNode:getSets(uri)) do + for _, set in ipairs(global:getSets(uri)) do if set.value then if not hasMarkDoc or guide.isLiteral(set.value) then - vm.setNode(source, vm.compileNode(set.value)) + globalNode:merge(vm.compileNode(set.value)) end end end end - if globalNode.cate == 'type' then - for _, set in ipairs(globalNode:getSets(uri)) do + if global.cate == 'type' then + for _, set in ipairs(global:getSets(uri)) do if set.type == 'doc.class' then if set.extends then for _, ext in ipairs(set.extends) do if ext.type == 'doc.type.table' then if not ext._generic then - vm.setNode(source, vm.compileNode(ext)) + globalNode:merge(vm.compileNode(ext)) end end end @@ -1584,7 +1614,7 @@ local function compileByGlobal(source) end if set.type == 'doc.alias' then if not set.extends._generic then - vm.setNode(source, vm.compileNode(set.extends)) + globalNode:merge(vm.compileNode(set.extends)) end end end |