Skip to content

Commit ba425cc

Browse files
authored
Merge pull request #20262 from ChayimFriedman2/goto-ref-raw
fix: Fix search of raw labels and lifetimes
2 parents 58e507d + 7723b21 commit ba425cc

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

crates/ide-db/src/search.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ impl<'a> FindUsages<'a> {
531531
node.token_at_offset(offset)
532532
.find(|it| {
533533
// `name` is stripped of raw ident prefix. See the comment on name retrieval below.
534-
it.text().trim_start_matches("r#") == name
534+
it.text().trim_start_matches('\'').trim_start_matches("r#") == name
535535
})
536536
.into_iter()
537537
.flat_map(move |token| {
@@ -938,7 +938,12 @@ impl<'a> FindUsages<'a> {
938938
})
939939
};
940940
// We need to search without the `r#`, hence `as_str` access.
941-
self.def.name(sema.db).or_else(self_kw_refs).map(|it| it.as_str().to_smolstr())
941+
// We strip `'` from lifetimes and labels as otherwise they may not match with raw-escaped ones,
942+
// e.g. if we search `'foo` we won't find `'r#foo`.
943+
self.def
944+
.name(sema.db)
945+
.or_else(self_kw_refs)
946+
.map(|it| it.as_str().trim_start_matches('\'').to_smolstr())
942947
}
943948
};
944949
let name = match &name {

crates/ide/src/references.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3088,4 +3088,42 @@ fn main() {
30883088
"#]],
30893089
);
30903090
}
3091+
3092+
#[test]
3093+
fn raw_labels_and_lifetimes() {
3094+
check(
3095+
r#"
3096+
fn foo<'r#fn>(s: &'r#fn str) {
3097+
let _a: &'r#fn str = s;
3098+
let _b: &'r#fn str;
3099+
'r#break$0: {
3100+
break 'r#break;
3101+
}
3102+
}
3103+
"#,
3104+
expect![[r#"
3105+
'r#break Label FileId(0) 87..96 87..95
3106+
3107+
FileId(0) 113..121
3108+
"#]],
3109+
);
3110+
check(
3111+
r#"
3112+
fn foo<'r#fn$0>(s: &'r#fn str) {
3113+
let _a: &'r#fn str = s;
3114+
let _b: &'r#fn str;
3115+
'r#break: {
3116+
break 'r#break;
3117+
}
3118+
}
3119+
"#,
3120+
expect![[r#"
3121+
'r#fn LifetimeParam FileId(0) 7..12
3122+
3123+
FileId(0) 18..23
3124+
FileId(0) 44..49
3125+
FileId(0) 72..77
3126+
"#]],
3127+
);
3128+
}
30913129
}

0 commit comments

Comments
 (0)