summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeOzay <colpaert.benoit@gmail.com>2024-07-24 18:22:00 +0200
committerNeOzay <colpaert.benoit@gmail.com>2024-07-24 18:22:00 +0200
commiteca4758b93bce043b702dac7f6234a2f58df218e (patch)
treed213fc9ba441420ccba0fef14b16afe45caf999f
parent69c992d298aab2b0d17695e11fa54816014aed4d (diff)
parentc08410458924a9f3c604e662cfce80f0f86d5b78 (diff)
downloadlua-language-server-eca4758b93bce043b702dac7f6234a2f58df218e.zip
Merge commit 'c08410458924a9f3c604e662cfce80f0f86d5b78' into inconsistent-behavior-(missing-fields)
-rw-r--r--script/core/diagnostics/missing-fields.lua17
-rw-r--r--test/diagnostics/missing-fields.lua18
2 files changed, 33 insertions, 2 deletions
diff --git a/script/core/diagnostics/missing-fields.lua b/script/core/diagnostics/missing-fields.lua
index b901461a..18b561ee 100644
--- a/script/core/diagnostics/missing-fields.lua
+++ b/script/core/diagnostics/missing-fields.lua
@@ -15,6 +15,7 @@ return function (uri, callback)
guide.eachSourceType(state.ast, 'table', function (src)
await.delay()
+ vm.removeNode(src) -- the node is not updated correctly, reason still unknown
local defs = vm.getDefs(src)
local sortedDefs = {}
for _, def in ipairs(defs) do
@@ -47,7 +48,7 @@ return function (uri, callback)
local myKeys = {}
for _, field in ipairs(src) do
- local key = vm.getKeyName(field)
+ local key = vm.getKeyName(field) or field.tindex
if key then
myKeys[key] = true
end
@@ -57,8 +58,20 @@ return function (uri, callback)
if not field.optional
and not vm.compileNode(field):isNullable() then
local key = vm.getKeyName(field)
+ if not key then
+ local fieldnode = vm.compileNode(field.field)[1]
+ if fieldnode and fieldnode.type == 'doc.type.integer' then
+ ---@cast fieldnode parser.object
+ key = vm.getKeyName(fieldnode)
+ end
+ end
+
if key and not myKeys[key] then
- missedKeys[#missedKeys+1] = ('`%s`'):format(key)
+ if type(key) == "number" then
+ missedKeys[#missedKeys+1] = ('`[%s]`'):format(key)
+ else
+ missedKeys[#missedKeys+1] = ('`%s`'):format(key)
+ end
end
end
end
diff --git a/test/diagnostics/missing-fields.lua b/test/diagnostics/missing-fields.lua
index f1b1beae..8c1ffbbb 100644
--- a/test/diagnostics/missing-fields.lua
+++ b/test/diagnostics/missing-fields.lua
@@ -334,4 +334,22 @@ local x = <!{
bb = 2,
bd = 4,
}!>
+]]
+
+TEST[[
+---@class A
+---@field [1] string
+---@field x number
+
+---@type A
+local t = {x = 1, ""}
+]]
+
+TEST[[
+---@class A
+---@field [1] string
+---@field x number
+
+---@type A
+local t = <!{x = 1}!>
]] \ No newline at end of file