Repository navigation
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
Conversation
Codecov Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
…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.
65e42e2 to
30f2d62
Compare
|
@coderabbitai review |
Action not completed
|
|
@coderabbitai review |
Action performed
|
|
@coderabbitai, about the inconclusive Out of Scope Changes check, here is the diff you asked for, against the merge base 19079c9.
The
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. |
|
Tip For best results, initiate chat on the files or code changes. Analysis chain
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. |
… 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 |
Fixes #2169
What
The debug console of a DAP session printed
outputevents as they came. ANSI escape sequences, which programs and debug adapters use for colours and bold, showed as raw codes such asESC[31mred ESC[0m. LSP4IJ also didn't send the client capabilitysupportsANSIStylingininitialize, so an adapter that honours it, such as vscode-js-debug, could leave styles out.Change
DAPOutputDecoder(dap/console) decodes anoutputevent's text with IntelliJ'sAnsiEscapeDecoder, as aColoredProcessHandlerconsole does. It returns chunks of text without the escape codes, each with its console content type:DAPClient.AnsiEscapeDecoderandColoredOutputTypeRegistrygive it, as in a process console.DAPClient: each client has its own decoder, so each session of astartDebuggingtree has its own.outputprints the decoded chunks.DAPDebugProcess.printOutput(List<Chunk>)prints an event's chunks together underconsoleLock, so that no other session's text lands between them. The existingprintOutput(String, ConsoleViewContentType)is unchanged.DebugAdapterDescriptor.createInitializeRequestArgumentssendssupportsANSIStyling: true.docs/dap/DAPSupport.mdnames the capability and the behaviour.#2198 (output groups) and #2199 (telemetry) are merged, and this PR is rebased on them.
DAPOutputGroups, itsoutputGroups.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:
Tests
New
DAPOutputAnsiStylingSessionTest(6 tests, aHeavyPlatformTestCasewith 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.initializecarriessupportsANSIStyling: true.\^[[31mred\^[[0m plainshowsred plain, withredin the scheme's red andplainas info, and no escape character.green donein green.LOG_ERROR_OUTPUT.Red-green:
supportsANSIStylingis null, and the console shows the raw codes. The group test was added later, with the rebase on feat: the debug console of a DAP session indents the output of a group, as console.group() gives #2198. With the change, all 6 pass, also headless.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
initializedoesn't sendsupportsANSIStylinginitializesendssupportsANSIStyling: true