mirror of
https://github.com/openai/codex.git
synced 2026-11-26 23:40:43 +00:00
Fix Unicode highlighting in fuzzy file search (#64214)
## Why The fuzzy matcher reports grapheme positions, but the terminal file picker uses Unicode scalar offsets. When a path contains a joined emoji or a combining mark, the picker can highlight the wrong characters. ## What changed Let callers choose the unit for match indices. The terminal and CLI use scalar offsets that cover every scalar in each matched grapheme. The terminal's file picker and mention renderer now consume the same offsets. The app server returns grapheme offsets for both one-shot and streaming searches. ## Testing Add regression coverage for basename and full-path matches with joined emoji and combining marks, grapheme offsets in both app-server search modes, and terminal highlights in file and mention results. GitOrigin-RevId: 2da357a404396550333c785640d2c4121cb2ed3f
This commit is contained in:
@@ -45,7 +45,7 @@ pub(crate) async fn run_fuzzy_file_search(
|
||||
file_search::FileSearchOptions {
|
||||
limit,
|
||||
threads,
|
||||
compute_indices: true,
|
||||
index_unit: Some(file_search::IndexUnit::Grapheme),
|
||||
..Default::default()
|
||||
},
|
||||
Some(cancellation_flag),
|
||||
@@ -147,7 +147,7 @@ pub(crate) fn start_fuzzy_file_search_session(
|
||||
file_search::FileSearchOptions {
|
||||
limit,
|
||||
threads,
|
||||
compute_indices: true,
|
||||
index_unit: Some(file_search::IndexUnit::Grapheme),
|
||||
..Default::default()
|
||||
},
|
||||
reporter,
|
||||
|
||||
@@ -228,7 +228,7 @@ async fn test_fuzzy_file_search_sorts_and_includes_indices() -> Result<()> {
|
||||
std::fs::write(root.path().join("abcde"), "x")?;
|
||||
std::fs::write(root.path().join("abexy"), "x")?;
|
||||
std::fs::write(root.path().join("zzz.txt"), "x")?;
|
||||
let sub_dir = root.path().join("sub");
|
||||
let sub_dir = root.path().join("👩💻");
|
||||
std::fs::create_dir_all(&sub_dir)?;
|
||||
let sub_abce_path = sub_dir.join("abce");
|
||||
std::fs::write(&sub_abce_path, "x")?;
|
||||
@@ -283,7 +283,7 @@ async fn test_fuzzy_file_search_sorts_and_includes_indices() -> Result<()> {
|
||||
"match_type": "file",
|
||||
"file_name": "abce",
|
||||
"score": filename_bonus + 72,
|
||||
"indices": [4, 5, 7],
|
||||
"indices": [2, 3, 5],
|
||||
},
|
||||
{
|
||||
"root": root_path.clone(),
|
||||
@@ -356,7 +356,7 @@ async fn test_fuzzy_file_search_accepts_cancellation_token() -> Result<()> {
|
||||
async fn test_fuzzy_file_search_session_streams_updates() -> Result<()> {
|
||||
let codex_home = TempDir::new()?;
|
||||
let root = TempDir::new()?;
|
||||
std::fs::write(root.path().join("alpha.txt"), "contents")?;
|
||||
std::fs::write(root.path().join("👩💻alpha.txt"), "contents")?;
|
||||
let mut mcp = initialized_mcp(&codex_home).await?;
|
||||
|
||||
let root_path = root.path().to_string_lossy().to_string();
|
||||
@@ -371,7 +371,8 @@ async fn test_fuzzy_file_search_session_streams_updates() -> Result<()> {
|
||||
wait_for_session_updated(&mut mcp, session_id, "alp", FileExpectation::NonEmpty).await?;
|
||||
assert_eq!(payload.files.len(), 1);
|
||||
assert_eq!(payload.files[0].root, root_path);
|
||||
assert_eq!(payload.files[0].path, "alpha.txt");
|
||||
assert_eq!(payload.files[0].path, "👩💻alpha.txt");
|
||||
assert_eq!(payload.files[0].indices, Some(vec![1, 2, 3]));
|
||||
let completed = wait_for_session_completed(&mut mcp, session_id).await?;
|
||||
assert_eq!(completed.session_id, session_id);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user