tui: drop citation rendering (#4855)
We don't instruct the model to use citations, so it never emits them. Further, ratatui [doesn't currently support rendering links into the terminal with OSC 8](https://github.com/ratatui/ratatui/issues/1028), so even if we did parse citations, we can't correctly render them. So, remove all the code related to rendering them.
This commit is contained in:
@@ -1,59 +1,10 @@
|
||||
use codex_core::config::Config;
|
||||
use codex_core::config_types::UriBasedFileOpener;
|
||||
use ratatui::text::Line;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct MarkdownCitationContext {
|
||||
file_opener: UriBasedFileOpener,
|
||||
cwd: PathBuf,
|
||||
}
|
||||
|
||||
impl MarkdownCitationContext {
|
||||
pub(crate) fn new(file_opener: UriBasedFileOpener, cwd: PathBuf) -> Self {
|
||||
Self { file_opener, cwd }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&Config> for MarkdownCitationContext {
|
||||
fn from(config: &Config) -> Self {
|
||||
MarkdownCitationContext::new(config.file_opener, config.cwd.clone())
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn append_markdown<C>(
|
||||
pub(crate) fn append_markdown(
|
||||
markdown_source: &str,
|
||||
width: Option<usize>,
|
||||
lines: &mut Vec<Line<'static>>,
|
||||
citation_context: C,
|
||||
) where
|
||||
C: Into<MarkdownCitationContext>,
|
||||
{
|
||||
let citation_context: MarkdownCitationContext = citation_context.into();
|
||||
append_markdown_with_opener_and_cwd(
|
||||
markdown_source,
|
||||
width,
|
||||
lines,
|
||||
citation_context.file_opener,
|
||||
&citation_context.cwd,
|
||||
);
|
||||
}
|
||||
|
||||
pub(crate) fn append_markdown_with_opener_and_cwd(
|
||||
markdown_source: &str,
|
||||
width: Option<usize>,
|
||||
lines: &mut Vec<Line<'static>>,
|
||||
file_opener: UriBasedFileOpener,
|
||||
cwd: &Path,
|
||||
) {
|
||||
// Render via pulldown-cmark and rewrite citations during traversal (outside code blocks).
|
||||
let rendered = crate::markdown_render::render_markdown_text_with_citations(
|
||||
markdown_source,
|
||||
width,
|
||||
file_opener.get_scheme(),
|
||||
cwd,
|
||||
);
|
||||
let rendered = crate::markdown_render::render_markdown_text_with_width(markdown_source, width);
|
||||
crate::render::line_utils::push_owned_lines(&rendered.lines, lines);
|
||||
}
|
||||
|
||||
@@ -61,14 +12,10 @@ pub(crate) fn append_markdown_with_opener_and_cwd(
|
||||
mod tests {
|
||||
use super::*;
|
||||
use pretty_assertions::assert_eq;
|
||||
use ratatui::text::Line;
|
||||
|
||||
#[test]
|
||||
fn citations_not_rewritten_inside_code_blocks() {
|
||||
let src = "Before 【F:/x.rs†L1】\n```\nInside 【F:/x.rs†L2】\n```\nAfter 【F:/x.rs†L3】\n";
|
||||
let cwd = Path::new("/");
|
||||
let mut out = Vec::new();
|
||||
append_markdown_with_opener_and_cwd(src, None, &mut out, UriBasedFileOpener::VsCode, cwd);
|
||||
let rendered: Vec<String> = out
|
||||
fn lines_to_strings(lines: &[Line<'static>]) -> Vec<String> {
|
||||
lines
|
||||
.iter()
|
||||
.map(|l| {
|
||||
l.spans
|
||||
@@ -76,21 +23,21 @@ mod tests {
|
||||
.map(|s| s.content.clone())
|
||||
.collect::<String>()
|
||||
})
|
||||
.collect();
|
||||
// Expect a line containing the inside text unchanged.
|
||||
assert!(rendered.iter().any(|s| s.contains("Inside 【F:/x.rs†L2】")));
|
||||
// And first/last sections rewritten.
|
||||
assert!(
|
||||
rendered
|
||||
.first()
|
||||
.map(|s| s.contains("vscode://file"))
|
||||
.unwrap_or(false)
|
||||
);
|
||||
assert!(
|
||||
rendered
|
||||
.last()
|
||||
.map(|s| s.contains("vscode://file"))
|
||||
.unwrap_or(false)
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn citations_render_as_plain_text() {
|
||||
let src = "Before 【F:/x.rs†L1】\nAfter 【F:/x.rs†L3】\n";
|
||||
let mut out = Vec::new();
|
||||
append_markdown(src, None, &mut out);
|
||||
let rendered = lines_to_strings(&out);
|
||||
assert_eq!(
|
||||
rendered,
|
||||
vec![
|
||||
"Before 【F:/x.rs†L1】".to_string(),
|
||||
"After 【F:/x.rs†L3】".to_string()
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -98,57 +45,17 @@ mod tests {
|
||||
fn indented_code_blocks_preserve_leading_whitespace() {
|
||||
// Basic sanity: indented code with surrounding blank lines should produce the indented line.
|
||||
let src = "Before\n\n code 1\n\nAfter\n";
|
||||
let cwd = Path::new("/");
|
||||
let mut out = Vec::new();
|
||||
append_markdown_with_opener_and_cwd(src, None, &mut out, UriBasedFileOpener::None, cwd);
|
||||
let lines: Vec<String> = out
|
||||
.iter()
|
||||
.map(|l| {
|
||||
l.spans
|
||||
.iter()
|
||||
.map(|s| s.content.clone())
|
||||
.collect::<String>()
|
||||
})
|
||||
.collect();
|
||||
append_markdown(src, None, &mut out);
|
||||
let lines = lines_to_strings(&out);
|
||||
assert_eq!(lines, vec!["Before", "", " code 1", "", "After"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn citations_not_rewritten_inside_indented_code_blocks() {
|
||||
let src = "Start 【F:/x.rs†L1】\n\n Inside 【F:/x.rs†L2】\n\nEnd 【F:/x.rs†L3】\n";
|
||||
let cwd = Path::new("/");
|
||||
let mut out = Vec::new();
|
||||
append_markdown_with_opener_and_cwd(src, None, &mut out, UriBasedFileOpener::VsCode, cwd);
|
||||
let rendered: Vec<String> = out
|
||||
.iter()
|
||||
.map(|l| {
|
||||
l.spans
|
||||
.iter()
|
||||
.map(|s| s.content.clone())
|
||||
.collect::<String>()
|
||||
})
|
||||
.collect();
|
||||
assert!(
|
||||
rendered
|
||||
.iter()
|
||||
.any(|s| s.contains("Start") && s.contains("vscode://file"))
|
||||
);
|
||||
assert!(
|
||||
rendered
|
||||
.iter()
|
||||
.any(|s| s.contains("End") && s.contains("vscode://file"))
|
||||
);
|
||||
assert!(rendered.iter().any(|s| s.contains("Inside 【F:/x.rs†L2】")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn append_markdown_preserves_full_text_line() {
|
||||
use codex_core::config_types::UriBasedFileOpener;
|
||||
use std::path::Path;
|
||||
let src = "Hi! How can I help with codex-rs today? Want me to explore the repo, run tests, or work on a specific change?\n";
|
||||
let cwd = Path::new("/");
|
||||
let mut out = Vec::new();
|
||||
append_markdown_with_opener_and_cwd(src, None, &mut out, UriBasedFileOpener::None, cwd);
|
||||
append_markdown(src, None, &mut out);
|
||||
assert_eq!(
|
||||
out.len(),
|
||||
1,
|
||||
@@ -168,47 +75,19 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn append_markdown_matches_tui_markdown_for_ordered_item() {
|
||||
use codex_core::config_types::UriBasedFileOpener;
|
||||
use std::path::Path;
|
||||
let cwd = Path::new("/");
|
||||
let mut out = Vec::new();
|
||||
append_markdown_with_opener_and_cwd(
|
||||
"1. Tight item\n",
|
||||
None,
|
||||
&mut out,
|
||||
UriBasedFileOpener::None,
|
||||
cwd,
|
||||
);
|
||||
let lines: Vec<String> = out
|
||||
.iter()
|
||||
.map(|l| {
|
||||
l.spans
|
||||
.iter()
|
||||
.map(|s| s.content.clone())
|
||||
.collect::<String>()
|
||||
})
|
||||
.collect();
|
||||
append_markdown("1. Tight item\n", None, &mut out);
|
||||
let lines = lines_to_strings(&out);
|
||||
assert_eq!(lines, vec!["1. Tight item".to_string()]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn append_markdown_keeps_ordered_list_line_unsplit_in_context() {
|
||||
use codex_core::config_types::UriBasedFileOpener;
|
||||
use std::path::Path;
|
||||
let src = "Loose vs. tight list items:\n1. Tight item\n";
|
||||
let cwd = Path::new("/");
|
||||
let mut out = Vec::new();
|
||||
append_markdown_with_opener_and_cwd(src, None, &mut out, UriBasedFileOpener::None, cwd);
|
||||
append_markdown(src, None, &mut out);
|
||||
|
||||
let lines: Vec<String> = out
|
||||
.iter()
|
||||
.map(|l| {
|
||||
l.spans
|
||||
.iter()
|
||||
.map(|s| s.content.clone())
|
||||
.collect::<String>()
|
||||
})
|
||||
.collect();
|
||||
let lines = lines_to_strings(&out);
|
||||
|
||||
// Expect to find the ordered list line rendered as a single line,
|
||||
// not split into a marker-only line followed by the text.
|
||||
|
||||
Reference in New Issue
Block a user