diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-04-23 06:49:32 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-04-23 06:49:32 +0800 |
commit | 86557f99ac61fd23f6bb2184f8b9dfb94a76772e (patch) | |
tree | 4031107a835710a2fbf9fd052fb493b3c54f3e08 /script/vm/node.lua | |
parent | e8c06f25c2dc3a6a60e498449f29edc62020c0f9 (diff) | |
download | lua-language-server-86557f99ac61fd23f6bb2184f8b9dfb94a76772e.zip |
merge if results
Diffstat (limited to 'script/vm/node.lua')
-rw-r--r-- | script/vm/node.lua | 92 |
1 files changed, 67 insertions, 25 deletions
diff --git a/script/vm/node.lua b/script/vm/node.lua index b57fa80b..b759ed72 100644 --- a/script/vm/node.lua +++ b/script/vm/node.lua @@ -114,43 +114,86 @@ function mt:isNullable() end ---@return vm.node -function mt:copyTruly() - local newNode = vm.createNode() - newNode.optional = false - local hasBoolean, hasTrue - for _, c in ipairs(self) do +function mt:setTruly() + if self.optional == true then + self.optional = nil + end + local hasBoolean + local index = 0 + while true do + index = index + 1 + local c = self[index] + if not c then + break + end if c.type == 'nil' or (c.type == 'boolean' and c[1] == false) or (c.type == 'doc.type.boolean' and c[1] == false) then - goto CONTINUE + table.remove(self, index) + self[c] = nil + index = index - 1 end - if c.type == 'global' and c.cate == 'type' and c.name == 'boolean' then + if (c.type == 'global' and c.cate == 'type' and c.name == 'boolean') + or (c.type == 'boolean' or c.type == 'doc.type.boolean') then hasBoolean = true + table.remove(self, index) + self[c] = nil + index = index - 1 + end + end + if hasBoolean then + self[#self+1] = { + type = 'doc.type.boolean', + [1] = true, + } + end +end + +---@return vm.node +function mt:setFalsy() + if self.optional == false then + self.optional = nil + end + local hasBoolean + local index = 0 + while true do + index = index + 1 + local c = self[index] + if not c then + break + end + if c.type == 'nil' + or (c.type == 'boolean' and c[1] == true) + or (c.type == 'doc.type.boolean' and c[1] == true) then goto CONTINUE end - if c.type == 'boolean' or c.type == 'doc.type.boolean' then - hasTrue = true + if (c.type == 'global' and c.cate == 'type' and c.name == 'boolean') + or (c.type == 'boolean' or c.type == 'doc.type.boolean') then + hasBoolean = true + goto CONTINUE end - newNode:merge(c) + table.remove(self, index) + self[c] = nil + index = index - 1 ::CONTINUE:: end - if hasBoolean and not hasTrue then - newNode:merge { + if hasBoolean then + self[#self+1] = { type = 'doc.type.boolean', - [1] = true, + [1] = false, } end - return newNode end ---@param name string ----@return vm.node -function mt:copyWithout(name) - local newNode = vm.createNode() - if self:isOptional() then - newNode:addOptional() - end - for _, c in ipairs(self) do +function mt:remove(name) + local index = 0 + while true do + index = index + 1 + local c = self[index] + if not c then + break + end if (c.type == 'global' and c.cate == 'type' and c.name == name) or (c.type == name) or (c.type == 'doc.type.integer' and (name == 'number' or name == 'integer')) @@ -158,12 +201,11 @@ function mt:copyWithout(name) or (c.type == 'doc.type.table' and name == 'table') or (c.type == 'doc.type.array' and name == 'table') or (c.type == 'doc.type.function' and name == 'function') then - goto CONTINUE + table.remove(self, index) + self[c] = nil + index = index - 1 end - newNode:merge(c) - ::CONTINUE:: end - return newNode end ---@return fun():vm.object |