Sort scraped call locations before serializing
This commit is contained in:
parent
ce943d26f8
commit
3ad6d12827
@ -270,12 +270,18 @@ struct Decorations {
|
|||||||
|
|
||||||
impl Decorations {
|
impl Decorations {
|
||||||
fn new(info: DecorationInfo) -> Self {
|
fn new(info: DecorationInfo) -> Self {
|
||||||
let (starts, ends) = info
|
// Extract tuples (start, end, kind) into separate sequences of (start, kind) and (end).
|
||||||
|
let (mut starts, mut ends): (Vec<_>, Vec<_>) = info
|
||||||
.0
|
.0
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(kind, ranges)| ranges.into_iter().map(move |(lo, hi)| ((lo, kind), hi)))
|
.map(|(kind, ranges)| ranges.into_iter().map(move |(lo, hi)| ((lo, kind), hi)))
|
||||||
.flatten()
|
.flatten()
|
||||||
.unzip();
|
.unzip();
|
||||||
|
|
||||||
|
// Sort the sequences in document order.
|
||||||
|
starts.sort_by_key(|(lo, _)| *lo);
|
||||||
|
ends.sort();
|
||||||
|
|
||||||
Decorations { starts, ends }
|
Decorations { starts, ends }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -240,6 +240,13 @@ crate fn run(
|
|||||||
let mut finder = FindCalls { calls: &mut calls, tcx, map: tcx.hir(), cx, target_crates };
|
let mut finder = FindCalls { calls: &mut calls, tcx, map: tcx.hir(), cx, target_crates };
|
||||||
tcx.hir().visit_all_item_likes(&mut finder.as_deep_visitor());
|
tcx.hir().visit_all_item_likes(&mut finder.as_deep_visitor());
|
||||||
|
|
||||||
|
// Sort call locations within a given file in document order
|
||||||
|
for fn_calls in calls.values_mut() {
|
||||||
|
for file_calls in fn_calls.values_mut() {
|
||||||
|
file_calls.locations.sort_by_key(|loc| loc.call_expr.byte_span.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Save output to provided path
|
// Save output to provided path
|
||||||
let mut encoder = FileEncoder::new(options.output_path).map_err(|e| e.to_string())?;
|
let mut encoder = FileEncoder::new(options.output_path).map_err(|e| e.to_string())?;
|
||||||
calls.encode(&mut encoder).map_err(|e| e.to_string())?;
|
calls.encode(&mut encoder).map_err(|e| e.to_string())?;
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
foobar::ok();
|
foobar::ok(0);
|
||||||
|
|
||||||
// this is a
|
// this is a
|
||||||
|
|
||||||
|
// ..
|
||||||
|
|
||||||
// BIG
|
// BIG
|
||||||
|
|
||||||
// item
|
// item
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
foobar::ok();
|
foobar::ok(1);
|
||||||
// small item
|
// small item
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn f() {
|
||||||
|
foobar::ok(2);
|
||||||
|
}
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
// @has foobar/fn.ok.html '//*[@class="docblock scraped-example-list"]' 'ex2'
|
// @has foobar/fn.ok.html '//*[@class="docblock scraped-example-list"]' 'ex2'
|
||||||
// @has foobar/fn.ok.html '//*[@class="more-scraped-examples"]' 'ex1'
|
// @has foobar/fn.ok.html '//*[@class="more-scraped-examples"]' 'ex1'
|
||||||
|
// @has foobar/fn.ok.html '//*[@class="highlight focus"]' '1'
|
||||||
|
// @has foobar/fn.ok.html '//*[@class="highlight"]' '2'
|
||||||
|
// @has foobar/fn.ok.html '//*[@class="highlight focus"]' '0'
|
||||||
|
|
||||||
pub fn ok() {}
|
pub fn ok(_x: i32) {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user