mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
Merge #5146
5146: Simplify most of the inlay hints tests r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
4a19d5954a
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;
|
mod fixture;
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
convert::TryInto,
|
convert::{TryFrom, TryInto},
|
||||||
env, fs,
|
env, fs,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
@ -169,10 +169,9 @@ pub fn extract_annotations(text: &str) -> Vec<(TextRange, String)> {
|
||||||
for line in lines_with_ends(text) {
|
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()]);
|
let offset = prev_line_start.unwrap() + TextSize::of(&line[..idx + "//".len()]);
|
||||||
let marker_and_data = &line[idx + "//".len()..];
|
for (line_range, text) in extract_line_annotations(&line[idx + "//".len()..]) {
|
||||||
let len = marker_and_data.chars().take_while(|&it| it == '^').count();
|
res.push((line_range + offset, text))
|
||||||
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);
|
prev_line_start = Some(line_start);
|
||||||
line_start += TextSize::of(line);
|
line_start += TextSize::of(line);
|
||||||
|
@ -180,13 +179,28 @@ pub fn extract_annotations(text: &str) -> Vec<(TextRange, String)> {
|
||||||
res
|
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]
|
#[test]
|
||||||
fn test_extract_annotations() {
|
fn test_extract_annotations() {
|
||||||
let text = stdx::trim_indent(
|
let text = stdx::trim_indent(
|
||||||
r#"
|
r#"
|
||||||
fn main() {
|
fn main() {
|
||||||
let x = 92;
|
let (x, y) = (9, 2);
|
||||||
//^ def
|
//^ def ^ def
|
||||||
zoo + 1
|
zoo + 1
|
||||||
} //^^^ i32
|
} //^^^ i32
|
||||||
"#,
|
"#,
|
||||||
|
@ -195,7 +209,7 @@ fn main() {
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(range, ann)| (&text[range], ann))
|
.map(|(range, ann)| (&text[range], ann))
|
||||||
.collect::<Vec<_>>();
|
.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:
|
// Comparison functionality borrowed from cargo:
|
||||||
|
|
Loading…
Reference in a new issue