Repository navigation
fix: the debug console of a DAP session no longer shows the debug adapter's telemetry output - #2199
Conversation
…pter's telemetry output DAP's output event says of the category 'telemetry': "Send the output to telemetry instead of the client". VS Code doesn't show it either. LSP4IJ printed it in the debug console, as debug output, so usage data in JSON, which some debug adapters send, showed up among the program's output. DAPClient.output now skips output events of the category 'telemetry' and logs them at DEBUG, for whoever diagnoses a debug adapter. The other categories are printed as before. Fixes redhat-developer#2197
|
@coderabbitai review |
Action not completed
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2199 +/- ##
==========================================
- Coverage 54.23% 54.23% -0.01%
==========================================
Files 832 832
Lines 35334 35337 +3
Branches 7286 7287 +1
==========================================
+ Hits 19163 19164 +1
+ Misses 13348 13341 -7
- Partials 2823 2832 +9 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@coderabbitai review |
Action not completed
|
|
@coderabbitai review |
Action performed
|
…p, as console.group() gives (#2198) Part of #2167: the indentation. Folding a group in the console is left for later. ## What The DAP `output` event has an optional `group`, which `console.group()` and `console.groupCollapsed()` give, for instance: - `start` begins a group; - `startCollapsed` begins a collapsed one; - `end` ends the current group. LSP4IJ's debug console printed grouped output flat, with the group headers looking like any other line. ## Change New package-private `DAPOutputGroups`, one per `DAPClient`, so each session of a `startDebugging` tree has its own groups. `DAPClient.output` prints `outputGroups.indent(args)` instead of the event's text, and nothing else in it changes. - **Indentation:** each line of a group is indented 2 spaces per nesting level, as Node.js indents `console.group()` in a terminal. VS Code indents its tree in pixels, so it has no space count to copy. - **`start` and `startCollapsed`:** the event's text is the group's header, on its own line at the current level. Then the level goes up. - **`end`:** the level goes down, never below 0, and the end's text, if any, is printed at the outer level, as DAP and VS Code do. - **Line starts:** the indent goes at the start of each line, not each chunk, so a line sent in pieces is indented once. An empty line gets no trailing spaces. A `\r` also counts as a line start, so a progress line that rewrites itself stays indented. - **Groups on their own lines:** a group starts and ends on its own line. If the output so far stopped mid-line, a newline is added first. - **Telemetry output never reaches the groups.** Since #2199, `DAPClient.output` drops it first, as VS Code does. `DAPOutputGroups` itself passes it through unchanged. - **Docs:** the Output line in `docs/dap/DAPSupport.md` (merged with #2199's line about telemetry) describes the indentation, that each session has its own groups, and that folding isn't supported yet, so a `startCollapsed` group shows expanded. Not in this PR: - **Folding,** which IntelliJ's console doesn't offer for dynamic ranges. - **Interleaved partial lines:** child sessions share the root's console, so if two sessions interleave partial lines, an indent can land in the wrong place. Getting that exact would mean indenting under the console's lock in `DAPDebugProcess.printText`. ## Tests - New `DAPOutputGroupsTest` (JUnit 5, 14 tests): - nesting, `startCollapsed`, an `end` below 0, and the text of an `end`; - chunked lines, multi-line text with an empty line and CRLF, a multi-line header, and `\r`; - a group that starts or ends mid-line, an empty header, and telemetry. - New `DAPOutputGroupsSessionTest` (2 tests, an in-process debug adapter on a loopback socket): - nested groups, chunks and multi-line output in the console's text; - a root and a child session started with `startDebugging` don't share their group levels. - **Red-green:** without the `DAPClient` change, both session tests fail, since the block prints flat. With it, all 16 pass, also headless. - The `dap.*` tests pass on IC 2024.2, 2025.3 and IU 2026.3: 473 each, with 0 failures or skipped. ## Behaviour change | Before | After | |---|---| | The output of a group prints flat, with its header like any other line | Each line of a group is indented 2 spaces per nesting level. The header is at the level where the group starts, and the text of an `end` at the outer level. Each session has its own groups |
…e debug adapter's output, which it now asks for with supportsANSIStyling (#2200) Fixes #2169 ## What The debug console of a DAP session printed `output` events as they came. ANSI escape sequences, which programs and debug adapters use for colours and bold, showed as raw codes such as `ESC[31mred ESC[0m`. LSP4IJ also didn't send the client capability `supportsANSIStyling` in `initialize`, so an adapter that honours it, such as vscode-js-debug, could leave styles out. ## Change - **New `DAPOutputDecoder`** (`dap/console`) decodes an `output` event's text with IntelliJ's `AnsiEscapeDecoder`, as a `ColoredProcessHandler` console does. It returns chunks of text without the escape codes, each with its console content type: - **Unstyled text** keeps its category's content type, the same mapping as before: stderr red, important verbose, everything else info. The mapping moved here from `DAPClient`. - **Styled text** gets the content type that `AnsiEscapeDecoder` and `ColoredOutputTypeRegistry` give it, as in a process console. - **One decoder per category:** a missing or unknown category counts as console, as DAP says. stderr is decoded as STDERR and the other categories as STDOUT, since the decoder only handles those two. So a style, or a sequence split across events, continues into the next event of the same category, and doesn't leak into another one. - **`DAPClient`:** each client has its own decoder, so each session of a `startDebugging` tree has its own. `output` prints the decoded chunks. - **`DAPDebugProcess.printOutput(List<Chunk>)`** prints an event's chunks together under `consoleLock`, so that no other session's text lands between them. The existing `printOutput(String, ConsoleViewContentType)` is unchanged. - **`DebugAdapterDescriptor.createInitializeRequestArguments`** sends `supportsANSIStyling: true`. - **Docs:** the Output line of `docs/dap/DAPSupport.md` names the capability and the behaviour. #2198 (output groups) and #2199 (telemetry) are merged, and this PR is rebased on them. `DAPOutputGroups`, its `outputGroups.indent(args)` and the telemetry check were already on main at the base. This PR passes the indented text through the decoder: `outputDecoder.decode(outputGroups.indent(args), args.getCategory())`. Not in this PR: - A bold-only span on stderr is bold in the default foreground, not bold red, as in a process console. - If a session ends inside an escape sequence, the leftover is dropped. ## Tests New `DAPOutputAnsiStylingSessionTest` (6 tests, a `HeavyPlatformTestCase` with an in-process debug adapter on a loopback socket). It reads the console text, and the content type of each character from the document's markup. - `initialize` carries `supportsANSIStyling: true`. - `\^[[31mred\^[[0m plain` shows `red plain`, with `red` in the scheme's red and ` plain` as info, and no escape character. - The colour of a group's output shows where the group indents it (after the rebase on #2198). - An escape sequence split over two events, whose colour runs into a third, shows `green done` in green. - On stderr, bold text is bold, and unstyled text stays `LOG_ERROR_OUTPUT`. - A stdout colour doesn't carry into console output. Red-green: - Without the change, the first 5 tests fail: `supportsANSIStyling` is null, and the console shows the raw codes. The group test was added later, with the rebase on #2198. With the change, all 6 pass, also headless. - With one decoder shared by all categories, only the last test fails, so it guards the one-decoder-per-category rule. The `dap.*` tests pass on IC 2024.2, 2025.3 and IU 2026.3: 462 each, with 0 failures or skipped. Rebased on main at d8c7551, they pass again, also headless: 518 tests, 0 failures. ## Behaviour change | Before | After | |---|---| | The debug console shows ANSI escape codes as raw text, and `initialize` doesn't send `supportsANSIStyling` | It shows the colours and bold without the codes, keeping the category's colour for unstyled text, and `initialize` sends `supportsANSIStyling: true` |
Fixes #2197
What
The debug console of a DAP session printed the output events of the category
telemetry. DAP'soutputevent says of it: "Send the output to telemetry instead of the client." VS Code doesn't show it either. Some debug adapters send usage data in JSON this way, which then showed up among the program's output.Change
DAPClient.outputskips an output event of the categorytelemetry(new staticisTelemetry). It logs the event at DEBUG underDAPClient's logger, for whoever diagnoses a debug adapter.getContentTypeloses its now unreachabletelemetrycase.docs/dap/DAPSupport.md: the Output line says that telemetry isn't shown.#2198 (output groups) and the coming PR for #2169 (ANSI colours) also change
DAPClient.output. Whichever merges later is rebased.Tests
DAPOutputCategorySessionTest, aHeavyPlatformTestCasewith an in-process debug adapter on a loopback socket, built likeDAPProcessEventSessionTest. The adapter sends atelemetry, aconsoleand astdoutoutput event. The console shows the last two, but not the telemetry.{"event":"usage"}. With it, it passes, also headless.Behaviour change
telemetryoutput