Enable output renderers for code blocks in chat#316138
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends the chat output renderer contribution system so extensions can render completed fenced code blocks (by language identifier) using the same webview-based rendering flow that already exists for MIME-typed tool outputs. This aligns with the broader effort in #257761 to allow safe, custom rendering of chat response elements.
Changes:
- Adds a
ChatOutputRenderContext(withcodeBlockContext) to the proposedChatOutputRendererAPI surface. - Extends
chatOutputRendererscontributions and the workbenchChatOutputRendererServiceto resolve renderers bycodeBlockLanguageIdentifiersand render code blocks via a newrenderCodeBlockpath. - Updates chat markdown rendering to invoke contributed code block renderers (including streaming/incomplete-state UI) and adds browser tests; updates the Mermaid built-in extension to contribute the new identifier.
Show a summary per file
| File | Description |
|---|---|
| src/vscode-dts/vscode.proposed.chatOutputRenderer.d.ts | Introduces render context for renderers and updates the proposed API/docs for code block rendering. |
| src/vs/workbench/contrib/chat/test/browser/widget/chatContentParts/chatMarkdownContentPart.test.ts | Adds coverage for code-block rendering via contributed output renderers (including incomplete fences). |
| src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatMarkdownContentPart.ts | Renders eligible fenced code blocks using contributed output renderers and adds a webview-based code block part. |
| src/vs/workbench/contrib/chat/browser/chatOutputItemRenderer.ts | Extends renderer discovery and rendering to support code block identifiers and passes render context through. |
| src/vs/workbench/api/common/extHostChatOutputRenderer.ts | Threads render context through the ext host renderer call. |
| src/vs/workbench/api/common/extHost.protocol.ts | Adds DTO for render context and updates the ext host protocol signature. |
| src/vs/workbench/api/browser/mainThreadChatOutputRenderer.ts | Passes render context to the ext host and improves handling of re-registrations/logging. |
| extensions/mermaid-chat-features/package.json | Contributes codeBlockLanguageIdentifiers: ["mermaid"] so Mermaid fenced blocks can render via the renderer. |
Copilot's findings
Comments suppressed due to low confidence (1)
src/vs/workbench/contrib/chat/browser/chatOutputItemRenderer.ts:134
- Same grammatical issue as above: "No renderer registered found" should be rephrased for clarity (e.g. "No registered renderer found for code block language identifier …").
if (!rendererData) {
throw new Error(`No renderer registered found for code block language identifier: ${languageIdentifier}`);
}
- Files reviewed: 7/8 changed files
- Comments generated: 2
Comment on lines
118
to
121
|
|
||
| if (!rendererData) { | ||
| throw new Error(`No renderer registered found for mime type: ${mime}`); | ||
| } |
Comment on lines
+695
to
+710
| const parent = $('.webview-output'); | ||
| parent.style.maxHeight = '80vh'; | ||
| parent.style.minHeight = '38px'; | ||
| this.element.appendChild(parent); | ||
|
|
||
| const progressMessage = $('span'); | ||
| progressMessage.textContent = localize('chat.codeBlockOutputRendering', "Rendering code block..."); | ||
| const progressPart = this._register(this.instantiationService.createInstance(ChatProgressSubPart, progressMessage, ThemeIcon.modify(Codicon.loading, 'spin'), undefined)); | ||
| parent.appendChild(progressPart.domNode); | ||
| if (!isComplete) { | ||
| this.onDidChangeHeight(); | ||
| return; | ||
| } | ||
|
|
||
| this.chatOutputRendererService.renderCodeBlock(identifier, new TextEncoder().encode(text), parent, { origin: generateUuid(), title }, this._disposeCts.token).then(renderedItem => { | ||
| if (this._disposeCts.token.isCancellationRequested) { |
DonJayamanne
approved these changes
May 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For #257761