in src/debugAdapter/goDebug.ts [1873:1941]
protected evaluateRequest(response: DebugProtocol.EvaluateResponse, args: DebugProtocol.EvaluateArguments): void {
log('EvaluateRequest');
// Captures pattern that looks like the expression that starts with `call<space>`
// command call. This is supported only with APIv2.
const isCallCommand = args.expression.match(/^\s*call\s+\S+/);
if (!this.delve?.isApiV1 && isCallCommand) {
this.evaluateCallImpl(args).then(
(out) => {
const state = (<CommandOut>out).State;
const returnValues = state?.currentThread?.ReturnValues ?? [];
switch (returnValues.length) {
case 0:
response.body = { result: '', variablesReference: 0 };
break;
case 1:
response.body = this.convertDebugVariableToProtocolVariable(returnValues[0]);
break;
default:
// Go function can return multiple return values while
// DAP EvaluateResponse assumes a single result with possibly
// multiple children. So, create a fake DebugVariable
// that has all the results as children.
const returnResults = this.wrapReturnVars(returnValues);
response.body = this.convertDebugVariableToProtocolVariable(returnResults);
break;
}
this.sendResponse(response);
log('EvaluateCallResponse');
},
(err) => {
this.sendErrorResponse(
response,
2009,
'Unable to complete call: "{e}"',
{
e: err.toString()
},
args.context === 'watch' ? undefined : ErrorDestination.User
);
}
);
return;
}
// Now handle it as a conventional evaluateRequest.
this.evaluateRequestImpl(args).then(
(out) => {
const variable = this.delve?.isApiV1 ? <DebugVariable>out : (<EvalOut>out).Variable;
// #2326: Set the fully qualified name for variable mapping
variable.fullyQualifiedName = variable.name;
response.body = this.convertDebugVariableToProtocolVariable(variable);
this.sendResponse(response);
log('EvaluateResponse');
},
(err) => {
// No need to repeatedly show the error pop-up when expressions
// are continuously reevaluated in the Watch panel, which
// already displays errors.
this.sendErrorResponse(
response,
2009,
'Unable to eval expression: "{e}"',
{
e: err.toString()
},
args.context === 'watch' ? undefined : ErrorDestination.User
);
}
);
}