mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 11:07:42 +00:00
Merge #5135
5135: Generalize annotations r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
5a0fb3caff
@ -11,6 +11,7 @@ pub mod mark;
|
||||
mod fixture;
|
||||
|
||||
use std::{
|
||||
convert::TryInto,
|
||||
env, fs,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
@ -168,8 +169,10 @@ pub fn extract_annotations(text: &str) -> Vec<(TextRange, String)> {
|
||||
for line in lines_with_ends(text) {
|
||||
if let Some(idx) = line.find("//^") {
|
||||
let offset = prev_line_start.unwrap() + TextSize::of(&line[..idx + "//".len()]);
|
||||
let data = line[idx + "//^".len()..].trim().to_string();
|
||||
res.push((TextRange::at(offset, 1.into()), data))
|
||||
let marker_and_data = &line[idx + "//".len()..];
|
||||
let len = marker_and_data.chars().take_while(|&it| it == '^').count();
|
||||
let data = marker_and_data[len..].trim().to_string();
|
||||
res.push((TextRange::at(offset, len.try_into().unwrap()), data))
|
||||
}
|
||||
prev_line_start = Some(line_start);
|
||||
line_start += TextSize::of(line);
|
||||
@ -184,15 +187,15 @@ fn test_extract_annotations() {
|
||||
fn main() {
|
||||
let x = 92;
|
||||
//^ def
|
||||
z + 1
|
||||
} //^ i32
|
||||
zoo + 1
|
||||
} //^^^ i32
|
||||
"#,
|
||||
);
|
||||
let res = extract_annotations(&text)
|
||||
.into_iter()
|
||||
.map(|(range, ann)| (&text[range], ann))
|
||||
.collect::<Vec<_>>();
|
||||
assert_eq!(res, vec![("x", "def".into()), ("z", "i32".into()),]);
|
||||
assert_eq!(res, vec![("x", "def".into()), ("zoo", "i32".into()),]);
|
||||
}
|
||||
|
||||
// Comparison functionality borrowed from cargo:
|
||||
|
Loading…
Reference in New Issue
Block a user