mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-12 13:18:47 +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 prev_line_start: Option<TextSize> = None;
|
||||||
let mut line_start: TextSize = 0.into();
|
let mut line_start: TextSize = 0.into();
|
||||||
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()]);
|
||||||
for (line_range, text) in extract_line_annotations(&line[idx + "//".len()..]) {
|
for (line_range, text) in extract_line_annotations(&line[idx + "//".len()..]) {
|
||||||
res.push((line_range + offset, text))
|
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)> {
|
fn extract_line_annotations(mut line: &str) -> Vec<(TextRange, String)> {
|
||||||
let mut res = Vec::new();
|
let mut res = Vec::new();
|
||||||
let mut offset: TextSize = 0.into();
|
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();
|
let len = line.chars().take_while(|&it| it == '^').count();
|
||||||
assert!(len > 0);
|
assert!(len > 0);
|
||||||
let range = TextRange::at(offset, len.try_into().unwrap());
|
let range = TextRange::at(offset, len.try_into().unwrap());
|
||||||
|
|
Loading…
Reference in a new issue