Skip to content

Commit 119355c

Browse files
authored
Merge pull request #3182 from CWood-sdf/master
Prevent class methods from triggering missing fields diagnostics (Fixes #3175)
2 parents 837e2ea + 4ceb793 commit 119355c

File tree

3 files changed

+108
-15
lines changed

3 files changed

+108
-15
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* `FIX` cannot debug in Linux due to lua-debug expecting host process to have lua54 symbols available
66
* `NEW` support custom addons path for enhanced editor flexibility
77
* `FIX` support hex color codes with `#` in `textDocument/documentColor`
8+
* `FIX` Prevent class methods from triggering missing-fields diagnostics
89
* `ADD` missing locale
910
* `FIX` updates the EmmyLuaCodeStyle submodule reference to a newer commit, ensuring compatibility with GCC 15
1011

script/core/diagnostics/missing-fields.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ return function (uri, callback)
3131
local class = vm.getGlobal('type', className)
3232
---@cast class -nil
3333
for _, set in ipairs(class:getSets(uri)) do
34-
if set.type == 'doc.class'
34+
if set.type == 'doc.class'
3535
and vm.docHasAttr(set, 'partial')
3636
then
3737
sortedDefs[className].isPartial = true
@@ -70,6 +70,7 @@ return function (uri, callback)
7070

7171
for _, field in ipairs(fields) do
7272
if not field.optional
73+
and field.type == "doc.field"
7374
and not vm.compileNode(field):isNullable() then
7475
local key = vm.getKeyName(field)
7576
if not key then

test/diagnostics/missing-fields.lua

Lines changed: 105 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,97 @@ local t = {
5151
}
5252
]]
5353

54+
TEST [[
55+
---@diagnostic disable: unused-local
56+
---@class A
57+
---@field x number
58+
---@field y? number
59+
---@field z number
60+
local A = {}
61+
62+
function A:fun()
63+
end
64+
65+
---@type A
66+
local t = {
67+
x = 1,
68+
y = 2,
69+
z = 3,
70+
}
71+
]]
72+
73+
TEST [[
74+
---@diagnostic disable: unused-local
75+
76+
---@class Parent
77+
---@field a number
78+
local Parent = {}
79+
80+
function Parent:fun2()
81+
end
82+
83+
---@class A : Parent
84+
---@field x number
85+
---@field y? number
86+
---@field z number
87+
local A = {}
88+
89+
function A:fun()
90+
end
91+
92+
---@type A
93+
local t = <!{
94+
x = 1,
95+
y = 2,
96+
}!>
97+
]]
98+
99+
TEST [[
100+
---@diagnostic disable: unused-local
101+
102+
---@class Parent
103+
---@field a number
104+
local Parent = {}
105+
106+
function Parent:fun2()
107+
end
108+
109+
---@class A : Parent
110+
---@field x number
111+
---@field y? number
112+
---@field z number
113+
local A = {}
114+
115+
function A:fun()
116+
end
117+
118+
---@type A
119+
local t = {
120+
x = 1,
121+
y = 2,
122+
z = 3,
123+
a = 1,
124+
}
125+
]]
126+
127+
TEST [[
128+
---@diagnostic disable: unused-local
129+
---@class A
130+
---@field x number
131+
---@field y? number
132+
---@field z number
133+
local A = {}
134+
135+
function A:fun()
136+
end
137+
138+
---@type A
139+
local t = <!{
140+
x = 1,
141+
y = 2,
142+
}!>
143+
]]
144+
54145
TEST [[
55146
---@diagnostic disable: unused-local
56147
---@class A
@@ -336,7 +427,7 @@ local x = <!{
336427
}!>
337428
]]
338429

339-
TEST[[
430+
TEST [[
340431
---@class A
341432
---@field [1] string
342433
---@field x number
@@ -345,7 +436,7 @@ TEST[[
345436
local t = {x = 1, ""}
346437
]]
347438

348-
TEST[[
439+
TEST [[
349440
---@class A
350441
---@field [1] string
351442
---@field x number
@@ -356,7 +447,7 @@ local t = <!{x = 1}!>
356447

357448
-- Inheritance
358449

359-
TEST[[
450+
TEST [[
360451
---@class A
361452
---@field x number
362453
@@ -366,7 +457,7 @@ TEST[[
366457
local t = <!{}!>
367458
]]
368459

369-
TEST[[
460+
TEST [[
370461
---@class A
371462
---@field x number
372463
---@field y number
@@ -377,7 +468,7 @@ TEST[[
377468
local t = <!{y = 1}!>
378469
]]
379470

380-
TEST[[
471+
TEST [[
381472
---@class A
382473
---@field x number
383474
@@ -390,7 +481,7 @@ local t = <!{y = 1}!>
390481

391482
-- Inheritance + optional
392483

393-
TEST[[
484+
TEST [[
394485
---@class A
395486
---@field x? number
396487
@@ -400,7 +491,7 @@ TEST[[
400491
local t = {}
401492
]]
402493

403-
TEST[[
494+
TEST [[
404495
---@class A
405496
---@field x? number
406497
---@field y number
@@ -411,7 +502,7 @@ TEST[[
411502
local t = {y = 1}
412503
]]
413504

414-
TEST[[
505+
TEST [[
415506
---@class A
416507
---@field x? number
417508
@@ -424,7 +515,7 @@ local t = {y = 1}
424515

425516
-- Inheritance + function call
426517

427-
TEST[[
518+
TEST [[
428519
---@class A
429520
---@field x number
430521
@@ -436,7 +527,7 @@ local function f(b) end
436527
f <!{}!>
437528
]]
438529

439-
TEST[[
530+
TEST [[
440531
---@class A
441532
---@field x number
442533
---@field y number
@@ -449,7 +540,7 @@ local function f(b) end
449540
f <!{y = 1}!>
450541
]]
451542

452-
TEST[[
543+
TEST [[
453544
---@class A
454545
---@field x number
455546
@@ -464,7 +555,7 @@ f <!{y = 1}!>
464555

465556
-- partial class
466557

467-
TEST[[
558+
TEST [[
468559
---@class A
469560
---@field x number
470561
@@ -474,7 +565,7 @@ TEST[[
474565
local t = {}
475566
]]
476567

477-
TEST[[
568+
TEST [[
478569
---@class A
479570
---@field x number
480571
@@ -485,7 +576,7 @@ TEST[[
485576
local t = <!{}!>
486577
]]
487578

488-
TEST[[
579+
TEST [[
489580
---@class A
490581
---@field x number
491582

0 commit comments

Comments
 (0)