Skip to content

feat(debug): allow setting values of watch expressions - #18393

Open
KevinGruber2001 wants to merge 4 commits into
eclipse-theia:masterfrom
KevinGruber2001:feat/allow-setting-values-of-variables-in-watch-section
Open

KevinGruber2001 wants to merge 4 commits into
eclipse-theia:masterfrom
KevinGruber2001:feat/allow-setting-values-of-variables-in-watch-section

Conversation

@KevinGruber2001

@KevinGruber2001 KevinGruber2001 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

What it does

Adds a "Set Value" context menu action to the Watch view. It is shown when the debug adapter supports setExpression and is disabled when the expression is unavailable or the adapter marks the result as readOnly. The new value is sent with a setExpression request in the current frame. The expression is then re-evaluated and the frame's cached scopes are dropped, so the Variables view shows the new value too.

The input dialog and the readOnly check move from DebugVariable up to ExpressionContainer so both the Variables view and the Watch view use them.

How to test

  1. Debug a program with an adapter that supports setExpression (e.g. the built-in JS debugger).
  2. Pause at a breakpoint and add a watch expression for a local variable.
  3. Right-click the watch expression and choose "Set Value", then enter a new value.
  4. The watch expression and the variable in the Variables view show the new value. Continuing execution uses it.
  5. Entering an invalid value shows the adapter's error message in the dialog.

Follow-ups

None

Breaking changes

  • This PR introduces breaking changes and requires careful review. If yes, the breaking changes section in the changelog has been updated.

Review checklist

Reminder for reviewers

@github-actions

Copy link
Copy Markdown
Contributor

Hi @KevinGruber2001,

Thanks for your pull request! This is how we review it:

  1. A committer (the PR steward) checks whether the approach fits.
  2. If the approach fits, the steward may request an AI review. Fix or answer each finding. You cannot request a new AI review yourself, so comment on the PR when you are done and the steward requests the next round. The AI review approves once each finding is fixed or answered. This approval does not count for merging.
  3. The steward requests a review from a maintainer. Address the requested changes and re-request the review. The PR is merged after the approval of a maintainer.

See the review flow for details.

@sdirix sdirix linked an issue Nov 17, 2026 that may be closed by this pull request
@KevinGruber2001
KevinGruber2001 marked this pull request as ready for review November 18, 2026 09:27
@ndoschek ndoschek moved this from In review to Needs Classification in PR Review Flow Nov 18, 2026
@ndoschek ndoschek moved this to Waiting on reviewers in PR Review Flow Nov 18, 2026
@ndoschek

Copy link
Copy Markdown
Member

@EclipseSourceAI

@EclipseSourceAI EclipseSourceAI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

Autonomous AI review. May contain mistakes.

Useful comment? React 👍. Disagree? React 👎 to reject it for follow-up reviews. A reply explaining why helps too.

Agent approval means no blocking issues found. Unrelated and Follow-up comments are non-blocking. A maintainer must still sign off.

Only a maintainer can re-request a review from this agent.

Powered by Eclipse Enclave via review-guard-mcp

Issues Follow-ups Unrelated
1 1 0
Summary

The PR adds a "Set Value" item (debug.watch.setValue) to the Watch view's context menu. It is visible when the adapter supports setExpression, and disabled when the expression is unavailable or readOnly.

  • DebugWatchExpression.setValue sends setExpression in the current frame and then re-evaluates the expression. It also drops the frame's cached scopes through the new DebugStackFrame.forgetScopes() and fires a session change.
  • The input dialog and the readOnly getter move from DebugVariable to ExpressionContainer, so the Variables view and the Watch view share them.

Checks:

  • npm ci && npm run build:browser succeeds.
  • The new debug-watch-expression.spec.ts (6 tests) and the existing console specs pass.
  • ESLint reports nothing on the changed files.

UI check in the browser app with ms-vscode.js-debug:

  • On an available watch, the menu item shows and is enabled. On an unavailable watch (doesNotExist), it shows but is disabled.
  • The dialog opens prefilled with the current value. After submitting, the watch shows the new value, and the debuggee uses it after continuing (counter is 77 ... local is 9).
