summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2023-07-21 15:21:37 +0800
committer最萌小汐 <sumneko@hotmail.com>2023-07-21 15:21:37 +0800
commitf074686c59f033566b3fb44aa3f73d1a2ec0e7ed (patch)
treeb26280529d29ab54ee6eed8af3f79dbc2eb8407d
parent7c636357622b7b20e9729c902b5682a05995b911 (diff)
downloadlua-language-server-f074686c59f033566b3fb44aa3f73d1a2ec0e7ed.zip
fix `missing-fields`
-rw-r--r--script/core/diagnostics/missing-fields.lua6
-rw-r--r--test/diagnostics/common.lua17
2 files changed, 21 insertions, 2 deletions
diff --git a/script/core/diagnostics/missing-fields.lua b/script/core/diagnostics/missing-fields.lua
index 4b65172c..05b4f760 100644
--- a/script/core/diagnostics/missing-fields.lua
+++ b/script/core/diagnostics/missing-fields.lua
@@ -17,6 +17,7 @@ return function (uri, callback)
local defs = vm.getDefs(src)
local requiresKeys = {}
+ local isClass = false
for _, def in ipairs(defs) do
if def.type == 'doc.class' then
if not def.fields then
@@ -24,7 +25,8 @@ return function (uri, callback)
end
if def.bindSource then
if guide.isInRange(def.bindSource, src.start) then
- goto continue
+ isClass = true
+ break
end
end
for _, field in ipairs(def.fields) do
@@ -41,7 +43,7 @@ return function (uri, callback)
::continue::
end
- if #requiresKeys == 0 then
+ if #requiresKeys == 0 or isClass then
return
end
diff --git a/test/diagnostics/common.lua b/test/diagnostics/common.lua
index d061b4e4..aff97c77 100644
--- a/test/diagnostics/common.lua
+++ b/test/diagnostics/common.lua
@@ -2414,3 +2414,20 @@ f {
z = 3,
}
]]
+
+TEST [[
+---@diagnostic disable: unused-local
+---@class A
+---@field x number
+local t = {}
+]]
+
+TEST [[
+---@diagnostic disable: unused-local
+
+---@class A
+---@field x number
+
+---@class A
+local t = {}
+]]