Skip to content

Commit b7be823

Browse files
committed
agent: Add expand_code_block setting
When false, fenced code blocks in agent messages start collapsed and can be expanded individually. Complements expand_edit_card and expand_terminal_card. Tool output and compaction summaries are unaffected. Addresses #58333
1 parent 93f0fb9 commit b7be823

7 files changed

Lines changed: 46 additions & 1 deletion

File tree

‎assets/settings/default.json‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,6 +1362,11 @@
13621362
//
13631363
// Default: true
13641364
"expand_terminal_card": true,
1365+
// Whether to have code blocks in agent messages expanded, showing the whole code.
1366+
// When disabled, code blocks start collapsed and can be expanded individually.
1367+
//
1368+
// Default: true
1369+
"expand_code_block": true,
13651370
// Command to automatically run when Zed creates a Terminal Thread shell in the agent panel.
13661371
// The command is sent to the shell as if typed, so it is interpreted by your
13671372
// configured shell (including on Windows and remote/WSL projects).

‎crates/agent/src/tool_permissions.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,7 @@ mod tests {
600600
enable_feedback: false,
601601
expand_edit_card: true,
602602
expand_terminal_card: true,
603+
expand_code_block: true,
603604
terminal_init_command: None,
604605
cancel_generation_on_terminal_stop: true,
605606
use_modifier_to_send: true,

‎crates/agent_settings/src/agent_settings.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ pub struct AgentSettings {
240240
pub enable_feedback: bool,
241241
pub expand_edit_card: bool,
242242
pub expand_terminal_card: bool,
243+
pub expand_code_block: bool,
243244
pub terminal_init_command: Option<String>,
244245
pub thinking_display: ThinkingBlockDisplay,
245246
pub cancel_generation_on_terminal_stop: bool,
@@ -833,6 +834,7 @@ impl Settings for AgentSettings {
833834
enable_feedback: agent.enable_feedback.unwrap(),
834835
expand_edit_card: agent.expand_edit_card.unwrap(),
835836
expand_terminal_card: agent.expand_terminal_card.unwrap(),
837+
expand_code_block: agent.expand_code_block.unwrap(),
836838
terminal_init_command: agent
837839
.terminal_init_command
838840
.filter(|command| !command.trim().is_empty()),

‎crates/agent_ui/src/agent_ui.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,7 @@ mod tests {
10021002
enable_feedback: false,
10031003
expand_edit_card: true,
10041004
expand_terminal_card: true,
1005+
expand_code_block: true,
10051006
terminal_init_command: None,
10061007
cancel_generation_on_terminal_stop: true,
10071008
use_modifier_to_send: true,

‎crates/agent_ui/src/conversation_view/thread_view.rs‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3955,6 +3955,7 @@ impl ThreadView {
39553955
content.as_view(),
39563956
None,
39573957
true,
3958+
false,
39583959
window,
39593960
cx,
39603961
)
@@ -7385,14 +7386,22 @@ impl ThreadView {
73857386
window: &Window,
73867387
cx: &Context<Self>,
73877388
) -> Div {
7389+
let collapse_code_blocks = !AgentSettings::get_global(cx).expand_code_block;
73887390
v_flex().w_full().gap_3().children(
73897391
content
73907392
.blocks()
73917393
.enumerate()
73927394
.filter(|(_, block)| block.visible_content(cx))
73937395
.map(|(block_ix, block)| {
73947396
let content = self.render_output_content_block(
7395-
entry_ix, block_ix, block, None, false, window, cx,
7397+
entry_ix,
7398+
block_ix,
7399+
block,
7400+
None,
7401+
false,
7402+
collapse_code_blocks,
7403+
window,
7404+
cx,
73967405
);
73977406
div()
73987407
.id(("message-content-block", block_ix))
@@ -10189,6 +10198,7 @@ impl ThreadView {
1018910198
content.as_view(),
1019010199
Some(tool_call),
1019110200
card_layout,
10201+
false,
1019210202
window,
1019310203
cx,
1019410204
),
@@ -10215,6 +10225,7 @@ impl ThreadView {
1021510225
content: acp_thread::ContentBlockView<'_>,
1021610226
tool_call: Option<&ToolCall>,
1021710227
card_layout: bool,
10228+
collapse_code_blocks: bool,
1021810229
window: &Window,
1021910230
cx: &Context<Self>,
1022010231
) -> AnyElement {
@@ -10235,6 +10246,7 @@ impl ThreadView {
1023510246
MarkdownStyle::themed(MarkdownFont::Agent, window, cx),
1023610247
cx,
1023710248
)
10249+
.collapse_code_blocks(collapse_code_blocks)
1023810250
.into_any()
1023910251
}
1024010252
} else if let Some((resource, _)) = content.embedded_resource() {

‎crates/settings_content/src/agent.rs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,11 @@ pub struct AgentSettingsContent {
353353
///
354354
/// Default: true
355355
pub expand_terminal_card: Option<bool>,
356+
/// Whether to have code blocks in agent messages expanded, showing the whole code.
357+
/// When disabled, code blocks start collapsed and can be expanded individually.
358+
///
359+
/// Default: true
360+
pub expand_code_block: Option<bool>,
356361
/// Command to automatically run when Zed creates a Terminal Thread shell in the agent panel.
357362
/// The command is sent to the shell as if typed, so it is interpreted by your
358363
/// configured shell (including on Windows and remote/WSL projects).

‎crates/settings_ui/src/page_data.rs‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8962,6 +8962,25 @@ fn ai_page(cx: &App) -> SettingsPage {
89628962
metadata: None,
89638963
files: USER,
89648964
}),
8965+
SettingsPageItem::SettingItem(SettingItem {
8966+
title: "Expand Code Block",
8967+
description: "Whether to have code blocks in agent messages expanded, showing the whole code. When disabled, code blocks start collapsed and can be expanded individually.",
8968+
field: Box::new(SettingField {
8969+
organization_override: None,
8970+
json_path: Some("agent.expand_code_block"),
8971+
pick: |settings_content| {
8972+
settings_content.agent.as_ref()?.expand_code_block.as_ref()
8973+
},
8974+
write: |settings_content, value, _| {
8975+
settings_content
8976+
.agent
8977+
.get_or_insert_default()
8978+
.expand_code_block = value;
8979+
},
8980+
}),
8981+
metadata: None,
8982+
files: USER,
8983+
}),
89658984
SettingsPageItem::SettingItem(SettingItem {
89668985
title: "Terminal Thread Init Command",
89678986
description: "Command to automatically run when Zed creates a Terminal Thread shell in the agent panel. Runs in your configured shell.",

0 commit comments

Comments
 (0)