Ensure path headers appear before first diagnostic header

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Max Brunsfeld 2022-01-11 18:17:42 -08:00
parent ac0d55222f
commit 6ad9ff10c1
2 changed files with 28 additions and 21 deletions

View file

@ -423,28 +423,27 @@ impl ProjectDiagnosticsEditor {
render: path_header_renderer(buffer, self.build_settings.clone()),
disposition: BlockDisposition::Above,
});
let mut block_ids = editor
.insert_blocks(
header_block
let block_ids = editor.insert_blocks(
blocks_to_add
.into_iter()
.chain(blocks_to_add.into_iter().map(|block| {
.map(|block| {
let (excerpt_id, text_anchor) = block.position;
BlockProperties {
position: excerpts_snapshot
.anchor_in_excerpt(excerpt_id, text_anchor),
position: excerpts_snapshot.anchor_in_excerpt(excerpt_id, text_anchor),
height: block.height,
render: block.render,
disposition: block.disposition,
}
})),
})
.chain(header_block.into_iter()),
cx,
)
.into_iter();
);
path_state.header = block_ids.next();
let mut block_ids = block_ids.into_iter();
for group_state in &mut groups_to_add {
group_state.blocks = block_ids.by_ref().take(group_state.block_count).collect();
}
path_state.header = block_ids.next();
});
for ix in group_ixs_to_remove.into_iter().rev() {

View file

@ -5,7 +5,7 @@ use gpui::{AppContext, ElementBox};
use language::Chunk;
use parking_lot::Mutex;
use std::{
cmp::{self, Ordering},
cmp::{self, Ordering, Reverse},
fmt::Debug,
ops::{Deref, Range},
sync::{
@ -276,7 +276,11 @@ impl BlockMap {
(position.row(), column, block.clone())
}),
);
blocks_in_edit.sort_by_key(|(row, _, block)| (*row, block.disposition, block.id));
// When multiple blocks are on the same row, newer blocks appear above older
// blocks. This is arbitrary, but we currently rely on it in ProjectDiagnosticsEditor.
blocks_in_edit
.sort_by_key(|(row, _, block)| (*row, block.disposition, Reverse(block.id)));
// For each of these blocks, insert a new isomorphic transform preceding the block,
// and then insert the block itself.
@ -940,7 +944,11 @@ mod tests {
start_row..start_row + block.height(),
block.column(),
block
.render(&BlockContext { cx, anchor_x: 0., line_number_x: 0., })
.render(&BlockContext {
cx,
anchor_x: 0.,
line_number_x: 0.,
})
.name()
.unwrap()
.to_string(),