Skip to content

Commit 5e993c7

Browse files
committed
fix(diag): fix depends_on array node type (tableexp) and hoist sortedIds out of callback
1 parent 31541c2 commit 5e993c7

1 file changed

Lines changed: 24 additions & 20 deletions

File tree

script/core/diagnostics/devsper-depends.lua

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ return function (uri, callback)
4848
end
4949
end)
5050

51+
-- Build sorted ID list once for error messages
52+
local sortedIds = {}
53+
for k in pairs(declaredIds) do
54+
sortedIds[#sortedIds + 1] = k
55+
end
56+
table.sort(sortedIds)
57+
local declaredIdsStr = table.concat(sortedIds, ', ')
58+
5159
-- Pass 2: check depends_on entries in each wf.task spec
5260
guide.eachSourceType(state.ast, 'call', function (source)
5361
await.delay()
@@ -60,29 +68,25 @@ return function (uri, callback)
6068
local dependsOn = tableGet(spec, 'depends_on')
6169
if not dependsOn or dependsOn.type ~= 'table' then return end
6270

63-
-- Build sorted list of declared IDs for error messages
64-
local sortedIds = {}
65-
for k in pairs(declaredIds) do
66-
sortedIds[#sortedIds + 1] = k
67-
end
68-
table.sort(sortedIds)
69-
70-
-- Iterate direct children of the depends_on array table
71+
-- Array table elements are wrapped in tableexp nodes in the luals AST
7172
for i = 1, #dependsOn do
72-
local child = dependsOn[i]
73-
if child and child.type == 'string' then
74-
local val = child[1]
75-
if val and val ~= '*' and not declaredIds[val] then
76-
callback {
77-
start = child.start,
78-
finish = child.finish,
79-
message = ("devsper: unknown task id '%s' in depends_on — declared ids: %s"):format(
80-
val, table.concat(sortedIds, ', ')
81-
),
82-
}
73+
local exp = dependsOn[i]
74+
if exp and exp.type == 'tableexp' then
75+
local child = exp.value
76+
if child and child.type == 'string' then
77+
local val = child[1]
78+
if val and val ~= '*' and not declaredIds[val] then
79+
callback {
80+
start = child.start,
81+
finish = child.finish,
82+
message = ("devsper: unknown task id '%s' in depends_on — declared ids: %s"):format(
83+
val, declaredIdsStr
84+
),
85+
}
86+
end
8387
end
8488
end
85-
-- Non-string children (variables, function calls) are silently skipped
89+
-- Non-string/non-literal children silently skipped
8690
end
8791
end)
8892
end

0 commit comments

Comments
 (0)