Skip to content

DAP string rendering removes content quotes and corrupts escaped quote sequences #1992

Closed

Description

@muescha

Summary

For DAP variables with type: "string", the Variables view doesn't show the value text the adapter sent. LSP4IJ strips quote characters from both ends of it and then adds its own " around the rest. The stripping doesn't know about escapes, so quote characters that belong to the string content are lost:

  • different strings look the same ("test", "'test'" and "''test''" are all shown as "test"),
  • non-empty strings look empty ("'" is shown as ""),
  • an escaped quote at the end is cut in half: the " is removed but its \ stays ('"' is shown as "\").

The Set Value editor (F2) isn't affected: it starts with the full value text, so the tree and F2 show different text for the same variable.

How to reproduce

A debug adapter that sends each string value as a complete string literal (double quotes, backslash escapes), for example a JavaScript adapter:

function stringDisplayExample() {
    let plain = "test";
    let singleEdges = "'test'";
    let doubledEdges = "''test''";
    let empty = "";
    let singleOnly = "'";
    let doubleEdges = '"test"';
    debugger;
}
stringDisplayExample();
  1. Debug this file with such an adapter and stop at debugger.
  2. Look at the local variables in the Variables view.
  3. Select doubleEdges and press F2.

The value text below is what the adapter put into Variable.value. In the DAP message this text is JSON-encoded once more; for doubleEdges the wire form is "value": "\"\\\"test\\\"\"".

Variable value text from the adapter Shown in LSP4IJ Expected
plain "test" "test" "test"
singleEdges "'test'" "test" "'test'"
doubledEdges "''test''" "test" "''test''"
empty "" "" ""
singleOnly "'" "" "'"
doubleEdges "\"test\"" "\"test\" "\"test\""

F2 on doubleEdges starts with "\"test\"", which is correct.

Screenshots

Left: the source. Right: the Variables view. Each group is a separate function, so names repeat across groups. First group: different strings look the same. Second group: non-empty strings look empty, and a " content ends up as a lone \. Third group: escaped quotes at the end are shown without their closing "; quotes inside the text are kept.

String values in the Variables view

Columns: source, Variables view, F2 editor. Rows: single (content is one '), double (content is "test" with double quotes), c (content is \"test\" with backslashes and double quotes). In all three rows the F2 editor starts with the complete literal; only the tree is wrong. (The screenshots show the initial editor text, not that each value was set.)

Variables view next to the F2 editor

Cause

In the current code on main (the links are permalinks to the code as of 2026-11-13):

So only the display is changed; the value in the debuggee and the setVariable request aren't.

removeQuotes came with #814 for #812, where vscode-js-debug's 'name' was shown as "'name'". It fixes the outer quotes there, but has the same effect on content quotes with js-debug: in #812's own example, name1 = "name" (sent as 'name') and name3 = "'name'" (sent as "'name'") are both shown as "name".

Expected behavior and a possible fix

Show the value text as the adapter sent it, including its quotes and escapes. The string color can stay.

A possible fix, in DebugAdapterVariableSupport:

  1. formatValue(): drop the string branch that calls removeQuotes(value), so it returns value unchanged for every type.
  2. Remove the private removeQuotes() method; it has no other caller.
  3. getValuePresentation(): for string types, replace new XStringValuePresentation(formattedValue) with an XValuePresentation whose renderValue() calls renderer.renderValue(value, DefaultLanguageHighlighterColors.STRING). That keeps the string color but adds no quotes of its own.

Numbers, booleans and other types stay as they are. The js-debug value from #812 would then be shown as 'name', as it is in VS Code.

It shouldn't unescape the text or try to rebuild a literal from type: "string": LSP4IJ doesn't know the adapter's quoting rules, and the text comes from the adapter. A language-specific DebugAdapterVariableSupport can still override getValuePresentation() if it knows them.

Environment and limits

  • IntelliJ IDEA 2026.3, a local LSP4IJ snapshot, and a local JavaScript debug adapter that sends string values as complete double-quoted literals. Screenshots taken on 2026-11-13.
  • Not run with vscode-js-debug or other adapters; the Single/double quotes displayed not correctly in watch area when debug TypeScript file #812 case above is derived from js-debug's quoting and the removeQuotes code.
  • The "Shown in LSP4IJ" column was checked against the removeQuotes regular expressions and matches the screenshots.

Out of scope here, to keep this to the display: Set Value on lazy variables, on evaluate results and watches, and setExpression.

Claude Code found the cause and wrote this report from the source and the screenshots.

Activity

  1. lagergren commented on Nov 16, 2026

    @lagergren
    Collaborator

    Thanks for the thorough analysis, @muescha. #1994 makes the fix you proposed: a string is shown in the string color exactly as the debug adapter sends it, formatValue() returns the value unchanged, and removeQuotes() is gone. Its tests cover the strings in your table and #812's, and 4 of the 5 fail on main.

  2. added a commit that references this issue on Nov 17, 2026
    048cb4b
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions