Skip to content

Commit 4be797d

Browse files
committed
continued improvements to vararg and multi-return displays
1 parent e36a767 commit 4be797d

File tree

5 files changed

+25
-25
lines changed

5 files changed

+25
-25
lines changed

debugger/debugger.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,6 @@ export namespace Debugger {
467467
return stack;
468468
}
469469

470-
const varArgTable: LuaDebug.VarArgTable = "{...}";
471-
472470
let breakAtDepth = -1;
473471
let breakInThread: Thread | undefined;
474472
let updateHook: { (): void };
@@ -619,11 +617,11 @@ export namespace Debugger {
619617
const locs = getLocals(frame + frameOffset, currentThread !== activeThread ? currentThread : undefined);
620618
mapVarNames(locs.vars, sourceMap);
621619
if (locs.varargs) {
622-
const varargVals: unknown[] = [];
620+
const varArgVals: unknown[] = [];
623621
for (const vararg of locs.varargs) {
624-
table.insert(varargVals, vararg.val);
622+
table.insert(varArgVals, vararg.val);
625623
}
626-
locs.vars[varArgTable] = {val: varargVals, index: -1, type: "table"};
624+
locs.vars["..."] = {val: varArgVals, index: -1, type: "table"};
627625
}
628626
Send.vars(locs.vars);
629627

debugger/protocol.d.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,6 @@ declare namespace LuaDebug {
108108

109109
type Message = Error | DebugBreak | Result | Stack | Variables | Properties | Breakpoints | Threads;
110110

111-
type VarArgTable = "{...}";
112-
113111
type StartToken = "@lldbg|";
114112
type EndToken = "|lldbg@";
115113

debugger/send.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ export namespace Send {
8080
return dbgVar;
8181
}
8282

83+
function buildVarArgs(name: string, values: unknown[]): LuaDebug.Variable {
84+
const valueStrs: string[] = [];
85+
for (const [_, val] of ipairs(values)) {
86+
table.insert(valueStrs, getPrintableValue(val));
87+
}
88+
return {type: "table", name, value: table.concat(valueStrs, ", "), length: values.length};
89+
}
90+
8391
function send(message: LuaDebug.MessageBase) {
8492
outputFile.write(`${startToken}${Format.asJson(message)}${endToken}`);
8593
}
@@ -134,7 +142,7 @@ export namespace Send {
134142
variables: Format.makeExplicitArray()
135143
};
136144
for (const [name, info] of pairs(varsObj)) {
137-
const dbgVar = buildVariable(name, info.val);
145+
const dbgVar = name === "..." ? buildVarArgs(name, info.val as unknown[]) : buildVariable(name, info.val);
138146
table.insert(dbgVariables.variables, dbgVar);
139147
}
140148
send(dbgVariables);

extension/luaDebugSession.ts

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ const enum OutputCategory {
6868
const maxStackCount = 100;
6969
const metatableDisplayName = "[[metatable]]";
7070
const tableLengthDisplayName = "[[length]]";
71-
const varArgTable: LuaDebug.VarArgTable = "{...}";
7271
const envVariable = "LOCAL_LUA_DEBUGGER_VSCODE";
7372
const filePathEnvVariable = "LOCAL_LUA_DEBUGGER_FILEPATH";
7473
const scriptRootsEnvVariable: LuaDebug.ScriptRootsEnv = "LOCAL_LUA_DEBUGGER_SCRIPT_ROOTS";
@@ -686,11 +685,12 @@ export class LuaDebugSession extends LoggingDebugSession {
686685
} else if (msg.results.length === 1) {
687686
const result = msg.results[0];
688687
const variablesReference = result.type === "table" ? this.variableHandles.create(expression) : 0;
689-
const value = `${typeof result.value !== "undefined" ? result.value : `[${result.type}]`}`;
688+
const value = result.value ?? `[${result.type}]`;
690689
return {success: true, value, variablesReference};
691690
} else {
692691
const variablesReference = this.variableHandles.create(`@({${expression}})`);
693-
return {success: true, value: `[${msg.results.length}]`, variablesReference};
692+
const value = `(${msg.results.map(r => r.value ?? `[${r.type}]`).join(", ")})`;
693+
return {success: true, value, variablesReference};
694694
}
695695

696696
} else if (msg.type === "error") {
@@ -706,26 +706,18 @@ export class LuaDebugSession extends LoggingDebugSession {
706706
private buildVariable(variable: LuaDebug.Variable | LuaDebug.Value, refName: string, variableName?: string) {
707707
let valueStr: string;
708708
let ref: number | undefined;
709-
let name: string | undefined;
710-
if (variable.type === "table") {
711-
if (refName === varArgTable) {
712-
valueStr = typeof variable.length !== "undefined" ? `[${variable.length}]` : "";
713-
name = "...";
714-
refName = `@(${refName})`;
715-
} else if (typeof variable.value !== "undefined") {
716-
valueStr = variable.value;
717-
} else {
718-
valueStr = "[table]";
719-
}
709+
if (refName === "...") {
710+
valueStr = `(${variable.value ?? ""})`;
711+
ref = variable.type === "table" ? this.variableHandles.create("@({...})") : 0;
712+
} else if (variable.type === "table") {
713+
valueStr = variable.value ?? "[table]";
720714
ref = this.variableHandles.create(refName);
721715
} else if (typeof variable.value === "undefined") {
722716
valueStr = `[${variable.type}]`;
723717
} else {
724718
valueStr = variable.value;
725719
}
726-
if (typeof name === "undefined") {
727-
name = typeof variableName !== "undefined" ? variableName : (variable as LuaDebug.Variable).name;
728-
}
720+
const name = typeof variableName !== "undefined" ? variableName : (variable as LuaDebug.Variable).name;
729721
const indexedVariables = typeof variable.length !== "undefined" && variable.length > 0
730722
? variable.length + 1
731723
: variable.length;

tests/arg/main.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,14 @@ function baz(a, ...)
2626
end
2727

2828
foo("a")
29+
foo("a", "b")
2930
foo("a", "b", {c = "d"})
3031

3132
bar("a")
33+
bar("a", "b")
3234
bar("a", "b", {c = "d"})
3335

3436
baz("a")
37+
baz("a", "b")
38+
baz("a", {b = "c"})
3539
baz("a", "b", {c = "d"})

0 commit comments

Comments
 (0)