mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 04:23:25 +00:00
Generaize annotation extraction
This commit is contained in:
parent
83271f9b99
commit
0b0865ab22
1 changed files with 10 additions and 2 deletions
|
@ -180,7 +180,7 @@ pub fn extract_annotations(text: &str) -> Vec<(TextRange, String)> {
|
|||
let mut prev_line_start: Option<TextSize> = None;
|
||||
let mut line_start: TextSize = 0.into();
|
||||
for line in lines_with_ends(text) {
|
||||
if let Some(idx) = line.find("//^") {
|
||||
if let Some(idx) = line.find("//") {
|
||||
let offset = prev_line_start.unwrap() + TextSize::of(&line[..idx + "//".len()]);
|
||||
for (line_range, text) in extract_line_annotations(&line[idx + "//".len()..]) {
|
||||
res.push((line_range + offset, text))
|
||||
|
@ -195,7 +195,15 @@ pub fn extract_annotations(text: &str) -> Vec<(TextRange, String)> {
|
|||
fn extract_line_annotations(mut line: &str) -> Vec<(TextRange, String)> {
|
||||
let mut res = Vec::new();
|
||||
let mut offset: TextSize = 0.into();
|
||||
while !line.is_empty() {
|
||||
loop {
|
||||
match line.find('^') {
|
||||
Some(idx) => {
|
||||
offset += TextSize::try_from(idx).unwrap();
|
||||
line = &line[idx..];
|
||||
}
|
||||
None => break,
|
||||
};
|
||||
|
||||
let len = line.chars().take_while(|&it| it == '^').count();
|
||||
assert!(len > 0);
|
||||
let range = TextRange::at(offset, len.try_into().unwrap());
|
||||
|
|
Loading…
Reference in a new issue