Skip to content

Commit

Permalink
fix missing-fields
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Jul 21, 2023
1 parent 7c63635 commit f074686
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
6 changes: 4 additions & 2 deletions script/core/diagnostics/missing-fields.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ return function (uri, callback)

local defs = vm.getDefs(src)
local requiresKeys = {}
local isClass = false
for _, def in ipairs(defs) do
if def.type == 'doc.class' then
if not def.fields then
goto continue
end
if def.bindSource then
if guide.isInRange(def.bindSource, src.start) then
goto continue
isClass = true
break
end
end
for _, field in ipairs(def.fields) do
Expand All @@ -41,7 +43,7 @@ return function (uri, callback)
::continue::
end

if #requiresKeys == 0 then
if #requiresKeys == 0 or isClass then
return
end

Expand Down
17 changes: 17 additions & 0 deletions test/diagnostics/common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2414,3 +2414,20 @@ f {
z = 3,
}
]]

TEST [[
---@diagnostic disable: unused-local
---@class A
---@field x number
local t = {}
]]

TEST [[
---@diagnostic disable: unused-local
---@class A
---@field x number
---@class A
local t = {}
]]

0 comments on commit f074686

Please sign in to comment.