diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-06-15 17:40:43 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-06-15 17:40:43 +0800 |
commit | b22505b90c6df5fadfcad08bee82ec2f6d91bbaa (patch) | |
tree | cb45d1189a2b87d11f98d05ae22d51b45ce388a5 /script/vm/node.lua | |
parent | e6b82117616e5d055399aa1568fee90a99ba8d64 (diff) | |
download | lua-language-server-b22505b90c6df5fadfcad08bee82ec2f6d91bbaa.zip |
resolve #1105 infer type by `type(x)`
Diffstat (limited to 'script/vm/node.lua')
-rw-r--r-- | script/vm/node.lua | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/script/vm/node.lua b/script/vm/node.lua index 5086f66d..1b3ea45c 100644 --- a/script/vm/node.lua +++ b/script/vm/node.lua @@ -224,6 +224,32 @@ function mt:remove(name) return self end +---@param name string +function mt:narrow(name) + if name ~= 'nil' and self.optional == true then + self.optional = nil + end + for index = #self, 1, -1 do + local c = self[index] + 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')) + or (c.type == 'doc.type.boolean' and name == 'boolean') + 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 + end + table.remove(self, index) + self[c] = nil + ::CONTINUE:: + end + if #self == 0 then + self[#self+1] = vm.getGlobal('type', name) + end + return self +end + ---@param node vm.node function mt:removeNode(node) for _, c in ipairs(node) do |