Skip to content

Commit 3d32932

Browse files
committed
eval
1 parent 5c5f134 commit 3d32932

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/debugger/AttachDebugSession.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export class AttachDebugSession extends LoggingDebugSession implements ExprEvalu
4848
private breakpoints = new Map<string, EmmyBreakpoint[]>();
4949
private loadedScripts = new Map<string, LoadedScript>();
5050
private break?: DMBreak;
51+
private curFrameId = 0;
5152
private handles: Handles<IStackNode> = new Handles<IStackNode>();
5253
private evalIdCounter = 0;
5354
private evalMap = new Map<number, (v:DMRespEvaluate) => void>();
@@ -346,7 +347,7 @@ export class AttachDebugSession extends LoggingDebugSession implements ExprEvalu
346347
if (script) {
347348
source = new Source(path.basename(script.path), this.resolvePath(script.path));
348349
}
349-
return new StackFrame(index, root.functionName, source, this.convertDebuggerLineToClient(root.line));
350+
return new StackFrame(index++, root.functionName, source, this.convertDebuggerLineToClient(root.line));
350351
}),
351352
totalFrames: stacks.children.length
352353
};
@@ -355,11 +356,12 @@ export class AttachDebugSession extends LoggingDebugSession implements ExprEvalu
355356
}
356357

357358
protected scopesRequest(response: DebugProtocol.ScopesResponse, args: DebugProtocol.ScopesArguments): void {
359+
this.curFrameId = args.frameId;
358360
const stack = this.break!.stacks!.children[args.frameId];
359361
response.body = {
360362
scopes: [
361363
{
362-
name: "Local",
364+
name: "Variables",
363365
variablesReference: this.handles.create(stack),
364366
expensive: false
365367
}
@@ -402,8 +404,9 @@ export class AttachDebugSession extends LoggingDebugSession implements ExprEvalu
402404
}
403405

404406
protected evaluateRequest(response: DebugProtocol.EvaluateResponse, args: DebugProtocol.EvaluateArguments): void {
405-
const stackId = args.frameId || 0;
406-
this.eval(args.expression, stackId).then(v => {
407+
const frameId = args.frameId || 0;
408+
this.curFrameId = frameId;
409+
this.eval(args.expression, frameId).then(v => {
407410
const ctx = { evaluator: this, handles: this.handles, scriptManager: this };
408411
const variable = v.resultNode.children[0].toVariable(ctx);
409412
response.body = {
@@ -414,10 +417,13 @@ export class AttachDebugSession extends LoggingDebugSession implements ExprEvalu
414417
});
415418
}
416419

417-
eval(expr: string, stack: number): Thenable<DMRespEvaluate> {
420+
eval(expr: string, frameId: number = -1): Thenable<DMRespEvaluate> {
421+
if (frameId < 0) {
422+
frameId = this.curFrameId;
423+
}
418424
return new Promise((resolve) => {
419425
const id = this.evalIdCounter++;
420-
const stackId = stack;
426+
const stackId = frameId;
421427
const req = new DMReqEvaluate(this.break!.L, id, stackId, expr, 2);
422428
this.evalMap.set(id, resolve);
423429
this.send(req);

src/debugger/AttachProtol.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ export interface LoadedScriptManager {
234234
}
235235

236236
export interface ExprEvaluator {
237-
eval(expr: string, stack: number): Thenable<DMRespEvaluate>;
237+
eval(expr: string, stack?: number): Thenable<DMRespEvaluate>;
238238
}
239239

240240
interface Context {
@@ -368,7 +368,7 @@ class LuaXTable extends LuaXObjectValue {
368368
return Promise.resolve(this.children);
369369
}
370370
return new Promise((resolve) => {
371-
ctx.evaluator.eval(this.calcExpr(), 0).then(value => {
371+
ctx.evaluator.eval(this.calcExpr()).then(value => {
372372
const n = value.resultNode.children[0];
373373
if (n instanceof LuaXTable) {
374374
this.children = n.children;

0 commit comments

Comments
 (0)