Skip to content

feat: the debug console of a DAP session shows the ANSI colours of the debug adapter's output, which it now asks for with supportsANSIStyling - #2200

Merged
lagergren merged 2 commits into
redhat-developer:mainfrom
lagergren:feat/dap-console-ansi
Nov 24, 2026

Conversation

@lagergren

@lagergren lagergren commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

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 feat: the debug console of a DAP session indents the output of a group, as console.group() gives #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:

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

@lagergren lagergren added this to the 0.30.2 milestone Nov 24, 2026
@lagergren lagergren added the enhancement New feature or request label Nov 24, 2026
@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • New Features
    • Debug console output now displays ANSI formatting, including colors and bold text, when supported by the debug adapter. Formatting can continue across consecutive output events, while unstyled text retains its category color. Output categories remain distinct, and formatting resets are reflected in the console.
  • Documentation
    • Updated the DAP support guide to describe ANSI styling behavior in debug console output.

The DAP client now advertises ANSI styling support and decodes output events into console chunks. The debug console prints each chunk with its associated content type. Integration tests cover styling, category handling, and split ANSI sequences.

Changes: DAP ANSI Output Styling

Layer / File(s) Summary
Decode output by category
src/main/java/com/redhat/devtools/lsp4ij/dap/console/DAPOutputDecoder.java
Adds decoded text chunks with console content types. The decoder retains ANSI state per normalized output category.
Advertise and print styled output
src/main/java/com/redhat/devtools/lsp4ij/dap/descriptors/DebugAdapterDescriptor.java, src/main/java/com/redhat/devtools/lsp4ij/dap/client/DAPClient.java, src/main/java/com/redhat/devtools/lsp4ij/dap/DAPDebugProcess.java, docs/dap/DAPSupport.md
Enables ANSI styling in initialize arguments. Routes output events through the decoder and prints decoded chunks in the debug console. Documents the output behavior.
Test ANSI output in a debug session
src/test/java/com/redhat/devtools/lsp4ij/dap/client/DAPOutputAnsiStylingSessionTest.java
Adds session tests for styling, category handling, split ANSI sequences, output groups, and capability negotiation.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant DAPAdapter
  participant DAPClient
  participant DAPOutputDecoder
  participant DAPDebugProcess
  DAPAdapter->>DAPClient: Send output event
  DAPClient->>DAPOutputDecoder: Decode text by category
  DAPOutputDecoder-->>DAPClient: Return styled chunks
  DAPClient->>DAPDebugProcess: Print decoded chunks
Loading

Suggested reviewers: angelozerr

Merge Risk: Minimal · up to 30f2d

This change decodes ANSI styling in debug-console output and advertises support for it to debug adapters. No concrete merge-blocking risk was identified, and the PR reports passing tests.

Pre-merge checks: Passed 3 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Out of Scope Changes check Inconclusive The decoder, the DAPDebugProcess chunk printer, the capability in DebugAdapterDescriptor, the docs line, and the session test all support #2169. The category mapping moved from DAPClient into DAPOutpu… Provide the whole-PR diff of src/main/java/com/redhat/devtools/lsp4ij/dap/client/DAPClient.java and src/test/java/com/redhat/devtools/lsp4ij/dap/client/DAPOutputAnsiStylingSessionTest.java against the merge base, so the reviewer can confirm…
Passed Passed checks: 3 passed

Check name Status Explanation
Title check Passed The title names the main change: the DAP debug console now shows ANSI colours from the adapter's output, and LSP4IJ advertises supportsANSIStyling to request them. This matches the changeset, which ad…
Linked Issues check Passed Issue #2169 has two coding requirements. (1) Decode ANSI escape sequences in debug-console output with IntelliJ's AnsiEscapeDecoder, as run consoles do. DAPOutputDecoder.decode at the reviewed head ca…
Description check Passed The description explains the problem (raw ANSI escape codes in DAP debug console output, missing supportsANSIStyling capability), the new DAPOutputDecoder, the DAPClient and DAPDebugProcess changes, t…
Full details: Title check

Explanation

The title names the main change: the DAP debug console now shows ANSI colours from the adapter's output, and LSP4IJ advertises supportsANSIStyling to request them. This matches the changeset, which adds DAPOutputDecoder, per-client decoders, printOutput(List<Chunk>), and the supportsANSIStyling initialize argument. The title is long (141 characters) and could be shorter, but it is specific and accurate.

Full details: Linked Issues check

Explanation

