diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-06-23 02:45:02 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-06-23 02:45:02 +0800 |
commit | 0ff98557a45c25d7a49520e57f49561a62300f35 (patch) | |
tree | 41d19002f9051f6d48613271d0edcfe712ae3ea3 /script/vm | |
parent | e0e3c9ab6b69b16b8949f93f309461f298038fa4 (diff) | |
download | lua-language-server-0ff98557a45c25d7a49520e57f49561a62300f35.zip |
update
Diffstat (limited to 'script/vm')
-rw-r--r-- | script/vm/compiler.lua | 10 | ||||
-rw-r--r-- | script/vm/node.lua | 19 |
2 files changed, 24 insertions, 5 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index 5ebf624c..27ba6273 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -1383,13 +1383,13 @@ local compilerSwitch = util.switch() local uri = guide.getUri(source) local value = vm.getTableValue(uri, vm.compileNode(source.node), key) if value then - vm.setNode(source, value) + vm.setNode(source, value):removeOptional() end else vm.compileByParentNode(source.node, key, false, function (src) vm.setNode(source, vm.compileNode(src)) if src.value then - vm.setNode(source, vm.compileNode(src.value)) + vm.setNode(source, vm.compileNode(src.value)):removeOptional() end end) end @@ -1403,7 +1403,7 @@ local compilerSwitch = util.switch() vm.compileByParentNode(source.node, key, false, function (src) if src.type == 'doc.type.field' or src.type == 'doc.field' then - vm.setNode(source, vm.compileNode(src)) + vm.setNode(source, vm.compileNode(src)):removeOptional() end end) end) @@ -1433,13 +1433,13 @@ local compilerSwitch = util.switch() if src.type == 'doc.field' or src.type == 'doc.type.field' then hasMarkDoc = true - vm.setNode(source, vm.compileNode(src)) + vm.setNode(source, vm.compileNode(src)):removeOptional() end end) end if not hasMarkDoc and source.value then - vm.setNode(source, vm.compileNode(source.value)) + vm.setNode(source, vm.compileNode(source.value)):removeOptional() end end) diff --git a/script/vm/node.lua b/script/vm/node.lua index 8ed5c027..65a203f8 100644 --- a/script/vm/node.lua +++ b/script/vm/node.lua @@ -81,6 +81,7 @@ end function mt:removeOptional() self:remove 'nil' + return self end ---@return boolean @@ -293,6 +294,24 @@ function mt:hasType(name) return false end +---@param name string +---@return boolean +function mt:hasName(name) + if name == 'nil' and self.optional == true then + return true + end + for _, c in ipairs(self) do + if c.type == 'global' and c.cate == 'type' and c.name == name then + return true + end + if c.type == name then + return true + end + -- TODO + end + return false +end + ---@return fun():vm.object function mt:eachObject() local i = 0 |