Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<!-- Add all new changes here. They will be moved under a version at release -->
* `FIX` cannot debug in Linux due to lua-debug expecting host process to have lua54 symbols available
* `FIX` support hex color codes with `#` in `textDocument/documentColor`
* `FIX` Prevent class methods from triggering missing-fields diagnostics

## 3.14.0
`2025-4-7`
Expand Down
5 changes: 3 additions & 2 deletions script/core/diagnostics/missing-fields.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ return function (uri, callback)
local class = vm.getGlobal('type', className)
---@cast class -nil
for _, set in ipairs(class:getSets(uri)) do
if set.type == 'doc.class'
if set.type == 'doc.class'
and vm.docHasAttr(set, 'partial')
then
sortedDefs[className].isPartial = true
Expand Down Expand Up @@ -70,7 +70,8 @@ return function (uri, callback)

for _, field in ipairs(fields) do
if not field.optional
and not vm.compileNode(field):isNullable() then
and not vm.compileNode(field):isNullable()
and field.type == "doc.field" then
local key = vm.getKeyName(field)
if not key then
local fieldnode = vm.compileNode(field.field)[1]
Expand Down
119 changes: 105 additions & 14 deletions test/diagnostics/missing-fields.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,97 @@ local t = {
}
]]

TEST [[
---@diagnostic disable: unused-local
---@class A
---@field x number
---@field y? number
---@field z number
local A = {}

function A:fun()
end

---@type A
local t = {
x = 1,
y = 2,
z = 3,
}
]]

TEST [[
---@diagnostic disable: unused-local

---@class Parent
---@field a number
local Parent = {}

function Parent:fun2()
end

---@class A : Parent
---@field x number
---@field y? number
---@field z number
local A = {}

function A:fun()
end

---@type A
local t = <!{
x = 1,
y = 2,
}!>
]]

TEST [[
---@diagnostic disable: unused-local

---@class Parent
---@field a number
local Parent = {}

function Parent:fun2()
end

---@class A : Parent
---@field x number
---@field y? number
---@field z number
local A = {}

function A:fun()
end

---@type A
local t = {
x = 1,
y = 2,
z = 3,
a = 1,
}
]]

TEST [[
---@diagnostic disable: unused-local
---@class A
---@field x number
---@field y? number
---@field z number
local A = {}

function A:fun()
end

---@type A
local t = <!{
x = 1,
y = 2,
}!>
]]

TEST [[
---@diagnostic disable: unused-local
---@class A
Expand Down Expand Up @@ -336,7 +427,7 @@ local x = <!{
}!>
]]

TEST[[
TEST [[
---@class A
---@field [1] string
---@field x number
Expand All @@ -345,7 +436,7 @@ TEST[[
local t = {x = 1, ""}
]]

TEST[[
TEST [[
---@class A
---@field [1] string
---@field x number
Expand All @@ -356,7 +447,7 @@ local t = <!{x = 1}!>

-- Inheritance

TEST[[
TEST [[
---@class A
---@field x number

Expand All @@ -366,7 +457,7 @@ TEST[[
local t = <!{}!>
]]

TEST[[
TEST [[
---@class A
---@field x number
---@field y number
Expand All @@ -377,7 +468,7 @@ TEST[[
local t = <!{y = 1}!>
]]

TEST[[
TEST [[
---@class A
---@field x number

Expand All @@ -390,7 +481,7 @@ local t = <!{y = 1}!>

-- Inheritance + optional

TEST[[
TEST [[
---@class A
---@field x? number

Expand All @@ -400,7 +491,7 @@ TEST[[
local t = {}
]]

TEST[[
TEST [[
---@class A
---@field x? number
---@field y number
Expand All @@ -411,7 +502,7 @@ TEST[[
local t = {y = 1}
]]

TEST[[
TEST [[
---@class A
---@field x? number

Expand All @@ -424,7 +515,7 @@ local t = {y = 1}

-- Inheritance + function call

TEST[[
TEST [[
---@class A
---@field x number

Expand All @@ -436,7 +527,7 @@ local function f(b) end
f <!{}!>
]]

TEST[[
TEST [[
---@class A
---@field x number
---@field y number
Expand All @@ -449,7 +540,7 @@ local function f(b) end
f <!{y = 1}!>
]]

TEST[[
TEST [[
---@class A
---@field x number

Expand All @@ -464,7 +555,7 @@ f <!{y = 1}!>

-- partial class

TEST[[
TEST [[
---@class A
---@field x number

Expand All @@ -474,7 +565,7 @@ TEST[[
local t = {}
]]

TEST[[
TEST [[
---@class A
---@field x number

Expand All @@ -485,7 +576,7 @@ TEST[[
local t = <!{}!>
]]

TEST[[
TEST [[
---@class A
---@field x number

Expand Down
Loading