Skip to content

Commit

Permalink
watch: cleanup setExpression calls
Browse files Browse the repository at this point in the history
  • Loading branch information
isidorn committed Aug 6, 2021
1 parent ba5054e commit 19eb720
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,9 @@ export class WatchExpressionsRenderer extends AbstractExpressionsRenderer {
ariaLabel: localize('typeNewValue', "Type new value"),
onFinish: async (value: string, success: boolean) => {
if (success && value) {
const focusedSession = this.debugService.getViewModel().focusedSession;
const focusedFrame = this.debugService.getViewModel().focusedStackFrame;
if (focusedSession && focusedFrame) {
const path = expression instanceof Variable && expression.evaluateName ? expression.evaluateName : expression.name;
await focusedSession.setExpression(focusedFrame.frameId, path, value);
if (focusedFrame && (expression instanceof Variable || expression instanceof Expression)) {
await expression.setExpression(value, focusedFrame);
ignoreViewUpdates = true;
this.debugService.getViewModel().updateViews();
ignoreViewUpdates = false;
Expand Down
41 changes: 31 additions & 10 deletions src/vs/workbench/contrib/debug/common/debugModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,16 @@ export class ExpressionContainer implements IExpressionContainer {
}
}

function handleSetResponse(expression: ExpressionContainer, response: DebugProtocol.SetVariableResponse | DebugProtocol.SetExpressionResponse | undefined): void {
if (response && response.body) {
expression.value = response.body.value || '';
expression.type = response.body.type || expression.type;
expression.reference = response.body.variablesReference;
expression.namedVariables = response.body.namedVariables;
expression.indexedVariables = response.body.indexedVariables;
}
}

export class Expression extends ExpressionContainer implements IExpression {
static readonly DEFAULT_VALUE = nls.localize('notAvailable', "not available");

Expand All @@ -212,6 +222,15 @@ export class Expression extends ExpressionContainer implements IExpression {
override toString(): string {
return `${this.name}\n${this.value}`;
}

async setExpression(value: string, stackFrame: IStackFrame): Promise<void> {
if (!this.session) {
return;
}

const response = await this.session.setExpression(stackFrame.frameId, this.name, value);
handleSetResponse(this, response);
}
}

export class Variable extends ExpressionContainer implements IExpression {
Expand Down Expand Up @@ -250,23 +269,25 @@ export class Variable extends ExpressionContainer implements IExpression {
let response: DebugProtocol.SetExpressionResponse | DebugProtocol.SetVariableResponse | undefined;
// Send out a setExpression for debug extensions that do not support set variables https://github.com/microsoft/vscode/issues/124679#issuecomment-869844437
if (this.session.capabilities.supportsSetExpression && !this.session.capabilities.supportsSetVariable && this.evaluateName) {
response = await this.session.setExpression(stackFrame.frameId, this.evaluateName, value);
} else {
response = await this.session.setVariable((<ExpressionContainer>this.parent).reference, this.name, value);
return this.setExpression(value, stackFrame);
}

if (response && response.body) {
this.value = response.body.value || '';
this.type = response.body.type || this.type;
this.reference = response.body.variablesReference;
this.namedVariables = response.body.namedVariables;
this.indexedVariables = response.body.indexedVariables;
}
response = await this.session.setVariable((<ExpressionContainer>this.parent).reference, this.name, value);
handleSetResponse(this, response);
} catch (err) {
this.errorMessage = err.message;
}
}

async setExpression(value: string, stackFrame: IStackFrame): Promise<void> {
if (!this.session || !this.evaluateName) {
return;
}

const response = await this.session.setExpression(stackFrame.frameId, this.evaluateName, value);
handleSetResponse(this, response);
}

override toString(): string {
return this.name ? `${this.name}: ${this.value}` : this.value;
}
Expand Down

0 comments on commit 19eb720

Please sign in to comment.