Notes for maintainers
  • Variables view still shows the old value with js-debug. This contradicts step 4 of the PR's test instructions. After a watch Set Value, the view kept the value from the pause, both for a Local variable and for a Closure variable. That held even when a scope was expanded for the first time after the set.
    • On the Theia side the scopes are re-fetched: forgetScopes() runs, and the tree refreshes expanded nodes.
    • js-debug caches the scope variable containers per pause (_scopeVariable stores them in t.variables[e]). That cache looks like the source of the stale values.
    • So this looks like adapter behavior rather than a bug in this PR. A maintainer could confirm whether VS Code behaves the same with js-debug, and the PR description should not promise this behavior.
  • Child variables of a watch expression (the expanded nodes in the Watch view) still cannot be set. Only top-level watch expressions get the new item.
  • Not tested: Electron, and adapters other than js-debug.

Comment on lines +111 to +114
await session.sendRequest('setExpression', { expression: this.expression, value, frameId: frame.raw.id });
await this.evaluate();
frame.forgetScopes();
session['fireDidChange']();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

session['fireDidChange']() already re-evaluates every watch expression through the view model (session manager, refreshWatchExpressions), so the explicit await this.evaluate() sends a second evaluate for this expression. The setExpression response already carries value, type, variablesReference etc., so apply it with setResult like DebugVariable.setValue does with the setVariable response (link).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, i removed now the second evaluate function, and apply the response from setExpression directly via setResult

@ndoschek
ndoschek requested review from EclipseSourceAI and removed request for EclipseSourceAI November 20, 2026 12:09

@EclipseSourceAI EclipseSourceAI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

Autonomous AI review. May contain mistakes.

Useful comment? React 👍. Disagree? React 👎 to reject it for follow-up reviews. A reply explaining why helps too.

Agent approval means no blocking issues found. Unrelated and Follow-up comments are non-blocking. A maintainer must still sign off.

Only a maintainer can re-request a review from this agent.

Powered by Eclipse Enclave via review-guard-mcp

Issues Follow-ups Unrelated Fixed since last review Still open from last review
0 0 0 1 0
Changes since last review

Since the last review (commit 0dcf5444c), the only substantive change is commit 32c43bc1f ("apply setExpression response instead of re-evaluating watch"), plus a merge of origin/master that brought in unrelated upstream commits (no conflicts touching this PR's files).

DebugWatchExpression.setValue now maps the setExpression response body directly into setResult({ result: response.body.value, type, variablesReference, namedVariables, indexedVariables, presentationHint }) instead of awaiting a redundant evaluate(). This reuses ExpressionItem.setResult, which sets _value/_type/_available/variablesReference/etc. and clears the cached elements for re-expansion, exactly like a fresh evaluate response would.

  • Double evaluate / use setResult with the setExpression response: fixed. setValue no longer calls this.evaluate(); it applies the setExpression response via setResult directly, matching the suggested approach.

Verified:

  • npm ci && npm run build:browser: succeeds (0 errors, browser + node bundles built).
  • tsc --build in packages/debug: succeeds.
  • nyc mocha for debug-watch-expression.spec.ts and the console specs: 25/25 passing.
  • eslint on the changed file: clean.
Notes for maintainers

The remaining open note from the last review (Variables view keeping a stale value after Set Value with ms-vscode.js-debug, likely caused by the adapter caching scope variable containers per pause) wasn't re-tested this round since nothing changed in that area; it's still worth a maintainer's confirmation against VS Code's own behavior before merging, but it looked like adapter behavior rather than a bug in this PR.

Suggested squash commit message

feat(debug): allow setting values of watch expressions

These previous comments can be resolved as they are now handled:

I can't resolve them myself as I would need write permission on this repository.

@ndoschek
ndoschek requested a review from sdirix November 24, 2026 17:52

@sdirix sdirix left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#16069 also asks for Set Value on struct members, i.e. the expanded children of a watch expression.

Can either be handled here or in a follow up.

if (!this.supportSetExpression || !this.available || this.readOnly) {
return;
}
await this.openSetValueDialog(nls.localizeByDefault('Set Value'), this.value, value => this.setValue(value));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: The Variables view dialog names the variable. We could reuse the key with the expression:

Suggested change
await this.openSetValueDialog(nls.localizeByDefault('Set Value'), this.value, value => this.setValue(value));
await this.openSetValueDialog(nls.localize('theia/debug/debugVariableInput', 'Set {0} Value', this.expression), this.value, value => this.setValue(value));

Do you want to adapt this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes looks good, i will add it in the next commit

@github-project-automation github-project-automation Bot moved this from Waiting on reviewers to Needs merge in PR Review Flow Nov 26, 2026
@KevinGruber2001

Copy link
Copy Markdown
Contributor Author

Struct members where already changeable on double click, I added now the Set Value element to

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Needs merge

Development

Successfully merging this pull request may close these issues.

Debug: Allow setting values of variables in Watch section

4 participants