Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleaned up the scopes flows and added the ability to defer the loading of the local scope #227

Merged
merged 5 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/LaunchConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,16 @@ export interface LaunchConfiguration extends DebugProtocol.LaunchRequestArgument

/**
* Enables automatic population of the debug variable panel on a breakpoint or runtime errors.
* @deprecated Use `deferScopeLoading` instead
*/
enableVariablesPanel: boolean;

/**
* Will defer the population of the 'Local' scope variables until the user expands it in the variables panel.
* @default false
*/
deferScopeLoading: boolean;

/**
* Enables automatic population of the virtual variables.
*/
Expand Down
13 changes: 8 additions & 5 deletions src/adapters/DebugProtocolAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,6 @@ export class DebugProtocolAdapter {
* @param expression the expression for the specified variable (i.e. `m`, `someVar.value`, `arr[1][2].three`). If empty string/undefined is specified, all local variables are retrieved instead
*/
private async getVariablesResponse(expression: string, frameId: number) {
const isScopesRequest = expression === '';
const logger = this.logger.createLogger('[getVariable]');
logger.info('begin', { expression });
if (!this.isAtDebuggerPrompt) {
Expand Down Expand Up @@ -1012,6 +1011,14 @@ export class DebugProtocolAdapter {
}
}
}

public isTelnetAdapter(): this is TelnetAdapter {
return false;
}

public isDebugProtocolAdapter(): this is DebugProtocolAdapter {
return true;
}
}

