mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 04:23:25 +00:00
Simplify most of the inlay hints tests
This commit is contained in:
parent
0954d31bee
commit
442c13ba17
2 changed files with 199 additions and 631 deletions
File diff suppressed because it is too large
Load diff
|
@ -11,7 +11,7 @@ pub mod mark;
|
|||
mod fixture;
|
||||
|
||||
use std::{
|
||||
convert::TryInto,
|
||||
convert::{TryFrom, TryInto},
|
||||
env, fs,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
@ -169,10 +169,9 @@ 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 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))
|
||||
for (line_range, text) in extract_line_annotations(&line[idx + "//".len()..]) {
|
||||
res.push((line_range + offset, text))
|
||||
}
|
||||
}
|
||||
prev_line_start = Some(line_start);
|
||||
line_start += TextSize::of(line);
|
||||
|
@ -180,13 +179,28 @@ pub fn extract_annotations(text: &str) -> Vec<(TextRange, String)> {
|
|||
res
|
||||
}
|
||||
|
||||
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() {
|
||||
let len = line.chars().take_while(|&it| it == '^').count();
|
||||
assert!(len > 0);
|
||||
let range = TextRange::at(offset, len.try_into().unwrap());
|
||||
let next = line[len..].find('^').map_or(line.len(), |it| it + len);
|
||||
res.push((range, line[len..][..next - len].trim().to_string()));
|
||||
line = &line[next..];
|
||||
offset += TextSize::try_from(next).unwrap();
|
||||
}
|
||||
res
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extract_annotations() {
|
||||
let text = stdx::trim_indent(
|
||||
r#"
|
||||
fn main() {
|
||||
let x = 92;
|
||||
//^ def
|
||||
let (x, y) = (9, 2);
|
||||
//^ def ^ def
|
||||
zoo + 1
|
||||
} //^^^ i32
|
||||
"#,
|
||||
|
@ -195,7 +209,7 @@ fn main() {
|
|||
.into_iter()
|
||||
.map(|(range, ann)| (&text[range], ann))
|
||||
.collect::<Vec<_>>();
|
||||
assert_eq!(res, vec![("x", "def".into()), ("zoo", "i32".into()),]);
|
||||
assert_eq!(res, vec![("x", "def".into()), ("y", "def".into()), ("zoo", "i32".into()),]);
|
||||
}
|
||||
|
||||
// Comparison functionality borrowed from cargo:
|
||||
|
|
Loading…
Reference in a new issue