diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-06-20 23:26:07 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-06-20 23:26:07 +0800 |
commit | 7221cc92acd0099ed28727536c30d264b3cb7bcc (patch) | |
tree | 248793ddd9f92730c1cf4ecc897c3d8100571c65 | |
parent | 4084590d028ba9b57cbdc82591ba52e895d1271e (diff) | |
download | lua-language-server-7221cc92acd0099ed28727536c30d264b3cb7bcc.zip |
resolve #1211
-rw-r--r-- | script/vm/compiler.lua | 31 | ||||
-rw-r--r-- | test/diagnostics/type-check.lua | 9 |
2 files changed, 28 insertions, 12 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index 165dc6fb..fade0a78 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -306,7 +306,7 @@ function vm.getClassFields(suri, object, key, ref, pushResult) if vm.isSubType(suri, typeName, fieldNode) then local nkey = '|' .. typeName if not searchedFields[nkey] then - pushResult(field) + pushResult(field, true) hasFounded[nkey] = true end end @@ -317,16 +317,7 @@ function vm.getClassFields(suri, object, key, ref, pushResult) -- check local field and global field if not hasFounded[key] and set.bindSources then for _, src in ipairs(set.bindSources) do - searchFieldSwitch(src.type, suri, src, key, ref, function (field) - local fieldKey = guide.getKeyName(field) - if fieldKey then - if not searchedFields[fieldKey] - and guide.isSet(field) then - hasFounded[fieldKey] = true - pushResult(field) - end - end - end) + local skipSetLocal if src.value and src.value.type == 'table' then searchFieldSwitch('table', suri, src.value, key, ref, function (field) local fieldKey = guide.getKeyName(field) @@ -334,7 +325,22 @@ function vm.getClassFields(suri, object, key, ref, pushResult) if not searchedFields[fieldKey] and guide.isSet(field) then hasFounded[fieldKey] = true - pushResult(field) + pushResult(field, true) + if src.type == 'local' then + skipSetLocal = true + end + end + end + end) + end + if not skipSetLocal then + searchFieldSwitch(src.type, suri, src, key, ref, function (field) + local fieldKey = guide.getKeyName(field) + if fieldKey then + if not searchedFields[fieldKey] + and guide.isSet(field) then + hasFounded[fieldKey] = true + pushResult(field, true) end end end) @@ -647,6 +653,7 @@ function vm.compileByParentNode(source, key, ref, pushResult) and node.cate == 'type' and not guide.isBasicType(node.name) then hasClass = true + break end end for node in parentNode:eachObject() do diff --git a/test/diagnostics/type-check.lua b/test/diagnostics/type-check.lua index ace503ad..9dda3333 100644 --- a/test/diagnostics/type-check.lua +++ b/test/diagnostics/type-check.lua @@ -274,5 +274,14 @@ local t = { true } t[1] = nil ]] +TEST [[ +---@class A +local t = { + x = 1 +} + +<!t.x!> = true +]] + config.remove(nil, 'Lua.diagnostics.disable', 'unused-local') config.remove(nil, 'Lua.diagnostics.disable', 'undefined-global') |