summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeOzay <colpaert.benoit@gmail.com>2024-07-22 22:47:20 +0200
committerNeOzay <colpaert.benoit@gmail.com>2024-07-22 22:47:20 +0200
commit3ce73bee997a385b5f31cd7e7474eb3e23cbbd64 (patch)
tree95a473e7f13d29963d095d33a237c41d7467c72d
parentf221eb304e914736f88412b97ed3e1406754a907 (diff)
downloadlua-language-server-3ce73bee997a385b5f31cd7e7474eb3e23cbbd64.zip
improve diagnosis (missing-fields).
-rw-r--r--script/core/diagnostics/missing-fields.lua91
1 files changed, 54 insertions, 37 deletions
diff --git a/script/core/diagnostics/missing-fields.lua b/script/core/diagnostics/missing-fields.lua
index 210920fd..e6b48ffd 100644
--- a/script/core/diagnostics/missing-fields.lua
+++ b/script/core/diagnostics/missing-fields.lua
@@ -16,69 +16,86 @@ return function (uri, callback)
await.delay()
local defs = vm.getDefs(src)
+ local sortedDefs = {}
for _, def in ipairs(defs) do
- if def.type == 'doc.class' and def.bindSource then
- if guide.isInRange(def.bindSource, src.start) then
+ if def.type == 'doc.class' then
+ if def.bindSource and guide.isInRange(def.bindSource, src.start) then
return
end
+ if not sortedDefs[def.class[1]] then
+ sortedDefs[def.class[1]] = {}
+ end
+ local samedefs = sortedDefs[def.class[1]]
+ samedefs[#samedefs+1] = def
end
if def.type == 'doc.type.array'
or def.type == 'doc.type.table' then
return
end
end
- local warnings = {}
- for _, def in ipairs(defs) do
- if def.type == 'doc.class' then
- if not def.fields then
- return
- end
+
+ local Allwarnings = {}
+ for _, samedefs in pairs(sortedDefs) do
+ local warnings = {}
+ for _, def in ipairs(samedefs) do
+ if def.type == 'doc.class' then
+ if not def.fields then
+ goto continue
+ end
- local requiresKeys = {}
- for _, field in ipairs(def.fields) do
- if not field.optional
- and not vm.compileNode(field):isNullable() then
+ local requiresKeys = {}
+ for _, field in ipairs(def.fields) do
+ if not field.optional
+ and not vm.compileNode(field):isNullable() then
+ local key = vm.getKeyName(field)
+ if key and not requiresKeys[key] then
+ requiresKeys[key] = true
+ requiresKeys[#requiresKeys+1] = key
+ end
+ end
+ end
+
+ if #requiresKeys == 0 then
+ goto continue
+ end
+ local myKeys = {}
+ for _, field in ipairs(src) do
local key = vm.getKeyName(field)
- if key and not requiresKeys[key] then
- requiresKeys[key] = true
- requiresKeys[#requiresKeys+1] = key
+ if key then
+ myKeys[key] = true
end
end
- end
- if #requiresKeys == 0 then
- return
- end
- local myKeys = {}
- for _, field in ipairs(src) do
- local key = vm.getKeyName(field)
- if key then
- myKeys[key] = true
+ local missedKeys = {}
+ for _, key in ipairs(requiresKeys) do
+ if not myKeys[key] then
+ missedKeys[#missedKeys+1] = ('`%s`'):format(key)
+ end
end
- end
- local missedKeys = {}
- for _, key in ipairs(requiresKeys) do
- if not myKeys[key] then
- missedKeys[#missedKeys+1] = ('`%s`'):format(key)
+ if #missedKeys == 0 then
+ goto continue
end
- end
- if #missedKeys == 0 then
- return
+ warnings[#warnings+1] = lang.script('DIAG_MISSING_FIELDS', def.class[1], table.concat(missedKeys, ', '))
+ end
+ ::continue::
+ end
+ if #warnings == 0 then
+ return
+ else
+ for i = 1, #warnings do
+ Allwarnings[#Allwarnings+1] = warnings[i]
end
-
- warnings[#warnings+1] = lang.script('DIAG_MISSING_FIELDS', def.class[1], table.concat(missedKeys, ', '))
end
end
-
- if #warnings == 0 then
+ if #Allwarnings == 0 then
return
end
callback {
start = src.start,
finish = src.finish,
- message = table.concat(warnings, '\n')
+ message = table.concat(Allwarnings, '\n')
}
end)
end