mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 07:04:49 +00:00
simplify newline check with macro
This commit is contained in:
parent
d6312085a1
commit
1c44ba0f04
1 changed files with 14 additions and 20 deletions
|
@ -143,35 +143,33 @@ pub fn count_newlines(offset: TextUnit, line_index: &LineIndex, edits: &[AtomTex
|
||||||
|
|
||||||
let mut lines: u32 = 0;
|
let mut lines: u32 = 0;
|
||||||
|
|
||||||
|
macro_rules! test_newline {
|
||||||
|
($x:ident) => {
|
||||||
|
if offset < $x {
|
||||||
|
return lines;
|
||||||
|
} else {
|
||||||
|
lines += 1;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
for &orig_newline in line_index.newlines() {
|
for &orig_newline in line_index.newlines() {
|
||||||
loop {
|
loop {
|
||||||
let translated_newline = state.translate(orig_newline);
|
let translated_newline = state.translate(orig_newline);
|
||||||
match state.next_newlines(translated_newline) {
|
match state.next_newlines(translated_newline) {
|
||||||
NextNewlines::Use => {
|
NextNewlines::Use => {
|
||||||
if offset < translated_newline {
|
test_newline!(translated_newline);
|
||||||
return lines;
|
|
||||||
} else {
|
|
||||||
lines += 1;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
NextNewlines::ReplaceMany(ns) => {
|
NextNewlines::ReplaceMany(ns) => {
|
||||||
for n in ns {
|
for n in ns {
|
||||||
if offset < n {
|
test_newline!(n);
|
||||||
return lines;
|
|
||||||
} else {
|
|
||||||
lines += 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
NextNewlines::AddMany(ns) => {
|
NextNewlines::AddMany(ns) => {
|
||||||
for n in ns {
|
for n in ns {
|
||||||
if offset < n {
|
test_newline!(n);
|
||||||
return lines;
|
|
||||||
} else {
|
|
||||||
lines += 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -183,11 +181,7 @@ pub fn count_newlines(offset: TextUnit, line_index: &LineIndex, edits: &[AtomTex
|
||||||
None => break,
|
None => break,
|
||||||
Some(ns) => {
|
Some(ns) => {
|
||||||
for n in ns {
|
for n in ns {
|
||||||
if offset < n {
|
test_newline!(n);
|
||||||
return lines;
|
|
||||||
} else {
|
|
||||||
lines += 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue