diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-11-06 22:58:11 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-11-06 22:58:11 +0800 |
commit | 9be846d86c494e08d376aa465e8269796176765a (patch) | |
tree | 04027cdb5ae6a118739a92911dbbd6797a39939f /script/vm/infer.lua | |
parent | dcca81c4fa7bd9b745123be8be0c8b07fcd6e29a (diff) | |
download | lua-language-server-9be846d86c494e08d376aa465e8269796176765a.zip |
type check: check the fields in table
resolve #1434
Diffstat (limited to 'script/vm/infer.lua')
-rw-r--r-- | script/vm/infer.lua | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/script/vm/infer.lua b/script/vm/infer.lua index 066f72e6..1e531c1e 100644 --- a/script/vm/infer.lua +++ b/script/vm/infer.lua @@ -108,6 +108,10 @@ local viewNodeSwitch;viewNodeSwitch = util.switch() end) : case 'doc.generic.name' : call(function (source, infer, uri) + local resolved = vm.getGenericResolved(source) + if resolved then + return vm.getInfer(resolved):view(uri) + end if source.generic and source.generic.extends then return ('<%s:%s>'):format(source[1], vm.getInfer(source.generic.extends):view(uri)) else @@ -519,3 +523,44 @@ end function vm.viewObject(source, uri) return viewNodeSwitch(source.type, source, {}, uri) end + +---@param source parser.object +---@param uri uri +---@return string? +---@return string|number|boolean|nil +function vm.viewKey(source, uri) + if source.type == 'doc.type' then + if #source == 1 then + return vm.viewKey(source[1], uri) + else + local key = vm.viewObject(source, uri) + return '[' .. key .. ']', key + end + end + if source.type == 'tableindex' then + local name = vm.getKeyName(source) + if not name then + return nil + end + local key = util.viewLiteral(name) + return ('[%s]'):format(key), name + end + if source.type == 'tableexp' then + return ('[%d]'):format(source.tindex), source.tindex + end + if source.type == 'doc.field' then + return vm.viewKey(source.field, uri) + end + if source.type == 'doc.type.field' then + return vm.viewKey(source.name, uri) + end + local key = vm.getKeyName(source) + if key == nil then + return nil + end + if type(key) == 'string' then + return key, key + else + return ('[%s]'):format(key), key + end +end |