Repository navigation
Description
What
The setExpression request is gated by the capability supportsSetExpression. It "evaluates the given value expression and assigns it to the expression which must be a modifiable l-value". frameId is optional. The spec adds: "If a debug adapter implements both setExpression and setVariable, a client uses setExpression if the variable has an evaluateName property."
Why
Adapters that support it:
- debugpy:
src/debugpy/adapter/clients.py:192; pydevd'son_setexpression_requestat:1151. - vscode-js-debug:
debugAdapter.ts:346. It is implemented as an evaluate ofexpr = value(:505-520). - netcoredbg:
vscodeprotocol.cpp:421,:763. - GDB:
dap/evaluate.py:112-113. - MIEngine:
AD7DebugSession.cs:1083,:3316.
All five also advertise supportsSetVariable (clients.py:193, debugAdapter.ts:329, vscodeprotocol.cpp:420, evaluate.py:128, AD7DebugSession.cs:1082).
No: CodeLLDB, lldb-dap, rdbg, java-debug. Delve advertises false.
What users miss: Set Value (F2) on a watch, an Evaluate result or a hover value. These values have no parent variablesReference, so setVariable can't address them; setExpression can. VS Code uses setExpression for watch expressions (debugModel.ts:353-360).
Today
DAPValue.getModifierreturns aDAPValueModifierfor any value that isn't read-only, if the adapter supportssetVariable. That includes evaluate results.DAPDebuggerEvaluatorbuilds the result value with a nullparentVariablesReference. It copies only result, type, variablesReference and the named and indexed counts.DAPValueModifier.setValuepasses thatIntegertoDAPClient.setVariable(String, int, String)(DAPClient.java:1473). For a watch or evaluate result it is null, so unboxing should throw a NullPointerException. This is from reading the code; I did not reproduce it.evaluateNameis not read anywhere in LSP4IJ.
How it could be done
Which request to use: DAPValue.getModifier returns a modifier only if the value isn't read-only, and then:
- Watch or evaluate result (no
parentVariablesReference): only withsupportsSetExpression. It callssetExpressionwith the evaluated expression, whichDAPDebuggerEvaluatoralready stores as the value's name. - Variable with a parent reference: with
supportsSetVariable, usesetVariableas today. Otherwise, withsupportsSetExpressionand anevaluateName, usesetExpression(evaluateName). - Otherwise: no modifier. Never call
setVariablewithout a parent reference.
The spec prefers setExpression whenever there is an evaluateName. VS Code doesn't: for variables it uses setExpression only when the adapter lacks setVariable (debugModel.ts:402-406). This issue follows VS Code to keep today's behaviour for variables; this is an open question.
The request and the answer:
- Arguments:
expression;value = XExpression.getExpression();frameId = stackFrame.getFrameId();format = getValueFormat(), as forsetVariable. - Apply
SetExpressionResponseto the shown variable: value, type, variablesReference (nullable), named and indexed counts, presentationHint, memoryReference, valueLocationReference. Then callcallback.valueModified(). Adapters may sendinvalidated, which LSP4IJ handles since feat: show the debugger's views again on the DAP invalidated event #1766. - For a lazy variable that the user resolved, use the resolved variable's
evaluateName.
IntelliJ API: XValue.getModifier() and XValueModifier.setValue(XExpression, XModificationCallback) exist in both versions. In both, watch nodes are WatchNodeImpl extends XValueNodeImpl, and XSetValueAction asks XValue.getModifier() (bytecode checked). XValue.getModifierAsync() exists only in 2026.3 and is @ApiStatus.Internal; it isn't needed.
Compatibility: with adapters that support setVariable but not setExpression, Set Value disappears from watches and evaluate results instead of throwing. Variables don't change.
Docs: mark SetExpression as supported in DAPSupport.md, and update "Set value" in UserGuide.md.
Test
- Unit test in the style of
DAPValueSetVariableCapabilityTestandDAPValueReadOnlyTest, covering the modifier choice:setVariableonly,setExpressiononly, or both;- an evaluate result or a variable;
- with or without
evaluateName; - read-only.
- Session test with an in-process server that has
supportsSetExpression:- Evaluate through the frame's
XDebuggerEvaluator, then callgetModifier().setValue(...). - Assert that the server got
setExpressionwith expression, value and frameId, and thatvalueModifiedwas called. - With a server that has only
setVariable,getModifier()of an evaluate result must be null. This is the regression test for the NullPointerException.
- Evaluate through the frame's
Effort and risk
Small, low risk. Open question: follow the spec's preference for setExpression strictly?
Activity
fix: Set Value is no longer offered on an Evaluate result (#2123)
feat: set the value of an Evaluate result with the DAP setExpression …
feat: set the value of an Evaluate result with the DAP setExpression …