Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -5,6 +5,7 @@
* `FIX` cannot debug in Linux due to lua-debug expecting host process to have lua54 symbols available
* `NEW` support custom addons path for enhanced editor flexibility
* `FIX` support hex color codes with `#` in `textDocument/documentColor`
* `FIX` Prevent class methods from triggering missing-fields diagnostics
* `ADD` missing locale
* `FIX` updates the EmmyLuaCodeStyle submodule reference to a newer commit, ensuring compatibility with GCC 15

Expand Down
3 changes: 2 additions & 1 deletion 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,6 +70,7 @@ return function (uri, callback)

for _, field in ipairs(fields) do
if not field.optional
and field.type == "doc.field"
and not vm.compileNode(field):isNullable() then
local key = vm.getKeyName(field)
if not key then
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