diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2023-08-22 17:08:39 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2023-08-22 17:08:39 +0800 |
commit | cb16010fbb4128e2a5a31013e02b8cc4a4318be8 (patch) | |
tree | 0be2ac73f9bf987ea33fc070201d1eb238839dc3 | |
parent | a5c3b64c217fb2691a23ca3b849567474b653ddf (diff) | |
download | lua-language-server-cb16010fbb4128e2a5a31013e02b8cc4a4318be8.zip |
fix wrong `missing-fields` with union types
fix #2252
-rw-r--r-- | changelog.md | 2 | ||||
-rw-r--r-- | locale/en-us/script.lua | 2 | ||||
-rw-r--r-- | locale/pt-br/script.lua | 2 | ||||
-rw-r--r-- | locale/zh-cn/script.lua | 2 | ||||
-rw-r--r-- | locale/zh-tw/script.lua | 2 | ||||
-rw-r--r-- | script/core/diagnostics/missing-fields.lua | 16 | ||||
-rw-r--r-- | test/diagnostics/missing-fields.lua | 26 |
7 files changed, 43 insertions, 9 deletions
diff --git a/changelog.md b/changelog.md index 1c5b53f2..a105d276 100644 --- a/changelog.md +++ b/changelog.md @@ -25,10 +25,12 @@ * `FIX` wrong hover and signature for method with varargs and overloads * `FIX` [#2155] * `FIX` [#2224] +* `FIX` [#2252] * `FIX` [#2267] [#2155]: https://github.com/LuaLS/lua-language-server/issues/2155 [#2224]: https://github.com/LuaLS/lua-language-server/issues/2224 +[#2252]: https://github.com/LuaLS/lua-language-server/issues/2252 [#2267]: https://github.com/LuaLS/lua-language-server/issues/2267 ## 3.6.25 diff --git a/locale/en-us/script.lua b/locale/en-us/script.lua index 202d98d7..56e5fd87 100644 --- a/locale/en-us/script.lua +++ b/locale/en-us/script.lua @@ -169,7 +169,7 @@ DIAG_INVISIBLE_PACKAGE = DIAG_GLOBAL_ELEMENT = 'Element is global.' DIAG_MISSING_FIELDS = -'Missing fields: {}' +'Missing required fields in type `{1}`: {2}' DIAG_INJECT_FIELD = 'Fields cannot be injected into the reference of `{class}` for `{field}`. {fix}' DIAG_INJECT_FIELD_FIX_CLASS = diff --git a/locale/pt-br/script.lua b/locale/pt-br/script.lua index 05730d56..2357aa50 100644 --- a/locale/pt-br/script.lua +++ b/locale/pt-br/script.lua @@ -169,7 +169,7 @@ DIAG_INVISIBLE_PACKAGE = -- TODO: need translate! DIAG_GLOBAL_ELEMENT = -- TODO: need translate! 'Element is global.' DIAG_MISSING_FIELDS = -- TODO: need translate! -'Missing fields: {}' +'Missing required fields in type `{1}`: {2}' DIAG_INJECT_FIELD = -- TODO: need translate! 'Fields cannot be injected into the reference of `{class}` for `{field}`. {fix}' DIAG_INJECT_FIELD_FIX_CLASS = -- TODO: need translate! diff --git a/locale/zh-cn/script.lua b/locale/zh-cn/script.lua index b59411a9..6459a104 100644 --- a/locale/zh-cn/script.lua +++ b/locale/zh-cn/script.lua @@ -169,7 +169,7 @@ DIAG_INVISIBLE_PACKAGE = DIAG_GLOBAL_ELEMENT = '全局变量。' DIAG_MISSING_FIELDS = -'缺少字段: {}' +'缺少类型 `{1}` 的必要字段: {2}' DIAG_INJECT_FIELD = '不能在 `{class}` 的引用中注入字段 `{field}` 。{fix}' DIAG_INJECT_FIELD_FIX_CLASS = diff --git a/locale/zh-tw/script.lua b/locale/zh-tw/script.lua index 80c4bec2..43c064b2 100644 --- a/locale/zh-tw/script.lua +++ b/locale/zh-tw/script.lua @@ -169,7 +169,7 @@ DIAG_INVISIBLE_PACKAGE = -- TODO: need translate! DIAG_GLOBAL_ELEMENT = -- TODO: need translate! 'Element is global.' DIAG_MISSING_FIELDS = -- TODO: need translate! -'Missing fields: {}' +'Missing required fields in type `{1}`: {2}' DIAG_INJECT_FIELD = -- TODO: need translate! 'Fields cannot be injected into the reference of `{class}` for `{field}`. {fix}' DIAG_INJECT_FIELD_FIX_CLASS = -- TODO: need translate! diff --git a/script/core/diagnostics/missing-fields.lua b/script/core/diagnostics/missing-fields.lua index 6e02f638..210920fd 100644 --- a/script/core/diagnostics/missing-fields.lua +++ b/script/core/diagnostics/missing-fields.lua @@ -27,6 +27,7 @@ return function (uri, callback) return end end + local warnings = {} for _, def in ipairs(defs) do if def.type == 'doc.class' then if not def.fields then @@ -67,12 +68,17 @@ return function (uri, callback) return end - callback { - start = src.start, - finish = src.finish, - message = lang.script('DIAG_MISSING_FIELDS', table.concat(missedKeys, ', ')), - } + warnings[#warnings+1] = lang.script('DIAG_MISSING_FIELDS', def.class[1], table.concat(missedKeys, ', ')) end end + + if #warnings == 0 then + return + end + callback { + start = src.start, + finish = src.finish, + message = table.concat(warnings, '\n') + } end) end diff --git a/test/diagnostics/missing-fields.lua b/test/diagnostics/missing-fields.lua index f5fdd35c..ab87f81d 100644 --- a/test/diagnostics/missing-fields.lua +++ b/test/diagnostics/missing-fields.lua @@ -205,3 +205,29 @@ TEST [[ ---@type A return <!{}!> ]] + +TEST [[ +---@class A +---@field x number + +---@class B +---@field y number + +---@type A|B +local t = <!{ + z = 1, +}!> +]] + +TEST [[ +---@class A +---@field x number + +---@class B +---@field y number + +---@type A|B +local t = { + y = 1, +} +]] |