Auto-fix clippy::collapsible_if violations (#36428)
Release Notes: - N/A
This commit is contained in:
parent
9e8ec72bd5
commit
8f567383e4
281 changed files with 6628 additions and 7089 deletions
|
@ -969,13 +969,13 @@ impl DisplaySnapshot {
|
|||
if let Some(chunk_highlight) = chunk.highlight_style {
|
||||
// For color inlays, blend the color with the editor background
|
||||
let mut processed_highlight = chunk_highlight;
|
||||
if chunk.is_inlay {
|
||||
if let Some(inlay_color) = chunk_highlight.color {
|
||||
// Only blend if the color has transparency (alpha < 1.0)
|
||||
if inlay_color.a < 1.0 {
|
||||
let blended_color = editor_style.background.blend(inlay_color);
|
||||
processed_highlight.color = Some(blended_color);
|
||||
}
|
||||
if chunk.is_inlay
|
||||
&& let Some(inlay_color) = chunk_highlight.color
|
||||
{
|
||||
// Only blend if the color has transparency (alpha < 1.0)
|
||||
if inlay_color.a < 1.0 {
|
||||
let blended_color = editor_style.background.blend(inlay_color);
|
||||
processed_highlight.color = Some(blended_color);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2351,11 +2351,12 @@ pub mod tests {
|
|||
.highlight_style
|
||||
.and_then(|style| style.color)
|
||||
.map_or(black, |color| color.to_rgb());
|
||||
if let Some((last_chunk, last_severity, last_color)) = chunks.last_mut() {
|
||||
if *last_severity == chunk.diagnostic_severity && *last_color == color {
|
||||
last_chunk.push_str(chunk.text);
|
||||
continue;
|
||||
}
|
||||
if let Some((last_chunk, last_severity, last_color)) = chunks.last_mut()
|
||||
&& *last_severity == chunk.diagnostic_severity
|
||||
&& *last_color == color
|
||||
{
|
||||
last_chunk.push_str(chunk.text);
|
||||
continue;
|
||||
}
|
||||
|
||||
chunks.push((chunk.text.to_string(), chunk.diagnostic_severity, color));
|
||||
|
@ -2901,11 +2902,12 @@ pub mod tests {
|
|||
.syntax_highlight_id
|
||||
.and_then(|id| id.style(theme)?.color);
|
||||
let highlight_color = chunk.highlight_style.and_then(|style| style.color);
|
||||
if let Some((last_chunk, last_syntax_color, last_highlight_color)) = chunks.last_mut() {
|
||||
if syntax_color == *last_syntax_color && highlight_color == *last_highlight_color {
|
||||
last_chunk.push_str(chunk.text);
|
||||
continue;
|
||||
}
|
||||
if let Some((last_chunk, last_syntax_color, last_highlight_color)) = chunks.last_mut()
|
||||
&& syntax_color == *last_syntax_color
|
||||
&& highlight_color == *last_highlight_color
|
||||
{
|
||||
last_chunk.push_str(chunk.text);
|
||||
continue;
|
||||
}
|
||||
chunks.push((chunk.text.to_string(), syntax_color, highlight_color));
|
||||
}
|
||||
|
|
|
@ -525,26 +525,25 @@ impl BlockMap {
|
|||
// * Below blocks that end at the start of the edit
|
||||
// However, if we hit a replace block that ends at the start of the edit we want to reconstruct it.
|
||||
new_transforms.append(cursor.slice(&old_start, Bias::Left), &());
|
||||
if let Some(transform) = cursor.item() {
|
||||
if transform.summary.input_rows > 0
|
||||
&& cursor.end() == old_start
|
||||
&& transform
|
||||
.block
|
||||
.as_ref()
|
||||
.map_or(true, |b| !b.is_replacement())
|
||||
{
|
||||
// Preserve the transform (push and next)
|
||||
new_transforms.push(transform.clone(), &());
|
||||
cursor.next();
|
||||
if let Some(transform) = cursor.item()
|
||||
&& transform.summary.input_rows > 0
|
||||
&& cursor.end() == old_start
|
||||
&& transform
|
||||
.block
|
||||
.as_ref()
|
||||
.map_or(true, |b| !b.is_replacement())
|
||||
{
|
||||
// Preserve the transform (push and next)
|
||||
new_transforms.push(transform.clone(), &());
|
||||
cursor.next();
|
||||
|
||||
// Preserve below blocks at end of edit
|
||||
while let Some(transform) = cursor.item() {
|
||||
if transform.block.as_ref().map_or(false, |b| b.place_below()) {
|
||||
new_transforms.push(transform.clone(), &());
|
||||
cursor.next();
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
// Preserve below blocks at end of edit
|
||||
while let Some(transform) = cursor.item() {
|
||||
if transform.block.as_ref().map_or(false, |b| b.place_below()) {
|
||||
new_transforms.push(transform.clone(), &());
|
||||
cursor.next();
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -657,10 +656,10 @@ impl BlockMap {
|
|||
.iter()
|
||||
.filter_map(|block| {
|
||||
let placement = block.placement.to_wrap_row(wrap_snapshot)?;
|
||||
if let BlockPlacement::Above(row) = placement {
|
||||
if row < new_start {
|
||||
return None;
|
||||
}
|
||||
if let BlockPlacement::Above(row) = placement
|
||||
&& row < new_start
|
||||
{
|
||||
return None;
|
||||
}
|
||||
Some((placement, Block::Custom(block.clone())))
|
||||
}),
|
||||
|
@ -977,10 +976,10 @@ impl BlockMapReader<'_> {
|
|||
break;
|
||||
}
|
||||
|
||||
if let Some(BlockId::Custom(id)) = transform.block.as_ref().map(|block| block.id()) {
|
||||
if id == block_id {
|
||||
return Some(cursor.start().1);
|
||||
}
|
||||
if let Some(BlockId::Custom(id)) = transform.block.as_ref().map(|block| block.id())
|
||||
&& id == block_id
|
||||
{
|
||||
return Some(cursor.start().1);
|
||||
}
|
||||
cursor.next();
|
||||
}
|
||||
|
@ -1299,14 +1298,14 @@ impl BlockSnapshot {
|
|||
|
||||
let mut input_start = transform_input_start;
|
||||
let mut input_end = transform_input_start;
|
||||
if let Some(transform) = cursor.item() {
|
||||
if transform.block.is_none() {
|
||||
input_start += rows.start - transform_output_start;
|
||||
input_end += cmp::min(
|
||||
rows.end - transform_output_start,
|
||||
transform.summary.input_rows,
|
||||
);
|
||||
}
|
||||
if let Some(transform) = cursor.item()
|
||||
&& transform.block.is_none()
|
||||
{
|
||||
input_start += rows.start - transform_output_start;
|
||||
input_end += cmp::min(
|
||||
rows.end - transform_output_start,
|
||||
transform.summary.input_rows,
|
||||
);
|
||||
}
|
||||
|
||||
BlockChunks {
|
||||
|
@ -1472,18 +1471,18 @@ impl BlockSnapshot {
|
|||
longest_row_chars = summary.longest_row_chars;
|
||||
}
|
||||
|
||||
if let Some(transform) = cursor.item() {
|
||||
if transform.block.is_none() {
|
||||
let Dimensions(output_start, input_start, _) = cursor.start();
|
||||
let overshoot = range.end.0 - output_start.0;
|
||||
let wrap_start_row = input_start.0;
|
||||
let wrap_end_row = input_start.0 + overshoot;
|
||||
let summary = self
|
||||
.wrap_snapshot
|
||||
.text_summary_for_range(wrap_start_row..wrap_end_row);
|
||||
if summary.longest_row_chars > longest_row_chars {
|
||||
longest_row = BlockRow(output_start.0 + summary.longest_row);
|
||||
}
|
||||
if let Some(transform) = cursor.item()
|
||||
&& transform.block.is_none()
|
||||
{
|
||||
let Dimensions(output_start, input_start, _) = cursor.start();
|
||||
let overshoot = range.end.0 - output_start.0;
|
||||
let wrap_start_row = input_start.0;
|
||||
let wrap_end_row = input_start.0 + overshoot;
|
||||
let summary = self
|
||||
.wrap_snapshot
|
||||
.text_summary_for_range(wrap_start_row..wrap_end_row);
|
||||
if summary.longest_row_chars > longest_row_chars {
|
||||
longest_row = BlockRow(output_start.0 + summary.longest_row);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1557,12 +1556,11 @@ impl BlockSnapshot {
|
|||
|
||||
match transform.block.as_ref() {
|
||||
Some(block) => {
|
||||
if block.is_replacement() {
|
||||
if ((bias == Bias::Left || search_left) && output_start <= point.0)
|
||||
|| (!search_left && output_start >= point.0)
|
||||
{
|
||||
return BlockPoint(output_start);
|
||||
}
|
||||
if block.is_replacement()
|
||||
&& (((bias == Bias::Left || search_left) && output_start <= point.0)
|
||||
|| (!search_left && output_start >= point.0))
|
||||
{
|
||||
return BlockPoint(output_start);
|
||||
}
|
||||
}
|
||||
None => {
|
||||
|
@ -3228,34 +3226,32 @@ mod tests {
|
|||
let mut is_in_replace_block = false;
|
||||
if let Some((BlockPlacement::Replace(replace_range), block)) =
|
||||
sorted_blocks_iter.peek()
|
||||
&& wrap_row >= replace_range.start().0
|
||||
{
|
||||
if wrap_row >= replace_range.start().0 {
|
||||
is_in_replace_block = true;
|
||||
is_in_replace_block = true;
|
||||
|
||||
if wrap_row == replace_range.start().0 {
|
||||
if matches!(block, Block::FoldedBuffer { .. }) {
|
||||
expected_buffer_rows.push(None);
|
||||
} else {
|
||||
expected_buffer_rows
|
||||
.push(input_buffer_rows[multibuffer_row as usize]);
|
||||
}
|
||||
if wrap_row == replace_range.start().0 {
|
||||
if matches!(block, Block::FoldedBuffer { .. }) {
|
||||
expected_buffer_rows.push(None);
|
||||
} else {
|
||||
expected_buffer_rows.push(input_buffer_rows[multibuffer_row as usize]);
|
||||
}
|
||||
}
|
||||
|
||||
if wrap_row == replace_range.end().0 {
|
||||
expected_block_positions.push((block_row, block.id()));
|
||||
let text = "\n".repeat((block.height() - 1) as usize);
|
||||
if block_row > 0 {
|
||||
expected_text.push('\n');
|
||||
}
|
||||
expected_text.push_str(&text);
|
||||
|
||||
for _ in 1..block.height() {
|
||||
expected_buffer_rows.push(None);
|
||||
}
|
||||
block_row += block.height();
|
||||
|
||||
sorted_blocks_iter.next();
|
||||
if wrap_row == replace_range.end().0 {
|
||||
expected_block_positions.push((block_row, block.id()));
|
||||
let text = "\n".repeat((block.height() - 1) as usize);
|
||||
if block_row > 0 {
|
||||
expected_text.push('\n');
|
||||
}
|
||||
expected_text.push_str(&text);
|
||||
|
||||
for _ in 1..block.height() {
|
||||
expected_buffer_rows.push(None);
|
||||
}
|
||||
block_row += block.height();
|
||||
|
||||
sorted_blocks_iter.next();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -289,25 +289,25 @@ impl FoldMapWriter<'_> {
|
|||
let ChunkRendererId::Fold(id) = id else {
|
||||
continue;
|
||||
};
|
||||
if let Some(metadata) = self.0.snapshot.fold_metadata_by_id.get(&id).cloned() {
|
||||
if Some(new_width) != metadata.width {
|
||||
let buffer_start = metadata.range.start.to_offset(buffer);
|
||||
let buffer_end = metadata.range.end.to_offset(buffer);
|
||||
let inlay_range = inlay_snapshot.to_inlay_offset(buffer_start)
|
||||
..inlay_snapshot.to_inlay_offset(buffer_end);
|
||||
edits.push(InlayEdit {
|
||||
old: inlay_range.clone(),
|
||||
new: inlay_range.clone(),
|
||||
});
|
||||
if let Some(metadata) = self.0.snapshot.fold_metadata_by_id.get(&id).cloned()
|
||||
&& Some(new_width) != metadata.width
|
||||
{
|
||||
let buffer_start = metadata.range.start.to_offset(buffer);
|
||||
let buffer_end = metadata.range.end.to_offset(buffer);
|
||||
let inlay_range = inlay_snapshot.to_inlay_offset(buffer_start)
|
||||
..inlay_snapshot.to_inlay_offset(buffer_end);
|
||||
edits.push(InlayEdit {
|
||||
old: inlay_range.clone(),
|
||||
new: inlay_range.clone(),
|
||||
});
|
||||
|
||||
self.0.snapshot.fold_metadata_by_id.insert(
|
||||
id,
|
||||
FoldMetadata {
|
||||
range: metadata.range,
|
||||
width: Some(new_width),
|
||||
},
|
||||
);
|
||||
}
|
||||
self.0.snapshot.fold_metadata_by_id.insert(
|
||||
id,
|
||||
FoldMetadata {
|
||||
range: metadata.range,
|
||||
width: Some(new_width),
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -417,18 +417,18 @@ impl FoldMap {
|
|||
cursor.seek(&InlayOffset(0), Bias::Right);
|
||||
|
||||
while let Some(mut edit) = inlay_edits_iter.next() {
|
||||
if let Some(item) = cursor.item() {
|
||||
if !item.is_fold() {
|
||||
new_transforms.update_last(
|
||||
|transform| {
|
||||
if !transform.is_fold() {
|
||||
transform.summary.add_summary(&item.summary, &());
|
||||
cursor.next();
|
||||
}
|
||||
},
|
||||
&(),
|
||||
);
|
||||
}
|
||||
if let Some(item) = cursor.item()
|
||||
&& !item.is_fold()
|
||||
{
|
||||
new_transforms.update_last(
|
||||
|transform| {
|
||||
if !transform.is_fold() {
|
||||
transform.summary.add_summary(&item.summary, &());
|
||||
cursor.next();
|
||||
}
|
||||
},
|
||||
&(),
|
||||
);
|
||||
}
|
||||
new_transforms.append(cursor.slice(&edit.old.start, Bias::Left), &());
|
||||
edit.new.start -= edit.old.start - *cursor.start();
|
||||
|
|
|
@ -557,11 +557,11 @@ impl InlayMap {
|
|||
let mut buffer_edits_iter = buffer_edits.iter().peekable();
|
||||
while let Some(buffer_edit) = buffer_edits_iter.next() {
|
||||
new_transforms.append(cursor.slice(&buffer_edit.old.start, Bias::Left), &());
|
||||
if let Some(Transform::Isomorphic(transform)) = cursor.item() {
|
||||
if cursor.end().0 == buffer_edit.old.start {
|
||||
push_isomorphic(&mut new_transforms, *transform);
|
||||
cursor.next();
|
||||
}
|
||||
if let Some(Transform::Isomorphic(transform)) = cursor.item()
|
||||
&& cursor.end().0 == buffer_edit.old.start
|
||||
{
|
||||
push_isomorphic(&mut new_transforms, *transform);
|
||||
cursor.next();
|
||||
}
|
||||
|
||||
// Remove all the inlays and transforms contained by the edit.
|
||||
|
|
|
@ -249,48 +249,48 @@ impl WrapMap {
|
|||
return;
|
||||
}
|
||||
|
||||
if let Some(wrap_width) = self.wrap_width {
|
||||
if self.background_task.is_none() {
|
||||
let pending_edits = self.pending_edits.clone();
|
||||
let mut snapshot = self.snapshot.clone();
|
||||
let text_system = cx.text_system().clone();
|
||||
let (font, font_size) = self.font_with_size.clone();
|
||||
let update_task = cx.background_spawn(async move {
|
||||
let mut edits = Patch::default();
|
||||
let mut line_wrapper = text_system.line_wrapper(font, font_size);
|
||||
for (tab_snapshot, tab_edits) in pending_edits {
|
||||
let wrap_edits = snapshot
|
||||
.update(tab_snapshot, &tab_edits, wrap_width, &mut line_wrapper)
|
||||
.await;
|
||||
edits = edits.compose(&wrap_edits);
|
||||
}
|
||||
(snapshot, edits)
|
||||
});
|
||||
if let Some(wrap_width) = self.wrap_width
|
||||
&& self.background_task.is_none()
|
||||
{
|
||||
let pending_edits = self.pending_edits.clone();
|
||||
let mut snapshot = self.snapshot.clone();
|
||||
let text_system = cx.text_system().clone();
|
||||
let (font, font_size) = self.font_with_size.clone();
|
||||
let update_task = cx.background_spawn(async move {
|
||||
let mut edits = Patch::default();
|
||||
let mut line_wrapper = text_system.line_wrapper(font, font_size);
|
||||
for (tab_snapshot, tab_edits) in pending_edits {
|
||||
let wrap_edits = snapshot
|
||||
.update(tab_snapshot, &tab_edits, wrap_width, &mut line_wrapper)
|
||||
.await;
|
||||
edits = edits.compose(&wrap_edits);
|
||||
}
|
||||
(snapshot, edits)
|
||||
});
|
||||
|
||||
match cx
|
||||
.background_executor()
|
||||
.block_with_timeout(Duration::from_millis(1), update_task)
|
||||
{
|
||||
Ok((snapshot, output_edits)) => {
|
||||
self.snapshot = snapshot;
|
||||
self.edits_since_sync = self.edits_since_sync.compose(&output_edits);
|
||||
}
|
||||
Err(update_task) => {
|
||||
self.background_task = Some(cx.spawn(async move |this, cx| {
|
||||
let (snapshot, edits) = update_task.await;
|
||||
this.update(cx, |this, cx| {
|
||||
this.snapshot = snapshot;
|
||||
this.edits_since_sync = this
|
||||
.edits_since_sync
|
||||
.compose(mem::take(&mut this.interpolated_edits).invert())
|
||||
.compose(&edits);
|
||||
this.background_task = None;
|
||||
this.flush_edits(cx);
|
||||
cx.notify();
|
||||
})
|
||||
.ok();
|
||||
}));
|
||||
}
|
||||
match cx
|
||||
.background_executor()
|
||||
.block_with_timeout(Duration::from_millis(1), update_task)
|
||||
{
|
||||
Ok((snapshot, output_edits)) => {
|
||||
self.snapshot = snapshot;
|
||||
self.edits_since_sync = self.edits_since_sync.compose(&output_edits);
|
||||
}
|
||||
Err(update_task) => {
|
||||
self.background_task = Some(cx.spawn(async move |this, cx| {
|
||||
let (snapshot, edits) = update_task.await;
|
||||
this.update(cx, |this, cx| {
|
||||
this.snapshot = snapshot;
|
||||
this.edits_since_sync = this
|
||||
.edits_since_sync
|
||||
.compose(mem::take(&mut this.interpolated_edits).invert())
|
||||
.compose(&edits);
|
||||
this.background_task = None;
|
||||
this.flush_edits(cx);
|
||||
cx.notify();
|
||||
})
|
||||
.ok();
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1065,12 +1065,12 @@ impl sum_tree::Item for Transform {
|
|||
}
|
||||
|
||||
fn push_isomorphic(transforms: &mut Vec<Transform>, summary: TextSummary) {
|
||||
if let Some(last_transform) = transforms.last_mut() {
|
||||
if last_transform.is_isomorphic() {
|
||||
last_transform.summary.input += &summary;
|
||||
last_transform.summary.output += &summary;
|
||||
return;
|
||||
}
|
||||
if let Some(last_transform) = transforms.last_mut()
|
||||
&& last_transform.is_isomorphic()
|
||||
{
|
||||
last_transform.summary.input += &summary;
|
||||
last_transform.summary.output += &summary;
|
||||
return;
|
||||
}
|
||||
transforms.push(Transform::isomorphic(summary));
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -917,6 +917,10 @@ impl EditorElement {
|
|||
} else if cfg!(any(target_os = "linux", target_os = "freebsd"))
|
||||
&& event.button == MouseButton::Middle
|
||||
{
|
||||
#[allow(
|
||||
clippy::collapsible_if,
|
||||
reason = "The cfg-block below makes this a false positive"
|
||||
)]
|
||||
if !text_hitbox.is_hovered(window) || editor.read_only(cx) {
|
||||
return;
|
||||
}
|
||||
|
@ -1387,29 +1391,27 @@ impl EditorElement {
|
|||
ref drop_cursor,
|
||||
ref hide_drop_cursor,
|
||||
} = editor.selection_drag_state
|
||||
&& !hide_drop_cursor
|
||||
&& (drop_cursor
|
||||
.start
|
||||
.cmp(&selection.start, &snapshot.buffer_snapshot)
|
||||
.eq(&Ordering::Less)
|
||||
|| drop_cursor
|
||||
.end
|
||||
.cmp(&selection.end, &snapshot.buffer_snapshot)
|
||||
.eq(&Ordering::Greater))
|
||||
{
|
||||
if !hide_drop_cursor
|
||||
&& (drop_cursor
|
||||
.start
|
||||
.cmp(&selection.start, &snapshot.buffer_snapshot)
|
||||
.eq(&Ordering::Less)
|
||||
|| drop_cursor
|
||||
.end
|
||||
.cmp(&selection.end, &snapshot.buffer_snapshot)
|
||||
.eq(&Ordering::Greater))
|
||||
{
|
||||
let drag_cursor_layout = SelectionLayout::new(
|
||||
drop_cursor.clone(),
|
||||
false,
|
||||
CursorShape::Bar,
|
||||
&snapshot.display_snapshot,
|
||||
false,
|
||||
false,
|
||||
None,
|
||||
);
|
||||
let absent_color = cx.theme().players().absent();
|
||||
selections.push((absent_color, vec![drag_cursor_layout]));
|
||||
}
|
||||
let drag_cursor_layout = SelectionLayout::new(
|
||||
drop_cursor.clone(),
|
||||
false,
|
||||
CursorShape::Bar,
|
||||
&snapshot.display_snapshot,
|
||||
false,
|
||||
false,
|
||||
None,
|
||||
);
|
||||
let absent_color = cx.theme().players().absent();
|
||||
selections.push((absent_color, vec![drag_cursor_layout]));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1420,19 +1422,15 @@ impl EditorElement {
|
|||
CollaboratorId::PeerId(peer_id) => {
|
||||
if let Some(collaborator) =
|
||||
collaboration_hub.collaborators(cx).get(&peer_id)
|
||||
{
|
||||
if let Some(participant_index) = collaboration_hub
|
||||
&& let Some(participant_index) = collaboration_hub
|
||||
.user_participant_indices(cx)
|
||||
.get(&collaborator.user_id)
|
||||
{
|
||||
if let Some((local_selection_style, _)) = selections.first_mut()
|
||||
{
|
||||
*local_selection_style = cx
|
||||
.theme()
|
||||
.players()
|
||||
.color_for_participant(participant_index.0);
|
||||
}
|
||||
}
|
||||
&& let Some((local_selection_style, _)) = selections.first_mut()
|
||||
{
|
||||
*local_selection_style = cx
|
||||
.theme()
|
||||
.players()
|
||||
.color_for_participant(participant_index.0);
|
||||
}
|
||||
}
|
||||
CollaboratorId::Agent => {
|
||||
|
@ -3518,33 +3516,33 @@ impl EditorElement {
|
|||
let mut x_offset = px(0.);
|
||||
let mut is_block = true;
|
||||
|
||||
if let BlockId::Custom(custom_block_id) = block_id {
|
||||
if block.has_height() {
|
||||
if block.place_near() {
|
||||
if let Some((x_target, line_width)) = x_position {
|
||||
let margin = em_width * 2;
|
||||
if line_width + final_size.width + margin
|
||||
< editor_width + editor_margins.gutter.full_width()
|
||||
&& !row_block_types.contains_key(&(row - 1))
|
||||
&& element_height_in_lines == 1
|
||||
{
|
||||
x_offset = line_width + margin;
|
||||
row = row - 1;
|
||||
is_block = false;
|
||||
element_height_in_lines = 0;
|
||||
row_block_types.insert(row, is_block);
|
||||
} else {
|
||||
let max_offset = editor_width + editor_margins.gutter.full_width()
|
||||
- final_size.width;
|
||||
let min_offset = (x_target + em_width - final_size.width)
|
||||
.max(editor_margins.gutter.full_width());
|
||||
x_offset = x_target.min(max_offset).max(min_offset);
|
||||
}
|
||||
}
|
||||
};
|
||||
if element_height_in_lines != block.height() {
|
||||
resized_blocks.insert(custom_block_id, element_height_in_lines);
|
||||
if let BlockId::Custom(custom_block_id) = block_id
|
||||
&& block.has_height()
|
||||
{
|
||||
if block.place_near()
|
||||
&& let Some((x_target, line_width)) = x_position
|
||||
{
|
||||
let margin = em_width * 2;
|
||||
if line_width + final_size.width + margin
|
||||
< editor_width + editor_margins.gutter.full_width()
|
||||
&& !row_block_types.contains_key(&(row - 1))
|
||||
&& element_height_in_lines == 1
|
||||
{
|
||||
x_offset = line_width + margin;
|
||||
row = row - 1;
|
||||
is_block = false;
|
||||
element_height_in_lines = 0;
|
||||
row_block_types.insert(row, is_block);
|
||||
} else {
|
||||
let max_offset =
|
||||
editor_width + editor_margins.gutter.full_width() - final_size.width;
|
||||
let min_offset = (x_target + em_width - final_size.width)
|
||||
.max(editor_margins.gutter.full_width());
|
||||
x_offset = x_target.min(max_offset).max(min_offset);
|
||||
}
|
||||
};
|
||||
if element_height_in_lines != block.height() {
|
||||
resized_blocks.insert(custom_block_id, element_height_in_lines);
|
||||
}
|
||||
}
|
||||
for i in 0..element_height_in_lines {
|
||||
|
@ -3987,60 +3985,58 @@ impl EditorElement {
|
|||
}
|
||||
}
|
||||
|
||||
if let Some(focused_block) = focused_block {
|
||||
if let Some(focus_handle) = focused_block.focus_handle.upgrade() {
|
||||
if focus_handle.is_focused(window) {
|
||||
if let Some(block) = snapshot.block_for_id(focused_block.id) {
|
||||
let style = block.style();
|
||||
let width = match style {
|
||||
BlockStyle::Fixed => AvailableSpace::MinContent,
|
||||
BlockStyle::Flex => AvailableSpace::Definite(
|
||||
hitbox
|
||||
.size
|
||||
.width
|
||||
.max(fixed_block_max_width)
|
||||
.max(editor_margins.gutter.width + *scroll_width),
|
||||
),
|
||||
BlockStyle::Sticky => AvailableSpace::Definite(hitbox.size.width),
|
||||
};
|
||||
if let Some(focused_block) = focused_block
|
||||
&& let Some(focus_handle) = focused_block.focus_handle.upgrade()
|
||||
&& focus_handle.is_focused(window)
|
||||
&& let Some(block) = snapshot.block_for_id(focused_block.id)
|
||||
{
|
||||
let style = block.style();
|
||||
let width = match style {
|
||||
BlockStyle::Fixed => AvailableSpace::MinContent,
|
||||
BlockStyle::Flex => AvailableSpace::Definite(
|
||||
hitbox
|
||||
.size
|
||||
.width
|
||||
.max(fixed_block_max_width)
|
||||
.max(editor_margins.gutter.width + *scroll_width),
|
||||
),
|
||||
BlockStyle::Sticky => AvailableSpace::Definite(hitbox.size.width),
|
||||
};
|
||||
|
||||
if let Some((element, element_size, _, x_offset)) = self.render_block(
|
||||
&block,
|
||||
width,
|
||||
focused_block.id,
|
||||
rows.end,
|
||||
snapshot,
|
||||
text_x,
|
||||
&rows,
|
||||
line_layouts,
|
||||
editor_margins,
|
||||
line_height,
|
||||
em_width,
|
||||
text_hitbox,
|
||||
editor_width,
|
||||
scroll_width,
|
||||
&mut resized_blocks,
|
||||
&mut row_block_types,
|
||||
selections,
|
||||
selected_buffer_ids,
|
||||
is_row_soft_wrapped,
|
||||
sticky_header_excerpt_id,
|
||||
window,
|
||||
cx,
|
||||
) {
|
||||
blocks.push(BlockLayout {
|
||||
id: block.id(),
|
||||
x_offset,
|
||||
row: None,
|
||||
element,
|
||||
available_space: size(width, element_size.height.into()),
|
||||
style,
|
||||
overlaps_gutter: true,
|
||||
is_buffer_header: block.is_buffer_header(),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some((element, element_size, _, x_offset)) = self.render_block(
|
||||
&block,
|
||||
width,
|
||||
focused_block.id,
|
||||
rows.end,
|
||||
snapshot,
|
||||
text_x,
|
||||
&rows,
|
||||
line_layouts,
|
||||
editor_margins,
|
||||
line_height,
|
||||
em_width,
|
||||
text_hitbox,
|
||||
editor_width,
|
||||
scroll_width,
|
||||
&mut resized_blocks,
|
||||
&mut row_block_types,
|
||||
selections,
|
||||
selected_buffer_ids,
|
||||
is_row_soft_wrapped,
|
||||
sticky_header_excerpt_id,
|
||||
window,
|
||||
cx,
|
||||
) {
|
||||
blocks.push(BlockLayout {
|
||||
id: block.id(),
|
||||
x_offset,
|
||||
row: None,
|
||||
element,
|
||||
available_space: size(width, element_size.height.into()),
|
||||
style,
|
||||
overlaps_gutter: true,
|
||||
is_buffer_header: block.is_buffer_header(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4203,19 +4199,19 @@ impl EditorElement {
|
|||
edit_prediction_popover_visible = true;
|
||||
}
|
||||
|
||||
if editor.context_menu_visible() {
|
||||
if let Some(crate::ContextMenuOrigin::Cursor) = editor.context_menu_origin() {
|
||||
let (min_height_in_lines, max_height_in_lines) = editor
|
||||
.context_menu_options
|
||||
.as_ref()
|
||||
.map_or((3, 12), |options| {
|
||||
(options.min_entries_visible, options.max_entries_visible)
|
||||
});
|
||||
if editor.context_menu_visible()
|
||||
&& let Some(crate::ContextMenuOrigin::Cursor) = editor.context_menu_origin()
|
||||
{
|
||||
let (min_height_in_lines, max_height_in_lines) = editor
|
||||
.context_menu_options
|
||||
.as_ref()
|
||||
.map_or((3, 12), |options| {
|
||||
(options.min_entries_visible, options.max_entries_visible)
|
||||
});
|
||||
|
||||
min_menu_height += line_height * min_height_in_lines as f32 + POPOVER_Y_PADDING;
|
||||
max_menu_height += line_height * max_height_in_lines as f32 + POPOVER_Y_PADDING;
|
||||
context_menu_visible = true;
|
||||
}
|
||||
min_menu_height += line_height * min_height_in_lines as f32 + POPOVER_Y_PADDING;
|
||||
max_menu_height += line_height * max_height_in_lines as f32 + POPOVER_Y_PADDING;
|
||||
context_menu_visible = true;
|
||||
}
|
||||
context_menu_placement = editor
|
||||
.context_menu_options
|
||||
|
@ -5761,16 +5757,15 @@ impl EditorElement {
|
|||
cx: &mut App,
|
||||
) {
|
||||
for (_, hunk_hitbox) in &layout.display_hunks {
|
||||
if let Some(hunk_hitbox) = hunk_hitbox {
|
||||
if !self
|
||||
if let Some(hunk_hitbox) = hunk_hitbox
|
||||
&& !self
|
||||
.editor
|
||||
.read(cx)
|
||||
.buffer()
|
||||
.read(cx)
|
||||
.all_diff_hunks_expanded()
|
||||
{
|
||||
window.set_cursor_style(CursorStyle::PointingHand, hunk_hitbox);
|
||||
}
|
||||
{
|
||||
window.set_cursor_style(CursorStyle::PointingHand, hunk_hitbox);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10152,10 +10147,10 @@ fn compute_auto_height_layout(
|
|||
let overscroll = size(em_width, px(0.));
|
||||
|
||||
let editor_width = text_width - gutter_dimensions.margin - overscroll.width - em_width;
|
||||
if !matches!(editor.soft_wrap_mode(cx), SoftWrap::None) {
|
||||
if editor.set_wrap_width(Some(editor_width), cx) {
|
||||
snapshot = editor.snapshot(window, cx);
|
||||
}
|
||||
if !matches!(editor.soft_wrap_mode(cx), SoftWrap::None)
|
||||
&& editor.set_wrap_width(Some(editor_width), cx)
|
||||
{
|
||||
snapshot = editor.snapshot(window, cx);
|
||||
}
|
||||
|
||||
let scroll_height = (snapshot.max_point().row().next_row().0 as f32) * line_height;
|
||||
|
|
|
@ -312,10 +312,10 @@ impl GitBlame {
|
|||
.as_ref()
|
||||
.and_then(|entry| entry.author.as_ref())
|
||||
.map(|author| author.len());
|
||||
if let Some(author_len) = author_len {
|
||||
if author_len > max_author_length {
|
||||
max_author_length = author_len;
|
||||
}
|
||||
if let Some(author_len) = author_len
|
||||
&& author_len > max_author_length
|
||||
{
|
||||
max_author_length = author_len;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -416,20 +416,19 @@ impl GitBlame {
|
|||
if row_edits
|
||||
.peek()
|
||||
.map_or(true, |next_edit| next_edit.old.start >= old_end)
|
||||
&& let Some(entry) = cursor.item()
|
||||
{
|
||||
if let Some(entry) = cursor.item() {
|
||||
if old_end > edit.old.end {
|
||||
new_entries.push(
|
||||
GitBlameEntry {
|
||||
rows: cursor.end() - edit.old.end,
|
||||
blame: entry.blame.clone(),
|
||||
},
|
||||
&(),
|
||||
);
|
||||
}
|
||||
|
||||
cursor.next();
|
||||
if old_end > edit.old.end {
|
||||
new_entries.push(
|
||||
GitBlameEntry {
|
||||
rows: cursor.end() - edit.old.end,
|
||||
blame: entry.blame.clone(),
|
||||
},
|
||||
&(),
|
||||
);
|
||||
}
|
||||
|
||||
cursor.next();
|
||||
}
|
||||
}
|
||||
new_entries.append(cursor.suffix(), &());
|
||||
|
|
|
@ -418,24 +418,22 @@ pub fn update_inlay_link_and_hover_points(
|
|||
}
|
||||
if let Some((language_server_id, location)) =
|
||||
hovered_hint_part.location
|
||||
&& secondary_held
|
||||
&& !editor.has_pending_nonempty_selection()
|
||||
{
|
||||
if secondary_held
|
||||
&& !editor.has_pending_nonempty_selection()
|
||||
{
|
||||
go_to_definition_updated = true;
|
||||
show_link_definition(
|
||||
shift_held,
|
||||
editor,
|
||||
TriggerPoint::InlayHint(
|
||||
highlight,
|
||||
location,
|
||||
language_server_id,
|
||||
),
|
||||
snapshot,
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
}
|
||||
go_to_definition_updated = true;
|
||||
show_link_definition(
|
||||
shift_held,
|
||||
editor,
|
||||
TriggerPoint::InlayHint(
|
||||
highlight,
|
||||
location,
|
||||
language_server_id,
|
||||
),
|
||||
snapshot,
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -766,10 +764,11 @@ pub(crate) fn find_url_from_range(
|
|||
let mut finder = LinkFinder::new();
|
||||
finder.kinds(&[LinkKind::Url]);
|
||||
|
||||
if let Some(link) = finder.links(&text).next() {
|
||||
if link.start() == 0 && link.end() == text.len() {
|
||||
return Some(link.as_str().to_string());
|
||||
}
|
||||
if let Some(link) = finder.links(&text).next()
|
||||
&& link.start() == 0
|
||||
&& link.end() == text.len()
|
||||
{
|
||||
return Some(link.as_str().to_string());
|
||||
}
|
||||
|
||||
None
|
||||
|
|
|
@ -142,11 +142,11 @@ pub fn hover_at_inlay(
|
|||
.info_popovers
|
||||
.iter()
|
||||
.any(|InfoPopover { symbol_range, .. }| {
|
||||
if let RangeInEditor::Inlay(range) = symbol_range {
|
||||
if range == &inlay_hover.range {
|
||||
// Hover triggered from same location as last time. Don't show again.
|
||||
return true;
|
||||
}
|
||||
if let RangeInEditor::Inlay(range) = symbol_range
|
||||
&& range == &inlay_hover.range
|
||||
{
|
||||
// Hover triggered from same location as last time. Don't show again.
|
||||
return true;
|
||||
}
|
||||
false
|
||||
})
|
||||
|
@ -270,13 +270,12 @@ fn show_hover(
|
|||
}
|
||||
|
||||
// Don't request again if the location is the same as the previous request
|
||||
if let Some(triggered_from) = &editor.hover_state.triggered_from {
|
||||
if triggered_from
|
||||
if let Some(triggered_from) = &editor.hover_state.triggered_from
|
||||
&& triggered_from
|
||||
.cmp(&anchor, &snapshot.buffer_snapshot)
|
||||
.is_eq()
|
||||
{
|
||||
return None;
|
||||
}
|
||||
{
|
||||
return None;
|
||||
}
|
||||
|
||||
let hover_popover_delay = EditorSettings::get_global(cx).hover_popover_delay;
|
||||
|
@ -717,59 +716,54 @@ pub fn diagnostics_markdown_style(window: &Window, cx: &App) -> MarkdownStyle {
|
|||
}
|
||||
|
||||
pub fn open_markdown_url(link: SharedString, window: &mut Window, cx: &mut App) {
|
||||
if let Ok(uri) = Url::parse(&link) {
|
||||
if uri.scheme() == "file" {
|
||||
if let Some(workspace) = window.root::<Workspace>().flatten() {
|
||||
workspace.update(cx, |workspace, cx| {
|
||||
let task = workspace.open_abs_path(
|
||||
PathBuf::from(uri.path()),
|
||||
OpenOptions {
|
||||
visible: Some(OpenVisible::None),
|
||||
..Default::default()
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
if let Ok(uri) = Url::parse(&link)
|
||||
&& uri.scheme() == "file"
|
||||
&& let Some(workspace) = window.root::<Workspace>().flatten()
|
||||
{
|
||||
workspace.update(cx, |workspace, cx| {
|
||||
let task = workspace.open_abs_path(
|
||||
PathBuf::from(uri.path()),
|
||||
OpenOptions {
|
||||
visible: Some(OpenVisible::None),
|
||||
..Default::default()
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
|
||||
cx.spawn_in(window, async move |_, cx| {
|
||||
let item = task.await?;
|
||||
// Ruby LSP uses URLs with #L1,1-4,4
|
||||
// we'll just take the first number and assume it's a line number
|
||||
let Some(fragment) = uri.fragment() else {
|
||||
return anyhow::Ok(());
|
||||
};
|
||||
let mut accum = 0u32;
|
||||
for c in fragment.chars() {
|
||||
if c >= '0' && c <= '9' && accum < u32::MAX / 2 {
|
||||
accum *= 10;
|
||||
accum += c as u32 - '0' as u32;
|
||||
} else if accum > 0 {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if accum == 0 {
|
||||
return Ok(());
|
||||
}
|
||||
let Some(editor) = cx.update(|_, cx| item.act_as::<Editor>(cx))? else {
|
||||
return Ok(());
|
||||
};
|
||||
editor.update_in(cx, |editor, window, cx| {
|
||||
editor.change_selections(
|
||||
Default::default(),
|
||||
window,
|
||||
cx,
|
||||
|selections| {
|
||||
selections.select_ranges([text::Point::new(accum - 1, 0)
|
||||
..text::Point::new(accum - 1, 0)]);
|
||||
},
|
||||
);
|
||||
})
|
||||
})
|
||||
.detach_and_log_err(cx);
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
cx.spawn_in(window, async move |_, cx| {
|
||||
let item = task.await?;
|
||||
// Ruby LSP uses URLs with #L1,1-4,4
|
||||
// we'll just take the first number and assume it's a line number
|
||||
let Some(fragment) = uri.fragment() else {
|
||||
return anyhow::Ok(());
|
||||
};
|
||||
let mut accum = 0u32;
|
||||
for c in fragment.chars() {
|
||||
if c >= '0' && c <= '9' && accum < u32::MAX / 2 {
|
||||
accum *= 10;
|
||||
accum += c as u32 - '0' as u32;
|
||||
} else if accum > 0 {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if accum == 0 {
|
||||
return Ok(());
|
||||
}
|
||||
let Some(editor) = cx.update(|_, cx| item.act_as::<Editor>(cx))? else {
|
||||
return Ok(());
|
||||
};
|
||||
editor.update_in(cx, |editor, window, cx| {
|
||||
editor.change_selections(Default::default(), window, cx, |selections| {
|
||||
selections.select_ranges([
|
||||
text::Point::new(accum - 1, 0)..text::Point::new(accum - 1, 0)
|
||||
]);
|
||||
});
|
||||
})
|
||||
})
|
||||
.detach_and_log_err(cx);
|
||||
});
|
||||
return;
|
||||
}
|
||||
cx.open_url(&link);
|
||||
}
|
||||
|
@ -839,21 +833,20 @@ impl HoverState {
|
|||
pub fn focused(&self, window: &mut Window, cx: &mut Context<Editor>) -> bool {
|
||||
let mut hover_popover_is_focused = false;
|
||||
for info_popover in &self.info_popovers {
|
||||
if let Some(markdown_view) = &info_popover.parsed_content {
|
||||
if markdown_view.focus_handle(cx).is_focused(window) {
|
||||
hover_popover_is_focused = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(diagnostic_popover) = &self.diagnostic_popover {
|
||||
if diagnostic_popover
|
||||
.markdown
|
||||
.focus_handle(cx)
|
||||
.is_focused(window)
|
||||
if let Some(markdown_view) = &info_popover.parsed_content
|
||||
&& markdown_view.focus_handle(cx).is_focused(window)
|
||||
{
|
||||
hover_popover_is_focused = true;
|
||||
}
|
||||
}
|
||||
if let Some(diagnostic_popover) = &self.diagnostic_popover
|
||||
&& diagnostic_popover
|
||||
.markdown
|
||||
.focus_handle(cx)
|
||||
.is_focused(window)
|
||||
{
|
||||
hover_popover_is_focused = true;
|
||||
}
|
||||
hover_popover_is_focused
|
||||
}
|
||||
}
|
||||
|
|
|
@ -168,11 +168,11 @@ pub fn indent_guides_in_range(
|
|||
while let Some(fold) = folds.next() {
|
||||
let start = fold.range.start.to_point(&snapshot.buffer_snapshot);
|
||||
let end = fold.range.end.to_point(&snapshot.buffer_snapshot);
|
||||
if let Some(last_range) = fold_ranges.last_mut() {
|
||||
if last_range.end >= start {
|
||||
last_range.end = last_range.end.max(end);
|
||||
continue;
|
||||
}
|
||||
if let Some(last_range) = fold_ranges.last_mut()
|
||||
&& last_range.end >= start
|
||||
{
|
||||
last_range.end = last_range.end.max(end);
|
||||
continue;
|
||||
}
|
||||
fold_ranges.push(start..end);
|
||||
}
|
||||
|
|
|
@ -498,16 +498,14 @@ impl InlayHintCache {
|
|||
cmp::Ordering::Less | cmp::Ordering::Equal => {
|
||||
if !old_kinds.contains(&cached_hint.kind)
|
||||
&& new_kinds.contains(&cached_hint.kind)
|
||||
{
|
||||
if let Some(anchor) = multi_buffer_snapshot
|
||||
&& let Some(anchor) = multi_buffer_snapshot
|
||||
.anchor_in_excerpt(*excerpt_id, cached_hint.position)
|
||||
{
|
||||
to_insert.push(Inlay::hint(
|
||||
cached_hint_id.id(),
|
||||
anchor,
|
||||
cached_hint,
|
||||
));
|
||||
}
|
||||
{
|
||||
to_insert.push(Inlay::hint(
|
||||
cached_hint_id.id(),
|
||||
anchor,
|
||||
cached_hint,
|
||||
));
|
||||
}
|
||||
excerpt_cache.next();
|
||||
}
|
||||
|
@ -522,16 +520,16 @@ impl InlayHintCache {
|
|||
for cached_hint_id in excerpt_cache {
|
||||
let maybe_missed_cached_hint = &excerpt_cached_hints.hints_by_id[cached_hint_id];
|
||||
let cached_hint_kind = maybe_missed_cached_hint.kind;
|
||||
if !old_kinds.contains(&cached_hint_kind) && new_kinds.contains(&cached_hint_kind) {
|
||||
if let Some(anchor) = multi_buffer_snapshot
|
||||
if !old_kinds.contains(&cached_hint_kind)
|
||||
&& new_kinds.contains(&cached_hint_kind)
|
||||
&& let Some(anchor) = multi_buffer_snapshot
|
||||
.anchor_in_excerpt(*excerpt_id, maybe_missed_cached_hint.position)
|
||||
{
|
||||
to_insert.push(Inlay::hint(
|
||||
cached_hint_id.id(),
|
||||
anchor,
|
||||
maybe_missed_cached_hint,
|
||||
));
|
||||
}
|
||||
{
|
||||
to_insert.push(Inlay::hint(
|
||||
cached_hint_id.id(),
|
||||
anchor,
|
||||
maybe_missed_cached_hint,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -620,44 +618,44 @@ impl InlayHintCache {
|
|||
) {
|
||||
if let Some(excerpt_hints) = self.hints.get(&excerpt_id) {
|
||||
let mut guard = excerpt_hints.write();
|
||||
if let Some(cached_hint) = guard.hints_by_id.get_mut(&id) {
|
||||
if let ResolveState::CanResolve(server_id, _) = &cached_hint.resolve_state {
|
||||
let hint_to_resolve = cached_hint.clone();
|
||||
let server_id = *server_id;
|
||||
cached_hint.resolve_state = ResolveState::Resolving;
|
||||
drop(guard);
|
||||
cx.spawn_in(window, async move |editor, cx| {
|
||||
let resolved_hint_task = editor.update(cx, |editor, cx| {
|
||||
let buffer = editor.buffer().read(cx).buffer(buffer_id)?;
|
||||
editor.semantics_provider.as_ref()?.resolve_inlay_hint(
|
||||
hint_to_resolve,
|
||||
buffer,
|
||||
server_id,
|
||||
cx,
|
||||
)
|
||||
})?;
|
||||
if let Some(resolved_hint_task) = resolved_hint_task {
|
||||
let mut resolved_hint =
|
||||
resolved_hint_task.await.context("hint resolve task")?;
|
||||
editor.read_with(cx, |editor, _| {
|
||||
if let Some(excerpt_hints) =
|
||||
editor.inlay_hint_cache.hints.get(&excerpt_id)
|
||||
if let Some(cached_hint) = guard.hints_by_id.get_mut(&id)
|
||||
&& let ResolveState::CanResolve(server_id, _) = &cached_hint.resolve_state
|
||||
{
|
||||
let hint_to_resolve = cached_hint.clone();
|
||||
let server_id = *server_id;
|
||||
cached_hint.resolve_state = ResolveState::Resolving;
|
||||
drop(guard);
|
||||
cx.spawn_in(window, async move |editor, cx| {
|
||||
let resolved_hint_task = editor.update(cx, |editor, cx| {
|
||||
let buffer = editor.buffer().read(cx).buffer(buffer_id)?;
|
||||
editor.semantics_provider.as_ref()?.resolve_inlay_hint(
|
||||
hint_to_resolve,
|
||||
buffer,
|
||||
server_id,
|
||||
cx,
|
||||
)
|
||||
})?;
|
||||
if let Some(resolved_hint_task) = resolved_hint_task {
|
||||
let mut resolved_hint =
|
||||
resolved_hint_task.await.context("hint resolve task")?;
|
||||
editor.read_with(cx, |editor, _| {
|
||||
if let Some(excerpt_hints) =
|
||||
editor.inlay_hint_cache.hints.get(&excerpt_id)
|
||||
{
|
||||
let mut guard = excerpt_hints.write();
|
||||
if let Some(cached_hint) = guard.hints_by_id.get_mut(&id)
|
||||
&& cached_hint.resolve_state == ResolveState::Resolving
|
||||
{
|
||||
let mut guard = excerpt_hints.write();
|
||||
if let Some(cached_hint) = guard.hints_by_id.get_mut(&id) {
|
||||
if cached_hint.resolve_state == ResolveState::Resolving {
|
||||
resolved_hint.resolve_state = ResolveState::Resolved;
|
||||
*cached_hint = resolved_hint;
|
||||
}
|
||||
}
|
||||
resolved_hint.resolve_state = ResolveState::Resolved;
|
||||
*cached_hint = resolved_hint;
|
||||
}
|
||||
})?;
|
||||
}
|
||||
}
|
||||
})?;
|
||||
}
|
||||
|
||||
anyhow::Ok(())
|
||||
})
|
||||
.detach_and_log_err(cx);
|
||||
}
|
||||
anyhow::Ok(())
|
||||
})
|
||||
.detach_and_log_err(cx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -990,8 +988,8 @@ fn fetch_and_update_hints(
|
|||
|
||||
let buffer = editor.buffer().read(cx).buffer(query.buffer_id)?;
|
||||
|
||||
if !editor.registered_buffers.contains_key(&query.buffer_id) {
|
||||
if let Some(project) = editor.project.as_ref() {
|
||||
if !editor.registered_buffers.contains_key(&query.buffer_id)
|
||||
&& let Some(project) = editor.project.as_ref() {
|
||||
project.update(cx, |project, cx| {
|
||||
editor.registered_buffers.insert(
|
||||
query.buffer_id,
|
||||
|
@ -999,7 +997,6 @@ fn fetch_and_update_hints(
|
|||
);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
editor
|
||||
.semantics_provider
|
||||
|
@ -1240,14 +1237,12 @@ fn apply_hint_update(
|
|||
.inlay_hint_cache
|
||||
.allowed_hint_kinds
|
||||
.contains(&new_hint.kind)
|
||||
{
|
||||
if let Some(new_hint_position) =
|
||||
&& let Some(new_hint_position) =
|
||||
multi_buffer_snapshot.anchor_in_excerpt(query.excerpt_id, new_hint.position)
|
||||
{
|
||||
splice
|
||||
.to_insert
|
||||
.push(Inlay::hint(new_inlay_id, new_hint_position, &new_hint));
|
||||
}
|
||||
{
|
||||
splice
|
||||
.to_insert
|
||||
.push(Inlay::hint(new_inlay_id, new_hint_position, &new_hint));
|
||||
}
|
||||
let new_id = InlayId::Hint(new_inlay_id);
|
||||
cached_excerpt_hints.hints_by_id.insert(new_id, new_hint);
|
||||
|
|
|
@ -930,10 +930,10 @@ impl Item for Editor {
|
|||
})?;
|
||||
buffer
|
||||
.update(cx, |buffer, cx| {
|
||||
if let Some(transaction) = transaction {
|
||||
if !buffer.is_singleton() {
|
||||
buffer.push_transaction(&transaction.0, cx);
|
||||
}
|
||||
if let Some(transaction) = transaction
|
||||
&& !buffer.is_singleton()
|
||||
{
|
||||
buffer.push_transaction(&transaction.0, cx);
|
||||
}
|
||||
})
|
||||
.ok();
|
||||
|
@ -1374,36 +1374,33 @@ impl ProjectItem for Editor {
|
|||
let mut editor = Self::for_buffer(buffer.clone(), Some(project), window, cx);
|
||||
if let Some((excerpt_id, buffer_id, snapshot)) =
|
||||
editor.buffer().read(cx).snapshot(cx).as_singleton()
|
||||
&& WorkspaceSettings::get(None, cx).restore_on_file_reopen
|
||||
&& let Some(restoration_data) = Self::project_item_kind()
|
||||
.and_then(|kind| pane.as_ref()?.project_item_restoration_data.get(&kind))
|
||||
.and_then(|data| data.downcast_ref::<EditorRestorationData>())
|
||||
.and_then(|data| {
|
||||
let file = project::File::from_dyn(buffer.read(cx).file())?;
|
||||
data.entries.get(&file.abs_path(cx))
|
||||
})
|
||||
{
|
||||
if WorkspaceSettings::get(None, cx).restore_on_file_reopen {
|
||||
if let Some(restoration_data) = Self::project_item_kind()
|
||||
.and_then(|kind| pane.as_ref()?.project_item_restoration_data.get(&kind))
|
||||
.and_then(|data| data.downcast_ref::<EditorRestorationData>())
|
||||
.and_then(|data| {
|
||||
let file = project::File::from_dyn(buffer.read(cx).file())?;
|
||||
data.entries.get(&file.abs_path(cx))
|
||||
})
|
||||
{
|
||||
editor.fold_ranges(
|
||||
clip_ranges(&restoration_data.folds, snapshot),
|
||||
false,
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
if !restoration_data.selections.is_empty() {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
|
||||
s.select_ranges(clip_ranges(&restoration_data.selections, snapshot));
|
||||
});
|
||||
}
|
||||
let (top_row, offset) = restoration_data.scroll_position;
|
||||
let anchor = Anchor::in_buffer(
|
||||
*excerpt_id,
|
||||
buffer_id,
|
||||
snapshot.anchor_before(Point::new(top_row, 0)),
|
||||
);
|
||||
editor.set_scroll_anchor(ScrollAnchor { anchor, offset }, window, cx);
|
||||
}
|
||||
editor.fold_ranges(
|
||||
clip_ranges(&restoration_data.folds, snapshot),
|
||||
false,
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
if !restoration_data.selections.is_empty() {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
|
||||
s.select_ranges(clip_ranges(&restoration_data.selections, snapshot));
|
||||
});
|
||||
}
|
||||
let (top_row, offset) = restoration_data.scroll_position;
|
||||
let anchor = Anchor::in_buffer(
|
||||
*excerpt_id,
|
||||
buffer_id,
|
||||
snapshot.anchor_before(Point::new(top_row, 0)),
|
||||
);
|
||||
editor.set_scroll_anchor(ScrollAnchor { anchor, offset }, window, cx);
|
||||
}
|
||||
|
||||
editor
|
||||
|
|
|
@ -51,12 +51,11 @@ pub(crate) fn should_auto_close(
|
|||
continue;
|
||||
};
|
||||
let mut jsx_open_tag_node = node;
|
||||
if node.grammar_name() != config.open_tag_node_name {
|
||||
if let Some(parent) = node.parent() {
|
||||
if parent.grammar_name() == config.open_tag_node_name {
|
||||
jsx_open_tag_node = parent;
|
||||
}
|
||||
}
|
||||
if node.grammar_name() != config.open_tag_node_name
|
||||
&& let Some(parent) = node.parent()
|
||||
&& parent.grammar_name() == config.open_tag_node_name
|
||||
{
|
||||
jsx_open_tag_node = parent;
|
||||
}
|
||||
if jsx_open_tag_node.grammar_name() != config.open_tag_node_name {
|
||||
continue;
|
||||
|
@ -284,10 +283,8 @@ pub(crate) fn generate_auto_close_edits(
|
|||
unclosed_open_tag_count -= 1;
|
||||
}
|
||||
} else if has_erroneous_close_tag && kind == erroneous_close_tag_node_name {
|
||||
if tag_node_name_equals(&node, &tag_name) {
|
||||
if !is_after_open_tag(&node) {
|
||||
unclosed_open_tag_count -= 1;
|
||||
}
|
||||
if tag_node_name_equals(&node, &tag_name) && !is_after_open_tag(&node) {
|
||||
unclosed_open_tag_count -= 1;
|
||||
}
|
||||
} else if kind == config.jsx_element_node_name {
|
||||
// perf: filter only open,close,element,erroneous nodes
|
||||
|
|
|
@ -147,16 +147,15 @@ pub fn lsp_tasks(
|
|||
},
|
||||
cx,
|
||||
)
|
||||
}) {
|
||||
if let Some(new_runnables) = runnables_task.await.log_err() {
|
||||
new_lsp_tasks.extend(new_runnables.runnables.into_iter().filter_map(
|
||||
|(location, runnable)| {
|
||||
let resolved_task =
|
||||
runnable.resolve_task(&id_base, &lsp_buffer_context)?;
|
||||
Some((location, resolved_task))
|
||||
},
|
||||
));
|
||||
}
|
||||
}) && let Some(new_runnables) = runnables_task.await.log_err()
|
||||
{
|
||||
new_lsp_tasks.extend(new_runnables.runnables.into_iter().filter_map(
|
||||
|(location, runnable)| {
|
||||
let resolved_task =
|
||||
runnable.resolve_task(&id_base, &lsp_buffer_context)?;
|
||||
Some((location, resolved_task))
|
||||
},
|
||||
));
|
||||
}
|
||||
lsp_tasks
|
||||
.entry(source_kind)
|
||||
|
|
|
@ -510,10 +510,10 @@ pub fn find_preceding_boundary_point(
|
|||
if find_range == FindRange::SingleLine && ch == '\n' {
|
||||
break;
|
||||
}
|
||||
if let Some(prev_ch) = prev_ch {
|
||||
if is_boundary(ch, prev_ch) {
|
||||
break;
|
||||
}
|
||||
if let Some(prev_ch) = prev_ch
|
||||
&& is_boundary(ch, prev_ch)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
offset -= ch.len_utf8();
|
||||
|
@ -562,13 +562,13 @@ pub fn find_boundary_point(
|
|||
if find_range == FindRange::SingleLine && ch == '\n' {
|
||||
break;
|
||||
}
|
||||
if let Some(prev_ch) = prev_ch {
|
||||
if is_boundary(prev_ch, ch) {
|
||||
if return_point_before_boundary {
|
||||
return map.clip_point(prev_offset.to_display_point(map), Bias::Right);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
if let Some(prev_ch) = prev_ch
|
||||
&& is_boundary(prev_ch, ch)
|
||||
{
|
||||
if return_point_before_boundary {
|
||||
return map.clip_point(prev_offset.to_display_point(map), Bias::Right);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
prev_offset = offset;
|
||||
|
@ -603,13 +603,13 @@ pub fn find_preceding_boundary_trail(
|
|||
// Find the boundary
|
||||
let start_offset = offset;
|
||||
for ch in forward {
|
||||
if let Some(prev_ch) = prev_ch {
|
||||
if is_boundary(prev_ch, ch) {
|
||||
if start_offset == offset {
|
||||
trail_offset = Some(offset);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
if let Some(prev_ch) = prev_ch
|
||||
&& is_boundary(prev_ch, ch)
|
||||
{
|
||||
if start_offset == offset {
|
||||
trail_offset = Some(offset);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
offset -= ch.len_utf8();
|
||||
|
@ -651,13 +651,13 @@ pub fn find_boundary_trail(
|
|||
// Find the boundary
|
||||
let start_offset = offset;
|
||||
for ch in forward {
|
||||
if let Some(prev_ch) = prev_ch {
|
||||
if is_boundary(prev_ch, ch) {
|
||||
if start_offset == offset {
|
||||
trail_offset = Some(offset);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
if let Some(prev_ch) = prev_ch
|
||||
&& is_boundary(prev_ch, ch)
|
||||
{
|
||||
if start_offset == offset {
|
||||
trail_offset = Some(offset);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
offset += ch.len_utf8();
|
||||
|
|
|
@ -285,11 +285,11 @@ pub fn open_docs(editor: &mut Editor, _: &OpenDocs, window: &mut Window, cx: &mu
|
|||
workspace.update(cx, |_workspace, cx| {
|
||||
// Check if the local document exists, otherwise fallback to the online document.
|
||||
// Open with the default browser.
|
||||
if let Some(local_url) = docs_urls.local {
|
||||
if fs::metadata(Path::new(&local_url[8..])).is_ok() {
|
||||
cx.open_url(&local_url);
|
||||
return;
|
||||
}
|
||||
if let Some(local_url) = docs_urls.local
|
||||
&& fs::metadata(Path::new(&local_url[8..])).is_ok()
|
||||
{
|
||||
cx.open_url(&local_url);
|
||||
return;
|
||||
}
|
||||
|
||||
if let Some(web_url) = docs_urls.web {
|
||||
|
|
|
@ -703,20 +703,20 @@ impl Editor {
|
|||
if matches!(
|
||||
settings.defaults.soft_wrap,
|
||||
SoftWrap::PreferredLineLength | SoftWrap::Bounded
|
||||
) {
|
||||
if (settings.defaults.preferred_line_length as f32) < visible_column_count {
|
||||
visible_column_count = settings.defaults.preferred_line_length as f32;
|
||||
}
|
||||
) && (settings.defaults.preferred_line_length as f32) < visible_column_count
|
||||
{
|
||||
visible_column_count = settings.defaults.preferred_line_length as f32;
|
||||
}
|
||||
|
||||
// If the scroll position is currently at the left edge of the document
|
||||
// (x == 0.0) and the intent is to scroll right, the gutter's margin
|
||||
// should first be added to the current position, otherwise the cursor
|
||||
// will end at the column position minus the margin, which looks off.
|
||||
if current_position.x == 0.0 && amount.columns(visible_column_count) > 0. {
|
||||
if let Some(last_position_map) = &self.last_position_map {
|
||||
current_position.x += self.gutter_dimensions.margin / last_position_map.em_advance;
|
||||
}
|
||||
if current_position.x == 0.0
|
||||
&& amount.columns(visible_column_count) > 0.
|
||||
&& let Some(last_position_map) = &self.last_position_map
|
||||
{
|
||||
current_position.x += self.gutter_dimensions.margin / last_position_map.em_advance;
|
||||
}
|
||||
let new_position = current_position
|
||||
+ point(
|
||||
|
@ -749,12 +749,10 @@ impl Editor {
|
|||
|
||||
if let (Some(visible_lines), Some(visible_columns)) =
|
||||
(self.visible_line_count(), self.visible_column_count())
|
||||
&& newest_head.row() <= DisplayRow(screen_top.row().0 + visible_lines as u32)
|
||||
&& newest_head.column() <= screen_top.column() + visible_columns as u32
|
||||
{
|
||||
if newest_head.row() <= DisplayRow(screen_top.row().0 + visible_lines as u32)
|
||||
&& newest_head.column() <= screen_top.column() + visible_columns as u32
|
||||
{
|
||||
return Ordering::Equal;
|
||||
}
|
||||
return Ordering::Equal;
|
||||
}
|
||||
|
||||
Ordering::Greater
|
||||
|
|
|
@ -116,12 +116,12 @@ impl Editor {
|
|||
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
||||
let mut scroll_position = self.scroll_manager.scroll_position(&display_map);
|
||||
let original_y = scroll_position.y;
|
||||
if let Some(last_bounds) = self.expect_bounds_change.take() {
|
||||
if scroll_position.y != 0. {
|
||||
scroll_position.y += (bounds.top() - last_bounds.top()) / line_height;
|
||||
if scroll_position.y < 0. {
|
||||
scroll_position.y = 0.;
|
||||
}
|
||||
if let Some(last_bounds) = self.expect_bounds_change.take()
|
||||
&& scroll_position.y != 0.
|
||||
{
|
||||
scroll_position.y += (bounds.top() - last_bounds.top()) / line_height;
|
||||
if scroll_position.y < 0. {
|
||||
scroll_position.y = 0.;
|
||||
}
|
||||
}
|
||||
if scroll_position.y > max_scroll_top {
|
||||
|
|
|
@ -184,10 +184,10 @@ pub fn editor_content_with_blocks(editor: &Entity<Editor>, cx: &mut VisualTestCo
|
|||
for (row, block) in blocks {
|
||||
match block {
|
||||
Block::Custom(custom_block) => {
|
||||
if let BlockPlacement::Near(x) = &custom_block.placement {
|
||||
if snapshot.intersects_fold(x.to_point(&snapshot.buffer_snapshot)) {
|
||||
continue;
|
||||
}
|
||||
if let BlockPlacement::Near(x) = &custom_block.placement
|
||||
&& snapshot.intersects_fold(x.to_point(&snapshot.buffer_snapshot))
|
||||
{
|
||||
continue;
|
||||
};
|
||||
let content = block_content_for_tests(editor, custom_block.id, cx)
|
||||
.expect("block content not found");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue