MCPcopy Create free account
hub / github.com/Snapchat/Valdi / evaluate

Method evaluate

valdi/vscode_debugger/src/adapter/threads.ts:343–433  ·  view source on GitHub ↗
(args: Dap.EvaluateParams)

Source from the content-addressed store, hash-verified

341 }
342
343 async evaluate(args: Dap.EvaluateParams): Promise<Dap.EvaluateResult | Dap.Error> {
344 let callFrameId: Cdp.Debugger.CallFrameId | undefined;
345 if (args.frameId !== undefined) {
346 const stackFrame = this._pausedDetails
347 ? this._pausedDetails.stackTrace.frame(args.frameId)
348 : undefined;
349 if (!stackFrame) return this._stackFrameNotFoundError();
350 callFrameId = stackFrame.callFrameId();
351 if (!callFrameId) return this._evaluateOnAsyncFrameError();
352 }
353
354 if (args.context === 'repl' && args.expression.startsWith('cd ')) {
355 const contextName = args.expression.substring('cd '.length).trim();
356 for (const ec of this._executionContexts.values()) {
357 if (this._delegate.executionContextName(ec.description) === contextName) {
358 this._selectedContext = ec;
359 return {
360 result: `[${contextName}]`,
361 variablesReference: 0,
362 };
363 }
364 }
365 }
366
367 // For clipboard evaluations, return a safe JSON-stringified string.
368 const params: Cdp.Runtime.EvaluateParams =
369 args.context === 'clipboard'
370 ? {
371 expression: serializeForClipboardTmpl(args.expression, '2'),
372 includeCommandLineAPI: true,
373 returnByValue: true,
374 objectGroup: 'console',
375 }
376 : {
377 expression: args.expression,
378 includeCommandLineAPI: true,
379 objectGroup: 'console',
380 generatePreview: true,
381 timeout: args.context === 'hover' ? 500 : undefined,
382 };
383
384 if (args.context === 'repl') {
385 params.expression = sourceUtils.wrapObjectLiteral(params.expression);
386 if (params.expression.indexOf('await') !== -1) {
387 const rewritten = sourceUtils.rewriteTopLevelAwait(params.expression);
388 if (rewritten) {
389 params.expression = rewritten;
390 params.awaitPromise = true;
391 }
392 }
393 }
394
395 const responsePromise = this.evaluator.evaluate(
396 callFrameId
397 ? { ...params, callFrameId }
398 : {
399 ...params,
400 contextId: this._selectedContext ? this._selectedContext.description.id : undefined,

Callers

nothing calls this directly

Calls 13

_evaluateReplMethod · 0.95
callFrameIdMethod · 0.80
startsWithMethod · 0.80
substringMethod · 0.80
valuesMethod · 0.80
createVariableMethod · 0.80
executionContextNameMethod · 0.65
evaluateMethod · 0.65
frameMethod · 0.45
trimMethod · 0.45

Tested by

no test coverage detected