Issue #2169 has two coding requirements. (1) Decode ANSI escape sequences in debug-console output with IntelliJ's AnsiEscapeDecoder, as run consoles do. DAPOutputDecoder.decode at the reviewed head calls AnsiEscapeDecoder.escapeText, keeps one decoder per normalized category, and returns Chunk(text, contentType) values without escape codes. Unstyled text keeps the category content type. (2) Send supportsANSIStyling: true in initialize. The previous assessment read DebugAdapterDescriptor.createInitializeRequestArguments, which calls args.setSupportsANSIStyling(true). The PR summary states that DAPClient.output prints the decoded chunks through DAPDebugProcess.printOutput(List<Chunk>). The DAPClient diff could not be read at this review, so that wiring rests on the PR summary and the author's description. The session test results (5 tests, dap.* suites) are author-reported and were not run here.

Full details: Description check

Explanation

The description explains the problem (raw ANSI escape codes in DAP debug console output, missing supportsANSIStyling capability), the new DAPOutputDecoder, the DAPClient and DAPDebugProcess changes, the initialize argument change, docs, and tests. It is directly related to the changeset.

Full details: Out of Scope Changes check

Explanation

The decoder, the DAPDebugProcess chunk printer, the capability in DebugAdapterDescriptor, the docs line, and the session test all support #2169. The category mapping moved from DAPClient into DAPOutputDecoder and keeps its earlier behaviour. Two points remain unresolved. First, the change summary says DAPClient now indents output using outputGroups, and the PR description places output groups in #2198, not in this PR. The DAPClient diff was unavailable, so it is not known whether this indentation already exists at the merge base or was introduced here. Second, the change summary describes test cases for output-group indentation and style reset that the PR description does not list (it lists 5 tests). The test file blob was not read to confirm which cases exist. The PR description's two stated exclusions are not requirements of #2169.

Resolution

Provide the whole-PR diff of src/main/java/com/redhat/devtools/lsp4ij/dap/client/DAPClient.java and src/test/java/com/redhat/devtools/lsp4ij/dap/client/DAPOutputAnsiStylingSessionTest.java against the merge base, so the reviewer can confirm whether the outputGroups indentation and the extra test cases were introduced by this PR or already exist at the base. If they belong to #2198, remove them from this PR or confirm that the base already contains them.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 465157b8-9f6b-4f59-bc78-f0d360a50713
Commits

Reviewing files that changed from the base of the PR and between 65e42e2 and 30f2d62.

Files selected for processing: 4

  • docs/dap/DAPSupport.md
  • src/main/java/com/redhat/devtools/lsp4ij/dap/client/DAPClient.java
  • src/main/java/com/redhat/devtools/lsp4ij/dap/console/DAPOutputDecoder.java
  • src/test/java/com/redhat/devtools/lsp4ij/dap/client/DAPOutputAnsiStylingSessionTest.java
Files skipped from review as they are similar to previous changes: 1

  • docs/dap/DAPSupport.md

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

@codecov

codecov Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 55.00%. Comparing base (19079c9) to head (30f2d62).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
.../devtools/lsp4ij/dap/console/DAPOutputDecoder.java 78.26% 2 Missing and 3 partials ⚠️
...om/redhat/devtools/lsp4ij/dap/DAPDebugProcess.java 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2200      +/-   ##
==========================================
+ Coverage   54.98%   55.00%   +0.02%     
==========================================
  Files         837      838       +1     
  Lines       35510    35533      +23     
  Branches     5556     7329    +1773     
==========================================
+ Hits        19524    19546      +22     
+ Misses      13132    13128       -4     
- Partials     2854     2859       +5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…e debug adapter's output, which it now asks for with supportsANSIStyling

The debug console printed the output of the DAP 'output' events as it came, so ANSI escape sequences, such as those
of a program that colours its logs, showed as raw escape codes. It now decodes them with IntelliJ's
AnsiEscapeDecoder, as a run console does, and says so to the debug adapter with `supportsANSIStyling: true` in
`initialize`.

- DAPOutputDecoder decodes an event's output into chunks with a console content type each. Text without an ANSI
  style keeps the content type of its category, as before: stderr red, important verbose, telemetry debug, and the
  rest info. Text with a style gets the content type that AnsiEscapeDecoder and ColoredOutputTypeRegistry give it,
  as in a ColoredProcessHandler console.
- A DAPClient has one decoder per output category, so a style that starts in one event, or an escape sequence that
  an event splits, continues in the next event of the same category, and doesn't leak into another category or
  another session of a startDebugging tree. A missing or unknown category is console's, as the DAP specification says.
- DAPDebugProcess.printOutput(List<Chunk>) prints an event's chunks together under the console lock, so no other
  text comes between them. printOutput(String, ConsoleViewContentType) stays.
