Skip to content

Commit

Permalink
Add children to the children of roSGNode containers. Make the evaluat…
Browse files Browse the repository at this point in the history
…ion of temparory variables a helper function
  • Loading branch information
Christian-Holbrook committed Jun 13, 2024
1 parent 49a08e1 commit b6d6dd9
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 24 deletions.
12 changes: 12 additions & 0 deletions src/adapters/DebugProtocolAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,18 @@ export class DebugProtocolAdapter {
//this is the top-level container, so there are no parent keys to this entry
undefined
);
if (container?.value?.startsWith('roSGNode')) {
let nodeChildren = <EvaluateContainer>{
name: '[[children]]',
type: 'roArray',
highLevelType: 'array',
keyType: KeyType.integer,
presentationHint: 'virtual',
evaluateName: `${expression}.getChildren(-1, 0)`,
children: []
};
container.children.push(nodeChildren);
}
return container;
}
}
Expand Down
55 changes: 31 additions & 24 deletions src/debugSession/BrightScriptDebugSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,8 @@ export class BrightScriptDebugSession extends BaseDebugSession {
const vars = await (this.rokuAdapter as TelnetAdapter).getScopeVariables();

for (const varName of vars) {
let result = await this.rokuAdapter.getVariable(varName, -1);
let {evalArgs} = await this.evaluateTemporaryVariables({expression: varName, frameId: -1}, util.getVariablePath(varName));

Check failure on line 1102 in src/debugSession/BrightScriptDebugSession.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

A space is required after '{'

Check failure on line 1102 in src/debugSession/BrightScriptDebugSession.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

A space is required before '}'

Check failure on line 1102 in src/debugSession/BrightScriptDebugSession.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

A space is required after '{'

Check failure on line 1102 in src/debugSession/BrightScriptDebugSession.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

A space is required before '}'
let result = await this.rokuAdapter.getVariable(evalArgs.expression, -1);
let tempVar = this.getVariableFromResult(result, -1);
childVariables.push(tempVar);
}
Expand All @@ -1117,7 +1118,8 @@ export class BrightScriptDebugSession extends BaseDebugSession {
logger.log('variable', v);
//query for child vars if we haven't done it yet.
if (v.childVariables.length === 0) {
let result = await this.rokuAdapter.getVariable(v.evaluateName, v.frameId);
let {evalArgs} = await this.evaluateTemporaryVariables({expression: v.evaluateName, frameId: v.frameId}, util.getVariablePath(v.evaluateName));

Check failure on line 1121 in src/debugSession/BrightScriptDebugSession.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

A space is required after '{'

Check failure on line 1121 in src/debugSession/BrightScriptDebugSession.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

A space is required before '}'

Check failure on line 1121 in src/debugSession/BrightScriptDebugSession.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

A space is required after '{'

Check failure on line 1121 in src/debugSession/BrightScriptDebugSession.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

A space is required before '}'
let result = await this.rokuAdapter.getVariable(evalArgs.expression, v.frameId);
let tempVar = this.getVariableFromResult(result, v.frameId);
tempVar.frameId = v.frameId;
v.childVariables = tempVar.childVariables;
Expand Down Expand Up @@ -1195,41 +1197,26 @@ export class BrightScriptDebugSession extends BaseDebugSession {

//is at debugger prompt
} else {
let variablePath = util.getVariablePath(args.expression);
if (!variablePath && util.isAssignableExpression(args.expression)) {
let varIndex = this.getNextVarIndex(args.frameId);
let arrayVarName = this.tempVarPrefix + 'eval';
if (varIndex === 0) {
const response = await this.rokuAdapter.evaluate(`${arrayVarName} = []`, args.frameId);
console.log(response);
}
let statement = `${arrayVarName}[${varIndex}] = ${args.expression}`;
args.expression = `${arrayVarName}[${varIndex}]`;
let commandResults = await this.rokuAdapter.evaluate(statement, args.frameId);
if (commandResults.type === 'error') {
throw new Error(commandResults.message);
}
variablePath = [arrayVarName, varIndex.toString()];
}
let {evalArgs, variablePath} = await this.evaluateTemporaryVariables(args, util.getVariablePath(args.expression));

Check failure on line 1200 in src/debugSession/BrightScriptDebugSession.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

A space is required after '{'

Check failure on line 1200 in src/debugSession/BrightScriptDebugSession.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

A space is required before '}'

//if we found a variable path (e.g. ['a', 'b', 'c']) then do a variable lookup because it's faster and more widely supported than `evaluate`
if (variablePath) {
let refId = this.getEvaluateRefId(args.expression, args.frameId);
let refId = this.getEvaluateRefId(evalArgs.expression, evalArgs.frameId);
let v: AugmentedVariable;
//if we already looked this item up, return it
if (this.variables[refId]) {
v = this.variables[refId];
} else {
let result = await this.rokuAdapter.getVariable(args.expression, args.frameId);
let result = await this.rokuAdapter.getVariable(evalArgs.expression, evalArgs.frameId);
if (!result) {
throw new Error('Error: unable to evaluate expression');
}

v = this.getVariableFromResult(result, args.frameId);
v = this.getVariableFromResult(result, evalArgs.frameId);
//TODO - testing something, remove later
// eslint-disable-next-line camelcase
v.request_seq = response.request_seq;
v.frameId = args.frameId;
v.frameId = evalArgs.frameId;
}
response.body = {
result: v.value,
Expand All @@ -1241,13 +1228,13 @@ export class BrightScriptDebugSession extends BaseDebugSession {

//run an `evaluate` call
} else {
let commandResults = await this.rokuAdapter.evaluate(args.expression, args.frameId);
let commandResults = await this.rokuAdapter.evaluate(evalArgs.expression, evalArgs.frameId);

commandResults.message = util.trimDebugPrompt(commandResults.message);
if (args.context !== 'watch') {
//clear variable cache since this action could have side-effects
this.clearState();
this.sendInvalidatedEvent(null, args.frameId);
this.sendInvalidatedEvent(null, evalArgs.frameId);
}
//if the adapter captured output (probably only telnet), print it to the vscode debug console
if (typeof commandResults.message === 'string') {
Expand Down Expand Up @@ -1278,6 +1265,26 @@ export class BrightScriptDebugSession extends BaseDebugSession {
deferred.resolve();
}

private async evaluateTemporaryVariables(args: DebugProtocol.EvaluateArguments, variablePath: string[]): Promise<{evalArgs: DebugProtocol.EvaluateArguments, variablePath: string[]}> {
let returnVal = {evalArgs: args, variablePath};
if (!variablePath && util.isAssignableExpression(args.expression)) {
let varIndex = this.getNextVarIndex(args.frameId);
let arrayVarName = this.tempVarPrefix + 'eval';
if (varIndex === 0) {
const response = await this.rokuAdapter.evaluate(`${arrayVarName} = []`, args.frameId);
console.log(response);
}
let statement = `${arrayVarName}[${varIndex}] = ${args.expression}`;
returnVal.evalArgs.expression = `${arrayVarName}[${varIndex}]`;
let commandResults = await this.rokuAdapter.evaluate(statement, args.frameId);
if (commandResults.type === 'error') {
throw new Error(commandResults.message);
}
returnVal.variablePath = [arrayVarName, varIndex.toString()];
}
return returnVal;
}

/**
* Called when the host stops debugging
* @param response
Expand Down

0 comments on commit b6d6dd9

Please sign in to comment.