Skip to content

Commit 0fac06f

Browse files
committed
修复lazy的错误
1 parent 5f09787 commit 0fac06f

File tree

1 file changed

+43
-15
lines changed

1 file changed

+43
-15
lines changed

extension/script/backend/worker/variables.lua

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ local function varGetUserdata(value, allow_lazy)
500500
else
501501
local ok, res = rdebug.eval(fn, value)
502502
if ok then
503-
return res
503+
return res, "userdata"
504504
else
505505
return "__tostring error: "..res, "userdata"
506506
end
@@ -554,7 +554,10 @@ local function varGetValue(context, allow_lazy, v)
554554
end
555555
return varGetTableValue(v), 'table'
556556
elseif type == 'userdata' then
557-
return varGetUserdata(v, allow_lazy)
557+
if context == "variables" then
558+
return varGetUserdata(v, allow_lazy)
559+
end
560+
return varGetUserdata(v, false)
558561
elseif type == 'lightuserdata' then
559562
return 'light'..tostring(value), 'lightuserdata'
560563
elseif type == 'thread' then
@@ -576,8 +579,27 @@ local function varGetValue(context, allow_lazy, v)
576579
return ("%s: %s"):format(type, value), type
577580
end
578581

582+
local function deep_copy(tbl, seen)
583+
if type(tbl) ~= 'table' then
584+
return tbl
585+
end
586+
if seen and seen[tbl] then
587+
return seen[tbl]
588+
end
589+
local s = seen or {}
590+
local res = {}
591+
s[tbl] = res
592+
for k, v in pairs(tbl) do
593+
res[deep_copy(k, s)] = deep_copy(v, s)
594+
end
595+
return res
596+
end
597+
579598
local function varCreateReference(value, evaluateName, presentationHint, context)
580599
local valuestr, type, lazy = varGetValue(context, true, value)
600+
if lazy == nil then
601+
lazy = false
602+
end
581603
local result = {
582604
type = type,
583605
value = valuestr,
@@ -594,11 +616,10 @@ local function varCreateReference(value, evaluateName, presentationHint, context
594616
}
595617
result.memoryReference = #memoryRefPool
596618
end
597-
if varCanExtand(type, value) or result.presentationHint.lazy then
619+
if varCanExtand(type, value) then
598620
varPool[#varPool + 1] = {
599621
v = value,
600622
eval = evaluateName,
601-
lazy = result.presentationHint.lazy,
602623
context = context,
603624
}
604625
result.variablesReference = #varPool
@@ -607,6 +628,17 @@ local function varCreateReference(value, evaluateName, presentationHint, context
607628
result.indexedVariables = arrayBase + asize
608629
result.namedVariables = hsize
609630
end
631+
if result.presentationHint.lazy then
632+
local lazy_result = deep_copy(result)
633+
lazy_result.presentationHint.lazy = nil
634+
varPool[#varPool + 1] = {
635+
v = value,
636+
eval = evaluateName,
637+
context = context,
638+
lazy = lazy_result,
639+
}
640+
result.variablesReference = #varPool
641+
end
610642
end
611643
return result
612644
end
@@ -643,6 +675,9 @@ local function varCreateTableKV(key, value, context)
643675
special = "TableKV",
644676
}
645677
local valuestr, _, lazy = varGetValue(context, true, value)
678+
if lazy == nil then
679+
lazy = false
680+
end
646681
return {
647682
type = 'TableKV',
648683
value = valuestr,
@@ -1252,6 +1287,9 @@ local function extandCData(varRef)
12521287
end
12531288

12541289
local function extandValue(varRef, filter, start, count)
1290+
if varRef.lazy then
1291+
return { varRef.lazy }
1292+
end
12551293
if varRef.special then
12561294
return special_extand[varRef.special](varRef, filter, start, count)
12571295
end
@@ -1329,17 +1367,7 @@ function m.extand(valueId, filter, start, count)
13291367
if not varRef then
13301368
return nil, 'Error variablesReference'
13311369
end
1332-
local vars = extandValue(varRef, filter, start, count)
1333-
if varRef.lazy then
1334-
--TODO: fuck VSCode
1335-
local valuestr, type = varGetValue(varRef.context, false, varRef.v)
1336-
table.insert(vars, 1, {
1337-
name = "",
1338-
type = type,
1339-
value = valuestr,
1340-
})
1341-
end
1342-
return vars
1370+
return extandValue(varRef, filter, start, count)
13431371
end
13441372

13451373
function m.set(valueId, name, value)

0 commit comments

Comments
 (0)