- docs/dap/DAPSupport.md: the Output event lists supportsANSIStyling.

Fixes redhat-developer#2169
…hows the ANSI styles of the output without the escape sequences

DAPOutputAnsiStylingSessionTest attaches a debug session to a DAP server in the test's process, on a loopback socket,
and reads the console's text and the content types of its editor markup:

- the arguments of 'initialize' have supportsANSIStyling: true;
- "\u001b[31mred\u001b[0m plain" on stdout shows "red plain", "red" in the ANSI red, " plain" as stdout;
- an escape sequence split over two events, and a colour over two more, are decoded;
- stderr text without a style stays LOG_ERROR_OUTPUT, and a bold one is bold;
- a style of stdout doesn't continue in the console category.
@lagergren
lagergren force-pushed the feat/dap-console-ansi branch from 65e42e2 to 30f2d62 Compare November 24, 2026 18:29
@lagergren

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@lagergren

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@lagergren

Copy link
Copy Markdown
Collaborator Author

@coderabbitai, about the inconclusive Out of Scope Changes check, here is the diff you asked for, against the merge base 19079c9.

DAPClient.java: the whole diff is these three hunks.

  • It adds the import of DAPOutputDecoder.
  • It adds a field: private final DAPOutputDecoder outputDecoder = new DAPOutputDecoder();
  • In output(...), debugProcess.printOutput(outputGroups.indent(args), getContentType(args.getCategory())); becomes debugProcess.printOutput(outputDecoder.decode(outputGroups.indent(args), args.getCategory()));.
  • It removes getContentType(String), whose mapping moved to DAPOutputDecoder.

The outputGroups field, DAPOutputGroups and indent(args) are already at the base. They came with #2198, which is merged, so this PR doesn't introduce the group indentation; it only decodes the indented text.

DAPOutputAnsiStylingSessionTest.java: a new file, with 6 tests:

  • testTheInitializeRequestSaysThatTheClientSupportsAnsiStyling
  • testTheConsoleShowsTheColourOfTheOutputWithoutItsEscapeSequences
  • testTheColourOfTheOutputOfAGroupIsShownWhereTheGroupIndentsIt
  • testAnEscapeSequenceWhichAnOutputEventSplitsIsDecodedWithTheNextEvent
  • testTheStderrOutputKeepsItsContentTypeWhereItHasNoAnsiStyle
  • testAStyleOfOneCategoryDoesNotContinueInAnother

The group test was added when this PR was rebased on #2198. It checks that a colour shows correctly in indented group output, which is this PR's decoding. I've updated the description to list it, so it now lists all 6 tests.

@coderabbitai

coderabbitai Bot commented Nov 24, 2026

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

Analysis chain

Script executed:

#!/bin/bash
set +e
echo "=== Checkout ==="
git rev-parse HEAD
git status --short
echo "=== PR metadata ==="
gh pr view 2200 --repo redhat-developer/lsp4ij --json baseRefOid,headRefOid,body,updatedAt --jq '{baseRefOid, headRefOid, updatedAt, body}'
echo "=== Merge-base availability and comparison ==="
git rev-parse --verify '19079c91^{commit}'
git diff --stat 19079c91 HEAD -- src/main/java/com/redhat/devtools/lsp4ij/dap/client/DAPClient.java src/test/java/com/redhat/devtools/lsp4ij/dap/client/DAPOutputAnsiStylingSessionTest.java
git diff 19079c91 HEAD -- src/main/java/com/redhat/devtools/lsp4ij/dap/client/DAPClient.java
echo "=== Base output group usage ==="
git show 19079c91:src/main/java/com/redhat/devtools/lsp4ij/dap/client/DAPClient.java | rg -n -C3 'outputGroups|void output\('
echo "=== Current source outlines ==="
ast-grep outline src/main/java/com/redhat/devtools/lsp4ij/dap/client/DAPClient.java --items all --match 'output|outputDecoder'
ast-grep outline src/test/java/com/redhat/devtools/lsp4ij/dap/client/DAPOutputAnsiStylingSessionTest.java --items all
echo "=== Test source ==="
cat -n src/test/java/com/redhat/devtools/lsp4ij/dap/client/DAPOutputAnsiStylingSessionTest.java

Length of output: 30889


@lagergren Thanks for the details. I checked the diff against 19079c91 and the current PR description.

  • DAPClient already used outputGroups.indent(args) at the base. This PR adds ANSI decoding after indentation.
  • The new test file has six tests. The group test checks ANSI decoding in indented output, so it is in scope. The colour and split-sequence tests also check style reset.
  • The description lists all six tests. Its red-green section still says “all 5”; please clarify if that refers to an earlier run.

