diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-04-13 02:47:34 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-04-13 02:47:34 +0800 |
commit | 7fdc3519e62f00f236956d272295b241d4bfa762 (patch) | |
tree | d3a1fc449350ea641ad23a229138a97cbe0fe825 /script/vm/node.lua | |
parent | f760dc359b389c20a0d48bef463d14800e67894c (diff) | |
download | lua-language-server-7fdc3519e62f00f236956d272295b241d4bfa762.zip |
cleanup
Diffstat (limited to 'script/vm/node.lua')
-rw-r--r-- | script/vm/node.lua | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/script/vm/node.lua b/script/vm/node.lua index 409841fc..eb1ee69d 100644 --- a/script/vm/node.lua +++ b/script/vm/node.lua @@ -1,14 +1,15 @@ local union = require 'vm.union' local files = require 'files' ----@alias vm.node parser.object | vm.node.union | vm.node.global | vm.generic +---@alias vm.node vm.node.union +---@alias vm.object parser.object | vm.global | vm.generic ---@class vm.node-manager local m = {} local DUMMY_FUNCTION = function () end ----@type table<parser.object, vm.node> +---@type table<vm.object, vm.node> m.nodeCache = {} ---@param a vm.node @@ -23,7 +24,7 @@ function m.mergeNode(a, b) return union(a, b) end ----@param source parser.object +---@param source vm.object ---@param node vm.node ---@param cover? boolean function m.setNode(source, node, cover) @@ -36,21 +37,23 @@ function m.setNode(source, node, cover) end local me = m.nodeCache[source] if not me then - m.nodeCache[source] = node - return - end - if me == node then + if node.type == 'union' then + m.nodeCache[source] = node + else + m.nodeCache[source] = union(node) + end return end - m.nodeCache[source] = m.mergeNode(me, node) + m.nodeCache[source] = union(me, node) end +---@return vm.node? function m.getNode(source) return m.nodeCache[source] end ----@param node vm.node ----@return vm.node.union +---@param node vm.node? +---@return vm.node function m.addOptional(node) if not node or node.type ~= 'union' then node = union(node) @@ -59,7 +62,7 @@ function m.addOptional(node) return node end ----@param node vm.node +---@param node vm.node? ---@return vm.node.union? function m.removeOptional(node) if not node then @@ -72,8 +75,8 @@ function m.removeOptional(node) return node end ----@return fun():vm.node -function m.eachNode(node) +---@return fun():vm.object +function m.eachObject(node) if not node then return DUMMY_FUNCTION end |