export interface StackFrame {
Expand Down Expand Up @@ -1064,7 +1071,3 @@ interface BrightScriptRuntimeError {
message: string;
errorCode: string;
}

export function isDebugProtocolAdapter(adapter: TelnetAdapter | DebugProtocolAdapter): adapter is DebugProtocolAdapter {
return adapter?.constructor.name === DebugProtocolAdapter.name;
}
15 changes: 10 additions & 5 deletions src/adapters/TelnetAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -588,8 +588,9 @@ export class TelnetAdapter {
/**
* Given an expression, evaluate that statement ON the roku
* @param expression
* @param frameId unused but added to match signature of DebugProtocolAdapter
*/
public async getVariable(expression: string) {
public async getVariable(expression: string, frameId = -1) {
const logger = this.logger.createLogger('[getVariable]');
logger.info('begin', { expression });
if (!this.isAtDebuggerPrompt) {
Expand Down Expand Up @@ -1112,6 +1113,14 @@ export class TelnetAdapter {
public async syncBreakpoints() {
//we can't send dynamic breakpoints to the server...so just do nothing
}

public isTelnetAdapter(): this is TelnetAdapter {
return true;
}

public isDebugProtocolAdapter(): this is DebugProtocolAdapter {
return true;
}
}

export interface StackFrame {
Expand Down Expand Up @@ -1166,7 +1175,3 @@ interface BrightScriptRuntimeError {
message: string;
errorCode: string;
}

export function isTelnetAdapterAdapter(adapter: TelnetAdapter | DebugProtocolAdapter): adapter is TelnetAdapter {
return adapter?.constructor.name === TelnetAdapter.name;
}
30 changes: 28 additions & 2 deletions src/debugSession/BrightScriptDebugSession.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { RendezvousTracker } from '../RendezvousTracker';
import { ClientToServerCustomEventName, isCustomRequestEvent, LogOutputEvent } from './Events';
import { EventEmitter } from 'eventemitter3';
import type { EvaluateContainer } from '../adapters/DebugProtocolAdapter';
import { VariableType } from '../debugProtocol/events/responses/VariablesResponse';

const sinon = sinonActual.createSandbox();
const tempDir = s`${__dirname}/../../.tmp`;
Expand Down Expand Up @@ -117,6 +118,8 @@ describe('BrightScriptDebugSession', () => {
getScopeVariables: (a) => { },
setExceptionBreakpoints: (a) => { },
isScrapableContainObject: () => { },
isTelnetAdapter: () => false,
isDebugProtocolAdapter: () => true,
getThreads: () => {
return [];
},
Expand Down Expand Up @@ -334,6 +337,21 @@ describe('BrightScriptDebugSession', () => {
sinon.stub(rokuAdapter, 'getScopeVariables').callsFake(() => {
return Promise.resolve(['m', 'top', `${session.tempVarPrefix}eval`]);
});
sinon.stub(session as any, 'populateScopeVariables').callsFake((v: AugmentedVariable, args: DebugProtocol.VariablesArguments) => {
v.childVariables = [{
name: `${session.tempVarPrefix}eval`,
value: 'true',
variablesReference: 0
}, {
name: 'top',
value: 'roSGNode:GetSubReddit',
variablesReference: 3
}, {
name: 'm',
value: VariableType.AssociativeArray,
variablesReference: 0
}];
});
sinon.stub(rokuAdapter, 'getVariable').callsFake(x => {
return Promise.resolve(
{
Expand All @@ -359,7 +377,7 @@ describe('BrightScriptDebugSession', () => {
session['dispatchRequest']({ command: 'scopes', arguments: { frameId: 0 }, type: 'request', seq: 8 });
await session.variablesRequest(
response,
{ variablesReference: 1000, filter: 'named', start: 0, count: 0, format: '' } as DebugProtocol.VariablesArguments
{ variablesReference: 1, filter: 'named', start: 0, count: 0, format: '' } as DebugProtocol.VariablesArguments
);

expect(
Expand All @@ -369,7 +387,7 @@ describe('BrightScriptDebugSession', () => {
session['launchConfiguration'].showHiddenVariables = true;
await session.variablesRequest(
response,
{ variablesReference: 1000, filter: 'named', start: 0, count: 0, format: '' } as DebugProtocol.VariablesArguments
{ variablesReference: 1, filter: 'named', start: 0, count: 0, format: '' } as DebugProtocol.VariablesArguments
);
expect(
response.body.variables.find(x => x.name.startsWith(session.tempVarPrefix))
Expand Down Expand Up @@ -654,6 +672,8 @@ describe('BrightScriptDebugSession', () => {

it('returns the correct boolean variable', async () => {
session['rokuAdapterDeferred'].resolve(session['rokuAdapter']);
sinon.stub(session['rokuAdapter'], 'isTelnetAdapter').callsFake(() => true);
sinon.stub(session['rokuAdapter'], 'isDebugProtocolAdapter').callsFake(() => false);

let expression = 'someBool';
getVariableValue = getBooleanEvaluateContainer(expression);
Expand All @@ -673,6 +693,8 @@ describe('BrightScriptDebugSession', () => {
//this fails on TravisCI for some reason. TODO - fix this
it('returns the correct indexed variables count', async () => {
session['rokuAdapterDeferred'].resolve(session['rokuAdapter']);
sinon.stub(session['rokuAdapter'], 'isTelnetAdapter').callsFake(() => true);
sinon.stub(session['rokuAdapter'], 'isDebugProtocolAdapter').callsFake(() => false);

let expression = 'someArray';
getVariableValue = <EvaluateContainer>{
Expand All @@ -699,6 +721,8 @@ describe('BrightScriptDebugSession', () => {

it('returns the correct named variables count', async () => {
session['rokuAdapterDeferred'].resolve(session['rokuAdapter']);
sinon.stub(session['rokuAdapter'], 'isTelnetAdapter').callsFake(() => true);
sinon.stub(session['rokuAdapter'], 'isDebugProtocolAdapter').callsFake(() => false);

let expression = 'someObject';
getVariableValue = <EvaluateContainer>{
Expand Down Expand Up @@ -1020,6 +1044,8 @@ describe('BrightScriptDebugSession', () => {

beforeEach(() => {
session['rokuAdapterDeferred'].resolve(session['rokuAdapter']);
sinon.stub(session['rokuAdapter'], 'isTelnetAdapter').callsFake(() => true);
sinon.stub(session['rokuAdapter'], 'isDebugProtocolAdapter').callsFake(() => false);

rokuAdapter.isAtDebuggerPrompt = true;
evalStub = sinon.stub(rokuAdapter, 'evaluate').callsFake((args) => {
Expand Down
Loading