I consider the out-of-scope concern resolved by this evidence. I did not run the tests or update the saved pre-merge check.

You are interacting with an AI system.

@lagergren
lagergren merged commit c46480d into redhat-developer:main Nov 24, 2026
11 checks passed
lagergren added a commit that referenced this pull request Nov 25, 2026
… to the source location that the debug adapter gives it (#2220)

Fixes #2166

## What

A DAP `output` event can carry the source location the output comes from: `source`, `line`, `column`, and since DAP 1.68 `locationReference`. VS Code shows it as a link next to the output line. LSP4IJ's `DAPClient.output` used only `category` and `output`, so the location was dropped.

## Change

- **`DAPClient.output`** keeps its order: skip telemetry, indent groups (#2198), decode ANSI (#2200). If the event has a location, it prints the decoded chunks followed by a link.
- **`DAPDebugProcess.printOutput(List<Chunk>, String, HyperlinkInfo)`**, a new overload, prints the output under `consoleLock` in this order:
  - the chunks, without the trailing line end;
  - a space;
  - the link, with `ConsoleView.printHyperlink`;
  - the line end.

  So the link stays on the output's line, right after it, with no other session's text in between. An output without a location, or without visible text, prints exactly as before.
- **Link text:** `name:line`, e.g. `app.js:12`, for a `source` with a `line`, as VS Code shows it. "Jump to Value Source" for a `locationReference` alone, since its location is unknown until it's resolved.
- **New `DAPOutputLocation`** (package-private `HyperlinkInfo`) resolves the location only when the link is clicked, off the EDT:
  - **`source` + `line`:** a `path` opens the local file at the line and column. A `sourceReference` loads its text, as stack frames do (`DAPFileRegistry`, `DAPSourceReferencePosition`), and opens it if the text loaded.
  - **`locationReference`:** resolved with the `locations` request (#2115), within the execution epoch of the output, because DAP gives it the lifetime of a `variablesReference`. Once the program has stopped or resumed since the output, the click reports that the reference is out of date and sends nothing.
  - **Both kinds present:** `source` + `line` wins, and one link is printed.
  - **Errors:** a failure is reported with a warning, as Jump to Value Source does. This covers the adapter's error, no location, an unopenable source, a stale reference, or an ended session. After the session ends, a `sourceReference` or `locationReference` link is reported, not sent. A `path` link still opens.
- **`DAPLocations`** is now public, with public `getSource`, `getSourcePosition`, `hasSourceReference` and a new `canBeOpened(Source)`. This adds API and breaks none.
- **Docs:** the Output line of `docs/dap/DAPSupport.md`.

Not in this PR:
- An output without a trailing line end gets the link at its end, so the next output continues after the link on the same line.
- A `startDebugging` child session that has ended while its parent still runs isn't recognized as ended. The check uses the shared `XDebugSession`.

## Tests

New `DAPOutputLocationSessionTest`, 7 tests with an in-process debug adapter. Every wait is bounded and has a message.
- A `path` gives the line `set up handlers.js:3`. The link covers only its text and opens the file at (2,21).
- A `sourceReference` makes the adapter receive `source` for reference 11, and `generated.js` opens with its text at (1,16).
- A `locationReference` sends no `locations` request until the click. Then it opens the file at (2,21).
- A `locationReference` clicked after a `continued` event is reported as out of date, and no request is sent.
- After the session ends, the `sourceReference` link is reported, and the `path` link still opens.
- An event without a location prints `plain` with no link.
- A group with ANSI red gives `  red handlers.js:3`, still indented and red, with the link after it.

Red-green: with `DAPClient.output` as on main, 5 tests fail (e.g. `expected:<set up[ handlers.js:3]> but was:<set up[]>`). The no-location test passes either way, as it guards against a regression. With the change, all 7 pass.

The new class passes headless on IC 2024.2, 2025.3 and IU 2026.3. The `dap.*` tests pass on all three: 525 tests each, with 0 failures or skipped.

## Behaviour change

| Before | After |
|---|---|
| The debug console dropped an `output` event's `source`, `line`, `column` and `locationReference`, and showed only the text | The console shows a link after the text, on its line. `app.js:12` opens the local file, or the text of the `sourceReference`, at that line and column. "Jump to Value Source" for a `locationReference` asks `locations` when clicked, while the program hasn't stopped or resumed since. An output without a location prints as before |
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DAP: decode ANSI colours in the debug console, and tell the debug adapter with supportsANSIStyling

1 participant