Skip to content

Commit

Permalink
Adding support to EvaluationOptions from dap. (#1323)
Browse files Browse the repository at this point in the history
* Adding support to EvaluationOptions from dap, as discussed in this issue: #1315

* Fix tests

* Pushing generated file after merge.
  • Loading branch information
thaystg committed Dec 30, 2022
1 parent 86a9efa commit bc604e0
Show file tree
Hide file tree
Showing 10 changed files with 327 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/adapter/debugAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ export class DebugAdapter implements IDisposable {
supportsBreakpointLocationsRequest: true,
supportsClipboardContext: true,
supportsExceptionFilterOptions: true,
supportsEvaluationOptions: extended ? true : false,
supportsDebuggerProperties: extended ? true : false,
supportsSetSymbolOptions: extended ? true : false,
//supportsDataBreakpoints: false,
Expand Down
11 changes: 8 additions & 3 deletions src/adapter/stackTrace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,19 @@ export class StackTrace {
this._lastFrameThread = thread;
}

async loadFrames(limit: number): Promise<FrameElement[]> {
async loadFrames(limit: number, noFuncEval?: boolean): Promise<FrameElement[]> {
while (this.frames.length < limit && this._asyncStackTraceId) {
if (this._asyncStackTraceId.debuggerId)
this._lastFrameThread = Thread.threadForDebuggerId(this._asyncStackTraceId.debuggerId);
if (!this._lastFrameThread) {
this._asyncStackTraceId = undefined;
break;
}
if (noFuncEval)
this._lastFrameThread
.cdp()
.DotnetDebugger.setEvaluationOptions({ options: { noFuncEval }, type: 'stackFrame' });

const response = await this._lastFrameThread
.cdp()
.Debugger.getStackTrace({ stackTraceId: this._asyncStackTraceId });
Expand Down Expand Up @@ -176,10 +181,10 @@ export class StackTrace {
return (await Promise.all(promises)).join('\n') + '\n';
}

async toDap(params: Dap.StackTraceParams): Promise<Dap.StackTraceResult> {
async toDap(params: Dap.StackTraceParamsExtended): Promise<Dap.StackTraceResult> {
const from = params.startFrame || 0;
let to = (params.levels || 50) + from;
const frames = await this.loadFrames(to);
const frames = await this.loadFrames(to, params.noFuncEval);
to = Math.min(frames.length, params.levels ? to : frames.length);

const result: Promise<Dap.StackFrame>[] = [];
Expand Down
8 changes: 7 additions & 1 deletion src/adapter/threads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ export class Thread implements IVariableStoreLocationProvider {
.map(label => ({ label, start: 0, length: params.text.length }));
}

async evaluate(args: Dap.EvaluateParams): Promise<Dap.EvaluateResult> {
async evaluate(args: Dap.EvaluateParamsExtended): Promise<Dap.EvaluateResult> {
let callFrameId: Cdp.Debugger.CallFrameId | undefined;
let stackFrame: StackFrame | undefined;
if (args.frameId !== undefined) {
Expand Down Expand Up @@ -495,6 +495,12 @@ export class Thread implements IVariableStoreLocationProvider {
params.expression += getReplSourceSuffix();
}

if (args.evaluationOptions)
this.cdp().DotnetDebugger.setEvaluationOptions({
options: args.evaluationOptions,
type: 'evaluation',
});

const responsePromise = this.evaluator.evaluate(
callFrameId
? { ...params, callFrameId }
Expand Down
15 changes: 12 additions & 3 deletions src/adapter/variableStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,10 @@ class VariableContext {
/**
* Creates Variables for each property on the RemoteObject.
*/
public async createObjectPropertyVars(object: Cdp.Runtime.RemoteObject): Promise<Variable[]> {
public async createObjectPropertyVars(
object: Cdp.Runtime.RemoteObject,
evaluationOptions?: Dap.EvaluationOptions,
): Promise<Variable[]> {
const properties: (Promise<Variable[]> | Variable[])[] = [];

if (this.settings.customPropertiesGenerator) {
Expand Down Expand Up @@ -299,6 +302,12 @@ class VariableContext {
return [];
}

if (evaluationOptions)
this.cdp.DotnetDebugger.setEvaluationOptions({
options: evaluationOptions,
type: 'variable',
});

const [accessorsProperties, ownProperties, stringyProps] = await Promise.all([
this.cdp.Runtime.getProperties({
objectId: object.objectId,
Expand Down Expand Up @@ -789,8 +798,8 @@ class ObjectVariable extends Variable implements IMemoryReadable {
return result.value;
}

public override getChildren(_params: Dap.VariablesParams) {
return this.context.createObjectPropertyVars(this.remoteObject);
public override getChildren(_params: Dap.VariablesParamsExtended) {
return this.context.createObjectPropertyVars(this.remoteObject, _params.evaluationOptions);
}
}

Expand Down
117 changes: 117 additions & 0 deletions src/build/dapCustom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,9 @@ const dapCustom: JSONSchema4 = {
supportsDebuggerProperties: {
type: 'boolean',
},
supportsEvaluationOptions: {
type: 'boolean',
},
supportsSetSymbolOptions: {
type: 'boolean',
description: 'The debug adapter supports the set symbol options request',
Expand All @@ -611,6 +614,120 @@ const dapCustom: JSONSchema4 = {
],
},

...makeRequest('evaluationOptions', 'Used by evaluate and variables.', {
properties: {
evaluateParams: {
$ref: '#/definitions/EvaluateParamsExtended',
},
variablesParams: {
$ref: '#/definitions/VariablesParamsExtended',
},
stackTraceParams: {
$ref: '#/definitions/StackTraceParamsExtended',
},
},
}),

EvaluationOptions: {
type: 'object',
description:
'Options passed to expression evaluation commands ("evaluate" and "variables") to control how the evaluation occurs.',
properties: {
treatAsStatement: {
type: 'boolean',
description: 'Evaluate the expression as a statement.',
},
allowImplicitVars: {
type: 'boolean',
description: 'Allow variables to be declared as part of the expression.',
},
noSideEffects: {
type: 'boolean',
description: 'Evaluate without side effects.',
},
noFuncEval: {
type: 'boolean',
description: 'Exclude funceval during evaluation.',
},
noToString: {
type: 'boolean',
description: 'Exclude calling `ToString` during evaluation.',
},
forceEvaluationNow: {
type: 'boolean',
description: 'Evaluation should take place immediately if possible.',
},
forceRealFuncEval: {
type: 'boolean',
description: 'Exclude interpretation from evaluation methods.',
},
runAllThreads: {
type: 'boolean',
description: 'Allow all threads to run during the evaluation.',
},
rawStructures: {
type: 'boolean',
description:
"The 'raw' view of objects and structions should be shown - visualization improvements should be disabled.",
},
filterToFavorites: {
type: 'boolean',
description:
'Variables responses containing favorites should be filtered to only those items',
},
simpleDisplayString: {
type: 'boolean',
description:
'Auto generated display strings for variables with favorites should not include field names.',
},
},
},

EvaluateParamsExtended: {
allOf: [
{ $ref: '#/definitions/EvaluateParams' },
{
type: 'object',
description: 'Extension of EvaluateParams',
properties: {
evaluationOptions: {
$ref: '#/definitions/EvaluationOptions',
},
},
},
],
},

VariablesParamsExtended: {
allOf: [
{ $ref: '#/definitions/VariablesParams' },
{
type: 'object',
description: 'Extension of VariablesParams',
properties: {
evaluationOptions: {
$ref: '#/definitions/EvaluationOptions',
},
},
},
],
},

StackTraceParamsExtended: {
allOf: [
{ $ref: '#/definitions/StackTraceParams' },
{
type: 'object',
description: 'Extension of StackTraceParams',
properties: {
noFuncEval: {
type: 'boolean',
},
},
},
],
},

...makeRequest('setSymbolOptions', 'Sets options for locating symbols.'),

SetSymbolOptionsArguments: {
Expand Down
19 changes: 19 additions & 0 deletions src/build/wasmCustom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ export default {
description:
'Arguments for "setDebuggerProperty" request. Properties are determined by debugger.',
},
{
id: 'EvaluationOptions',
type: 'object',
description: 'Options that will be used to evaluate or to get variables.',
},
{
id: 'SetSymbolOptionsParams',
type: 'object',
Expand All @@ -36,6 +41,20 @@ export default {
},
],
},
{
name: 'setEvaluationOptions',
description: 'Set options for evaluation',
parameters: [
{
name: 'options',
$ref: 'EvaluationOptions',
},
{
name: 'type',
type: 'string',
},
],
},
{
name: 'setSymbolOptions',
description: 'Sets options for locating symbols.',
Expand Down
60 changes: 59 additions & 1 deletion src/cdp/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9944,6 +9944,13 @@ export namespace Cdp {
params: DotnetDebugger.SetDebuggerPropertyParams,
): Promise<DotnetDebugger.SetDebuggerPropertyResult | undefined>;

/**
* Set options for evaluation
*/
setEvaluationOptions(
params: DotnetDebugger.SetEvaluationOptionsParams,
): Promise<DotnetDebugger.SetEvaluationOptionsResult | undefined>;

/**
* Sets options for locating symbols.
*/
Expand All @@ -9968,6 +9975,20 @@ export namespace Cdp {
*/
export interface SetDebuggerPropertyResult {}

/**
* Parameters of the 'DotnetDebugger.setEvaluationOptions' method.
*/
export interface SetEvaluationOptionsParams {
options: EvaluationOptions;

type: string;
}

/**
* Return value of the 'DotnetDebugger.setEvaluationOptions' method.
*/
export interface SetEvaluationOptionsResult {}

/**
* Parameters of the 'DotnetDebugger.setSymbolOptions' method.
*/
Expand All @@ -9985,6 +10006,13 @@ export namespace Cdp {
[key: string]: any;
}

/**
* Options that will be used to evaluate or to get variables.
*/
export interface EvaluationOptions {
[key: string]: any;
}

/**
* Arguments for "setSymbolOptions" request. Properties are determined by debugger.
*/
Expand Down Expand Up @@ -22769,7 +22797,8 @@ export namespace Cdp {
| 'SameSiteCrossOriginNavigationNotOptIn'
| 'ActivationNavigationParameterMismatch'
| 'ActivatedInBackground'
| 'EmbedderHostDisallowed';
| 'EmbedderHostDisallowed'
| 'ActivationNavigationDestroyedBeforeSuccess';
}

/**
Expand Down Expand Up @@ -23777,6 +23806,16 @@ export namespace Cdp {
*/
throwOnSideEffect?: boolean;

/**
* An alternative way to specify the execution context to call function on.
* Compared to contextId that may be reused across processes, this is guaranteed to be
* system-unique, so it can be used to prevent accidental function call
* in context different than intended (e.g. as a result of navigation across process
* boundaries).
* This is mutually exclusive with `executionContextId`.
*/
uniqueContextId?: string;

/**
* Whether the result should contain `webDriverValue`, serialized according to
* https://w3c.github.io/webdriver-bidi. This is mutually exclusive with `returnByValue`, but
Expand Down Expand Up @@ -26052,6 +26091,13 @@ export namespace Cdp {
params: Storage.ClearSharedStorageEntriesParams,
): Promise<Storage.ClearSharedStorageEntriesResult | undefined>;

/**
* Resets the budget for `ownerOrigin` by clearing all budget withdrawals.
*/
resetSharedStorageBudget(
params: Storage.ResetSharedStorageBudgetParams,
): Promise<Storage.ResetSharedStorageBudgetResult | undefined>;

/**
* Enables/disables issuing of sharedStorageAccessed events.
*/
Expand Down Expand Up @@ -26536,6 +26582,18 @@ export namespace Cdp {
*/
export interface ClearSharedStorageEntriesResult {}

/**
* Parameters of the 'Storage.resetSharedStorageBudget' method.
*/
export interface ResetSharedStorageBudgetParams {
ownerOrigin: string;
}

/**
* Return value of the 'Storage.resetSharedStorageBudget' method.
*/
export interface ResetSharedStorageBudgetResult {}

/**
* Parameters of the 'Storage.setSharedStorageTracking' method.
*/
Expand Down
Loading

0 comments on commit bc604e0

Please sign in to comment.