Skip to content

Commit 6349e4f

Browse files
committed
fix: handle character boundary in search mode
1 parent 9923b00 commit 6349e4f

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

crates/hir-def/src/import_map.rs

+25-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ impl SearchMode {
320320
};
321321
match m {
322322
Some((index, _)) => {
323-
name = &name[index + 1..];
323+
name = &name[ceil_char_boundary(name, index + 1)..];
324324
true
325325
}
326326
None => false,
@@ -331,6 +331,12 @@ impl SearchMode {
331331
}
332332
}
333333

334+
// FIXME: use `ceil_char_boundary` from `std::str` when it gets stable
335+
// https://github.com/rust-lang/rust/issues/93743
336+
fn ceil_char_boundary(text: &str, index: usize) -> usize {
337+
(index..).find(|&index| text.is_char_boundary(index)).unwrap_or(text.len())
338+
}
339+
334340
/// Three possible ways to search for the name in associated and/or other items.
335341
#[derive(Debug, Clone, Copy)]
336342
pub enum AssocSearchMode {
@@ -1043,4 +1049,22 @@ pub mod fmt {
10431049
"#]],
10441050
);
10451051
}
1052+
1053+
#[test]
1054+
fn unicode_fn_name() {
1055+
let ra_fixture = r#"
1056+
//- /main.rs crate:main deps:dep
1057+
//- /dep.rs crate:dep
1058+
pub fn あい() {}
1059+
"#;
1060+
1061+
check_search(
1062+
ra_fixture,
1063+
"main",
1064+
Query::new("あ".to_owned()).fuzzy(),
1065+
expect![[r#"
1066+
dep::あい (f)
1067+
"#]],
1068+
);
1069+
}
10461070
}

0 commit comments

Comments
 (0)