Skip to content

Commit cb16010

Browse files
committed
fix wrong missing-fields with union types
fix #2252
1 parent a5c3b64 commit cb16010

File tree

7 files changed

+43
-9
lines changed

7 files changed

+43
-9
lines changed

changelog.md

+2
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@
2525
* `FIX` wrong hover and signature for method with varargs and overloads
2626
* `FIX` [#2155]
2727
* `FIX` [#2224]
28+
* `FIX` [#2252]
2829
* `FIX` [#2267]
2930

3031
[#2155]: https://github.com/LuaLS/lua-language-server/issues/2155
3132
[#2224]: https://github.com/LuaLS/lua-language-server/issues/2224
33+
[#2252]: https://github.com/LuaLS/lua-language-server/issues/2252
3234
[#2267]: https://github.com/LuaLS/lua-language-server/issues/2267
3335

3436
## 3.6.25

locale/en-us/script.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ DIAG_INVISIBLE_PACKAGE =
169169
DIAG_GLOBAL_ELEMENT =
170170
'Element is global.'
171171
DIAG_MISSING_FIELDS =
172-
'Missing fields: {}'
172+
'Missing required fields in type `{1}`: {2}'
173173
DIAG_INJECT_FIELD =
174174
'Fields cannot be injected into the reference of `{class}` for `{field}`. {fix}'
175175
DIAG_INJECT_FIELD_FIX_CLASS =

locale/pt-br/script.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ DIAG_INVISIBLE_PACKAGE = -- TODO: need translate!
169169
DIAG_GLOBAL_ELEMENT = -- TODO: need translate!
170170
'Element is global.'
171171
DIAG_MISSING_FIELDS = -- TODO: need translate!
172-
'Missing fields: {}'
172+
'Missing required fields in type `{1}`: {2}'
173173
DIAG_INJECT_FIELD = -- TODO: need translate!
174174
'Fields cannot be injected into the reference of `{class}` for `{field}`. {fix}'
175175
DIAG_INJECT_FIELD_FIX_CLASS = -- TODO: need translate!

locale/zh-cn/script.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ DIAG_INVISIBLE_PACKAGE =
169169
DIAG_GLOBAL_ELEMENT =
170170
'全局变量。'
171171
DIAG_MISSING_FIELDS =
172-
'缺少字段: {}'
172+
'缺少类型 `{1}` 的必要字段: {2}'
173173
DIAG_INJECT_FIELD =
174174
'不能在 `{class}` 的引用中注入字段 `{field}` 。{fix}'
175175
DIAG_INJECT_FIELD_FIX_CLASS =

locale/zh-tw/script.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ DIAG_INVISIBLE_PACKAGE = -- TODO: need translate!
169169
DIAG_GLOBAL_ELEMENT = -- TODO: need translate!
170170
'Element is global.'
171171
DIAG_MISSING_FIELDS = -- TODO: need translate!
172-
'Missing fields: {}'
172+
'Missing required fields in type `{1}`: {2}'
173173
DIAG_INJECT_FIELD = -- TODO: need translate!
174174
'Fields cannot be injected into the reference of `{class}` for `{field}`. {fix}'
175175
DIAG_INJECT_FIELD_FIX_CLASS = -- TODO: need translate!

script/core/diagnostics/missing-fields.lua

+11-5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ return function (uri, callback)
2727
return
2828
end
2929
end
30+
local warnings = {}
3031
for _, def in ipairs(defs) do
3132
if def.type == 'doc.class' then
3233
if not def.fields then
@@ -67,12 +68,17 @@ return function (uri, callback)
6768
return
6869
end
6970

70-
callback {
71-
start = src.start,
72-
finish = src.finish,
73-
message = lang.script('DIAG_MISSING_FIELDS', table.concat(missedKeys, ', ')),
74-
}
71+
warnings[#warnings+1] = lang.script('DIAG_MISSING_FIELDS', def.class[1], table.concat(missedKeys, ', '))
7572
end
7673
end
74+
75+
if #warnings == 0 then
76+
return
77+
end
78+
callback {
79+
start = src.start,
80+
finish = src.finish,
81+
message = table.concat(warnings, '\n')
82+
}
7783
end)
7884
end

test/diagnostics/missing-fields.lua

+26
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,29 @@ TEST [[
205205
---@type A
206206
return <!{}!>
207207
]]
208+
209+
TEST [[
210+
---@class A
211+
---@field x number
212+
213+
---@class B
214+
---@field y number
215+
216+
---@type A|B
217+
local t = <!{
218+
z = 1,
219+
}!>
220+
]]
221+
222+
TEST [[
223+
---@class A
224+
---@field x number
225+
226+
---@class B
227+
---@field y number
228+
229+
---@type A|B
230+
local t = {
231+
y = 1,
232+
}
233+
]]

0 commit comments

Comments
 (0)