Reduce generic code duplication in RPC and Markdown rendering (#47751)

## Why

RPC sending and waiting do not depend on request or response types, and Markdown layout does not depend on the parser iterator. Share these implementations across typed calls and parser variants.

## What changed

- Extract `RpcClient::send_request_and_wait` into a non-generic async method, preserving registration before serialization and disconnected-client error precedence.
- Remove the iterator type parameter from `Writer` and pass iterators to event traversal methods, retaining static dispatch and dropping the parser before rendering state, including on unwind.
- Update streaming rendering and existing rendering tests to use the separate parser.

GitOrigin-RevId: 4cc07223111b7c08211028948d13fe04598f8fc7
This commit is contained in:
Ahmed Ibrahim
2026-09-24 04:48:03 +00:00
committed by copyberry
parent a16381c445
commit e0ef5a1a0f
5 changed files with 56 additions and 39 deletions
@@ -65,14 +65,16 @@ pub(crate) fn render_streaming_markdown_lines_with_width_and_cwd(
first_is_html: false,
mutable_fence_start: None,
};
let mut writer = Writer::new(input, parser, width, cwd, is_hidden_link_destination);
let mut writer = Writer::new(input, width, cwd, is_hidden_link_destination);
// Drop the consumed parser before the rendering state, including on unwind.
let mut parser = parser;
writer.list_spacing = list_spacing;
writer.run();
writer.run(&mut parser);
StreamingMarkdownRender {
lines: writer.text,
pending_math_start: math.pending_start,
last_top_level_block_start: (writer.iter.block_count > 1)
.then_some(writer.iter.last_start)
last_top_level_block_start: (parser.block_count > 1)
.then_some(parser.last_start)
.filter(|start| math.pending_start.is_none_or(|pending| *start <= pending))
.filter(|start| {
!math
@@ -81,8 +83,8 @@ pub(crate) fn render_streaming_markdown_lines_with_width_and_cwd(
.any(|range| range.start < *start && *start < range.end)
}),
has_reference_link_definition,
first_top_level_block_is_html: writer.iter.first_is_html,
mutable_fence_start: writer.iter.mutable_fence_start,
first_top_level_block_is_html: parser.first_is_html,
mutable_fence_start: parser.mutable_fence_start,
}
}
@@ -2,14 +2,9 @@
//! Keep the hanging indent aligned with the task text, including in loose lists.
use super::Writer;
use pulldown_cmark::Event;
use ratatui::text::Span;
use std::ops::Range;
impl<'a, 'policy, I> Writer<'a, 'policy, I>
where
I: Iterator<Item = (Event<'a>, Range<usize>)>,
{
impl Writer<'_, '_> {
pub(super) fn task_list_marker(&mut self, checked: bool) {
let Some(context) = self
.indent_stack