MCPcopy Create free account
hub / github.com/Dart-Code/Dart-Code / evaluateRequest

Function evaluateRequest

src/debug/dart_debug_impl.ts:1173–1272  ·  view source on GitHub ↗
(response: DebugProtocol.EvaluateResponse, args: DebugProtocol.EvaluateArguments)

Source from the content-addressed store, hash-verified

1171 }
1172
1173 protected async evaluateRequest(response: DebugProtocol.EvaluateResponse, args: DebugProtocol.EvaluateArguments): Promise<void> {
1174 const isClipboardContext = args.context === "clipboard";
1175 const isWatchContext = args.context === "watch";
1176 const expression: string = args.expression.replace(trailingSemicolonPattern, "");
1177
1178 if (expression.endsWith(",nq") || expression.endsWith(",h") || expression.endsWith(",d")) {
1179 this.errorResponse(response, "Format specifiers are only supported in the SDK debug adapters");
1180 return;
1181 }
1182
1183 // Stack frame scope; if not specified, the expression is evaluated in the global scope.
1184 const frameId = args.frameId;
1185
1186 const data = frameId ? this.threadManager.getStoredData(frameId) : undefined;
1187 const thread = data ? data.thread : this.threadManager.threads[0];
1188
1189 try {
1190 let result: DebuggerResult | undefined;
1191 if (!data) {
1192 if (!this.vmService || !thread) {
1193 this.errorResponse(response, "Global evaluation requires a thread to have been loaded");
1194 return;
1195 }
1196
1197 const isolate = (await this.vmService.getIsolate(thread.ref.id)).result as VMIsolate;
1198 const rootLib = isolate.rootLib;
1199
1200 if (!rootLib) {
1201 this.errorResponse(response, "global evaluation requires a rootLib on the initial thread");
1202 return;
1203 }
1204
1205 // Don't wait more than a second for the response:
1206 // 1. VS Code's watch window behaves badly when there are incomplete evaluate requests
1207 // https://github.com/Microsoft/vscode/issues/52317
1208 // 2. The VM sometimes doesn't respond to your requests at all
1209 // https://github.com/flutter/flutter/issues/18595
1210 result = await this.withTimeout(this.vmService.evaluate(thread.ref.id, rootLib.id, expression, true));
1211 } else {
1212 const frame = data.data as VMFrame;
1213 if ((expression === threadExceptionExpression || expression.startsWith(`${threadExceptionExpression}.`)) && thread.exceptionReference) {
1214 const exceptionData = this.threadManager.getStoredData(thread.exceptionReference);
1215 const exceptionInstanceRef = exceptionData && exceptionData.data as VMInstanceRef;
1216
1217 if (expression === threadExceptionExpression) {
1218 response.body = {
1219 result: await this.fullValueAsString(thread.ref, exceptionInstanceRef) || "<unknown>",
1220 variablesReference: thread.exceptionReference,
1221 };
1222 this.sendResponse(response);
1223 return;
1224 }
1225
1226 const exceptionId = exceptionInstanceRef && exceptionInstanceRef.id;
1227
1228 if (exceptionId)
1229 result = await this.vmService!.evaluate(thread.ref.id, exceptionId, expression.substr(threadExceptionExpression.length + 1), true);
1230 }

Callers

nothing calls this directly

Calls 7

errorStringFunction · 0.90
getStoredDataMethod · 0.80
getIsolateMethod · 0.80
evaluateMethod · 0.80
sendResponseMethod · 0.80
evaluateInFrameMethod · 0.80
storeDataMethod · 0.45

Tested by

no test coverage detected