Skip to content

DAP: support the setExpression request #2109

Done

Description

@lagergren

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's on_setexpression_request at :1151.
  • vscode-js-debug: debugAdapter.ts:346. It is implemented as an evaluate of expr = 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.getModifier returns a DAPValueModifier for any value that isn't read-only, if the adapter supports setVariable. That includes evaluate results.
  • DAPDebuggerEvaluator builds the result value with a null parentVariablesReference. It copies only result, type, variablesReference and the named and indexed counts.
  • DAPValueModifier.setValue passes that Integer to DAPClient.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.
  • evaluateName is 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 with supportsSetExpression. It calls setExpression with the evaluated expression, which DAPDebuggerEvaluator already stores as the value's name.
  • Variable with a parent reference: with supportsSetVariable, use setVariable as today. Otherwise, with supportsSetExpression and an evaluateName, use setExpression(evaluateName).
  • Otherwise: no modifier. Never call setVariable without 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 for setVariable.
  • Apply SetExpressionResponse to the shown variable: value, type, variablesReference (nullable), named and indexed counts, presentationHint, memoryReference, valueLocationReference. Then call callback.valueModified(). Adapters may send invalidated, 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 DAPValueSetVariableCapabilityTest and DAPValueReadOnlyTest, covering the modifier choice:
    • setVariable only, setExpression only, 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 call getModifier().setValue(...).
    • Assert that the server got setExpression with expression, value and frameId, and that valueModified was called.
    • With a server that has only setVariable, getModifier() of an evaluate result must be null. This is the regression test for the NullPointerException.

Effort and risk

Small, low risk. Open question: follow the spec's preference for setExpression strictly?

Activity

  1. added
    enhancement
    dap
    on Nov 22, 2026
  2. added this to the 0.30.2 milestone on Nov 23, 2026
  3. added a commit that references this issue on Nov 23, 2026
    2935139
  4. added a commit that references this issue on Nov 24, 2026
    bc3c8bd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    dapenhancement

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions