Skip to content

Commit dfe6c65

Browse files
committed
improve debugger
1 parent 431f5e8 commit dfe6c65

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

src/debugger/AttachDebugSession.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import {
1010
LuaAttachMessage, DMReqInitialize, DebugMessageId, DMMessage, DMLoadScript,
1111
DMAddBreakpoint, DMBreak, StackNodeContainer, StackRootNode, IStackNode,
1212
DMReqEvaluate, DMRespEvaluate, ExprEvaluator, LoadedScript, LoadedScriptManager,
13-
DMDelBreakpoint
13+
DMDelBreakpoint,
14+
LuaXObjectValue
1415
} from './AttachProtol';
1516
import { ByteArray } from './ByteArray';
1617
import * as path from 'path';
@@ -439,7 +440,11 @@ export class AttachDebugSession extends EmmyDebugSession implements ExprEvaluato
439440
this.curFrameId = frameId;
440441
this.eval(args.expression, frameId).then(v => {
441442
const ctx = { evaluator: this, handles: this.handles, scriptManager: this };
442-
const variable = v.resultNode.children[0].toVariable(ctx);
443+
const node = v.resultNode.children[0];
444+
if (node instanceof LuaXObjectValue) {
445+
node.name = args.expression;
446+
}
447+
const variable = node.toVariable(ctx);
443448
response.body = {
444449
result: variable.name,
445450
variablesReference: variable.variablesReference

src/debugger/AttachProtol.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -265,13 +265,15 @@ interface ComputeContext {
265265
}
266266

267267
export interface IStackNode {
268-
parent?: IStackNode;
268+
parent: IStackNode | undefined;
269269
read(ctx: Context, buf: ByteArray): void;
270270
toVariable(ctx: ComputeContext): Variable;
271271
computeChildren(ctx: ComputeContext): Thenable<IStackNode[]>;
272272
}
273273

274274
abstract class StackNode implements IStackNode {
275+
parent: IStackNode | undefined;
276+
275277
abstract read(ctx: Context, buf: ByteArray): void;
276278

277279
abstract toVariable(ctx: ComputeContext): Variable;
@@ -326,8 +328,6 @@ export abstract class LuaXObjectValue extends StackNode {
326328
public type = "";
327329
public data = "";
328330

329-
public parent?: LuaXObjectValue;
330-
331331
read(ctx: Context, buf: ByteArray) {
332332
this.name = buf.readString();
333333
this.type = buf.readString();
@@ -375,6 +375,7 @@ class LuaXTable extends LuaXObjectValue {
375375
const key = <LuaXObjectValue> readNode(ctx, buf);
376376
const value = <LuaXObjectValue> readNode(ctx, buf);
377377
value.name = key.toKeyString();
378+
value.parent = this;
378379
this.children.push(value);
379380
}
380381
}
@@ -385,19 +386,21 @@ class LuaXTable extends LuaXObjectValue {
385386
return Promise.resolve(this.children);
386387
}
387388
return new Promise((resolve) => {
388-
ctx.evaluator.eval(this.calcExpr()).then(value => {
389+
let expr = this.calcExpr();
390+
ctx.evaluator.eval(expr).then(value => {
389391
const n = value.resultNode.children[0];
390392
if (n instanceof LuaXTable) {
391393
this.children = n.children;
392-
this.children.forEach(node => node.parent = this);
393-
resolve(n.children);
394+
this.children.map(c => c.parent = this);
394395
}
396+
resolve(this.children);
395397
});
396398
});
397399
}
398400

399401
toVariable(ctx: ComputeContext): DebugProtocol.Variable {
400-
return { name: this.name, value: "table", variablesReference: ctx.handles.create(this), type:"object" };
402+
let ref = ctx.handles.create(this);
403+
return { name: "table", value: "table", variablesReference: ref, type:"object" };
401404
}
402405
}
403406

0 commit comments

Comments
 (0)