Compare commits

...

10 Commits

Author SHA1 Message Date
Joseph T. Lyons
25c3c6b621 v0.135.x stable 2024-05-15 11:47:29 -04:00
gcp-cherry-pick-bot[bot]
ab33b6a1ad Fix panic when accepting completions (cherry-pick #11762) (#11763)
Cherry-picked Fix panic when accepting completions (#11762)

Release Notes:

- Fixed a panic caused by missing bounds check in completion handler

Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
2024-05-13 13:51:44 -06:00
Zed Bot
cfd8d1860e Bump to 0.135.2 for @ConradIrwin 2024-05-10 12:06:22 -07:00
Conrad Irwin
ad5683bcdb Create release archive in the target dir 2024-05-10 13:05:00 -06:00
Kirill Bulatov
a565c3a470 Remove a stray eprintln (#11635)
Release Notes:

- N/A
2024-05-10 02:33:42 +03:00
Kirill Bulatov
3f17540002 Properly calculate expanded git diff hunk highlight ranges (#11632)
Closes https://github.com/zed-industries/zed/issues/11576

Release Notes:

- Fixed expanded diff hunks highlighting an extra row as added
([11576](https://github.com/zed-industries/zed/issues/11576))
2024-05-10 02:05:59 +03:00
Zed Bot
647c31e398 Bump to 0.135.1 for @ConradIrwin 2024-05-08 15:09:27 -07:00
gcp-cherry-pick-bot[bot]
6d927a4991 Don't panic on failure to allocate an AtlasTile (cherry-pick #11579) (#11583)
Cherry-picked Don't panic on failure to allocate an AtlasTile (#11579)

Release Notes:

- Fixed a panic in graphics allocation

Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
2024-05-08 16:00:40 -06:00
gcp-cherry-pick-bot[bot]
3a84d5eaa3 Pass hover position as an anchor (cherry-pick #11578) (#11581)
Cherry-picked Pass hover position as an anchor (#11578)

It's too easily to accidentally pass a point from one snapshot into
another

Release Notes:

- Fixed a panic in show hover

Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
2024-05-08 15:52:14 -06:00
Joseph T. Lyons
3ad3a36643 v0.135.x preview 2024-05-08 12:05:18 -04:00
15 changed files with 218 additions and 181 deletions

2
Cargo.lock generated
View File

@@ -12756,7 +12756,7 @@ dependencies = [
[[package]]
name = "zed"
version = "0.135.0"
version = "0.135.2"
dependencies = [
"activity_indicator",
"anyhow",

View File

@@ -2110,10 +2110,7 @@ struct Row10;"#};
let snapshot = editor.snapshot(cx);
let all_hunks = editor_hunks(editor, &snapshot, cx);
let all_expanded_hunks = expanded_hunks(&editor, &snapshot, cx);
assert_eq!(
expanded_hunks_background_highlights(editor, &snapshot),
Vec::new(),
);
assert_eq!(expanded_hunks_background_highlights(editor, cx), Vec::new());
assert_eq!(
all_hunks,
vec![
@@ -2135,8 +2132,8 @@ struct Row10;"#};
let all_hunks = editor_hunks(editor, &snapshot, cx);
let all_expanded_hunks = expanded_hunks(&editor, &snapshot, cx);
assert_eq!(
expanded_hunks_background_highlights(editor, &snapshot),
vec![1..3, 8..9],
expanded_hunks_background_highlights(editor, cx),
vec![1..=2, 8..=8],
);
assert_eq!(
all_hunks,
@@ -2170,10 +2167,7 @@ struct Row10;"#};
let snapshot = editor.snapshot(cx);
let all_hunks = editor_hunks(editor, &snapshot, cx);
let all_expanded_hunks = expanded_hunks(&editor, &snapshot, cx);
assert_eq!(
expanded_hunks_background_highlights(editor, &snapshot),
Vec::new(),
);
assert_eq!(expanded_hunks_background_highlights(editor, cx), Vec::new());
assert_eq!(
all_hunks,
vec![(
@@ -2189,8 +2183,8 @@ struct Row10;"#};
let all_hunks = editor_hunks(editor, &snapshot, cx);
let all_expanded_hunks = expanded_hunks(&editor, &snapshot, cx);
assert_eq!(
expanded_hunks_background_highlights(editor, &snapshot),
Vec::new(),
expanded_hunks_background_highlights(editor, cx),
vec![5..=5]
);
assert_eq!(
all_hunks,

View File

@@ -448,7 +448,7 @@ pub struct Editor {
show_wrap_guides: Option<bool>,
placeholder_text: Option<Arc<str>>,
highlight_order: usize,
highlighted_rows: HashMap<TypeId, Vec<(usize, Range<Anchor>, Hsla)>>,
highlighted_rows: HashMap<TypeId, Vec<(usize, RangeInclusive<Anchor>, Option<Hsla>)>>,
background_highlights: TreeMap<TypeId, BackgroundHighlight>,
scrollbar_marker_state: ScrollbarMarkerState,
nav_history: Option<ItemNavHistory>,
@@ -4639,12 +4639,11 @@ impl Editor {
delta +=
snippet.text.len() as isize - insertion_range.len() as isize;
let start = snapshot.anchor_before(
(insertion_start + tabstop_range.start) as usize,
);
let end = snapshot
.anchor_after((insertion_start + tabstop_range.end) as usize);
start..end
let start = ((insertion_start + tabstop_range.start) as usize)
.min(snapshot.len());
let end = ((insertion_start + tabstop_range.end) as usize)
.min(snapshot.len());
snapshot.anchor_before(start)..snapshot.anchor_after(end)
})
})
.collect::<Vec<_>>();
@@ -9667,7 +9666,7 @@ impl Editor {
/// If multiple anchor ranges will produce highlights for the same row, the last range added will be used.
pub fn highlight_rows<T: 'static>(
&mut self,
rows: Range<Anchor>,
rows: RangeInclusive<Anchor>,
color: Option<Hsla>,
cx: &mut ViewContext<Self>,
) {
@@ -9678,9 +9677,13 @@ impl Editor {
let existing_highlight_index =
row_highlights.binary_search_by(|(_, highlight_range, _)| {
highlight_range
.start
.cmp(&rows.start, &multi_buffer_snapshot)
.then(highlight_range.end.cmp(&rows.end, &multi_buffer_snapshot))
.start()
.cmp(&rows.start(), &multi_buffer_snapshot)
.then(
highlight_range
.end()
.cmp(&rows.end(), &multi_buffer_snapshot),
)
});
match color {
Some(color) => {
@@ -9690,20 +9693,22 @@ impl Editor {
};
row_highlights.insert(
insert_index,
(post_inc(&mut self.highlight_order), rows, color),
(post_inc(&mut self.highlight_order), rows, Some(color)),
);
}
None => {
if let Ok(i) = existing_highlight_index {
None => match existing_highlight_index {
Ok(i) => {
row_highlights.remove(i);
}
}
Err(i) => {
row_highlights
.insert(i, (post_inc(&mut self.highlight_order), rows, None));
}
},
}
}
hash_map::Entry::Vacant(v) => {
if let Some(color) = color {
v.insert(vec![(post_inc(&mut self.highlight_order), rows, color)]);
}
v.insert(vec![(post_inc(&mut self.highlight_order), rows, color)]);
}
}
}
@@ -9716,12 +9721,12 @@ impl Editor {
/// For a highlight given context type, gets all anchor ranges that will be used for row highlighting.
pub fn highlighted_rows<T: 'static>(
&self,
) -> Option<impl Iterator<Item = (&Range<Anchor>, &Hsla)>> {
) -> Option<impl Iterator<Item = (&RangeInclusive<Anchor>, Option<&Hsla>)>> {
Some(
self.highlighted_rows
.get(&TypeId::of::<T>())?
.iter()
.map(|(_, range, color)| (range, color)),
.map(|(_, range, color)| (range, color.as_ref())),
)
}
@@ -9742,14 +9747,21 @@ impl Editor {
.fold(
BTreeMap::<u32, Hsla>::new(),
|mut unique_rows, (highlight_order, anchor_range, hsla)| {
let start_row = anchor_range.start.to_display_point(&snapshot).row();
let end_row = anchor_range.end.to_display_point(&snapshot).row();
let start_row = anchor_range.start().to_display_point(&snapshot).row();
let end_row = anchor_range.end().to_display_point(&snapshot).row();
for row in start_row..=end_row {
let used_index =
used_highlight_orders.entry(row).or_insert(*highlight_order);
if highlight_order >= used_index {
*used_index = *highlight_order;
unique_rows.insert(row, *hsla);
match hsla {
Some(hsla) => {
unique_rows.insert(row, *hsla);
}
None => {
unique_rows.remove(&row);
}
}
}
}
unique_rows
@@ -11548,6 +11560,12 @@ trait RangeToAnchorExt {
impl<T: ToOffset> RangeToAnchorExt for Range<T> {
fn to_anchors(self, snapshot: &MultiBufferSnapshot) -> Range<Anchor> {
snapshot.anchor_after(self.start)..snapshot.anchor_before(self.end)
let start_offset = self.start.to_offset(snapshot);
let end_offset = self.end.to_offset(snapshot);
if start_offset == end_offset {
snapshot.anchor_before(start_offset)..snapshot.anchor_before(end_offset)
} else {
snapshot.anchor_after(self.start)..snapshot.anchor_before(self.end)
}
}
}

View File

@@ -9543,8 +9543,8 @@ async fn test_toggle_hunk_diff(executor: BackgroundExecutor, cx: &mut gpui::Test
let all_hunks = editor_hunks(editor, &snapshot, cx);
let all_expanded_hunks = expanded_hunks(&editor, &snapshot, cx);
assert_eq!(
expanded_hunks_background_highlights(editor, &snapshot),
vec![1..2, 7..8, 9..10],
expanded_hunks_background_highlights(editor, cx),
vec![1..=1, 7..=7, 9..=9],
"After expanding, all git additions should be highlighted for Modified (split into added and removed) and Added hunks"
);
assert_eq!(
@@ -9571,7 +9571,7 @@ async fn test_toggle_hunk_diff(executor: BackgroundExecutor, cx: &mut gpui::Test
let all_hunks = editor_hunks(editor, &snapshot, cx);
let all_expanded_hunks = expanded_hunks(editor, &snapshot, cx);
assert_eq!(
expanded_hunks_background_highlights(editor, &snapshot),
expanded_hunks_background_highlights(editor, cx),
Vec::new(),
"After cancelling in editor, no git highlights should be left"
);
@@ -9684,8 +9684,8 @@ async fn test_toggled_diff_base_change(
let all_hunks = editor_hunks(editor, &snapshot, cx);
let all_expanded_hunks = expanded_hunks(&editor, &snapshot, cx);
assert_eq!(
expanded_hunks_background_highlights(editor, &snapshot),
vec![9..11, 13..15],
expanded_hunks_background_highlights(editor, cx),
vec![9..=10, 13..=14],
"After expanding, all git additions should be highlighted for Modified (split into added and removed) and Added hunks"
);
assert_eq!(
@@ -9713,7 +9713,7 @@ async fn test_toggled_diff_base_change(
let all_hunks = editor_hunks(editor, &snapshot, cx);
let all_expanded_hunks = expanded_hunks(editor, &snapshot, cx);
assert_eq!(
expanded_hunks_background_highlights(editor, &snapshot),
expanded_hunks_background_highlights(editor, cx),
Vec::new(),
"After diff base is changed, old git highlights should be removed"
);
@@ -9858,8 +9858,8 @@ async fn test_fold_unfold_diff(executor: BackgroundExecutor, cx: &mut gpui::Test
let all_hunks = editor_hunks(editor, &snapshot, cx);
let all_expanded_hunks = expanded_hunks(&editor, &snapshot, cx);
assert_eq!(
expanded_hunks_background_highlights(editor, &snapshot),
vec![9..11, 13..15, 19..20]
expanded_hunks_background_highlights(editor, cx),
vec![9..=10, 13..=14, 19..=19]
);
assert_eq!(
all_hunks,
@@ -9923,8 +9923,8 @@ async fn test_fold_unfold_diff(executor: BackgroundExecutor, cx: &mut gpui::Test
let all_hunks = editor_hunks(editor, &snapshot, cx);
let all_expanded_hunks = expanded_hunks(&editor, &snapshot, cx);
assert_eq!(
expanded_hunks_background_highlights(editor, &snapshot),
vec![5..6],
expanded_hunks_background_highlights(editor, cx),
vec![0..=0, 5..=5],
"Only one hunk is left not folded, its highlight should be visible"
);
assert_eq!(
@@ -10004,8 +10004,8 @@ async fn test_fold_unfold_diff(executor: BackgroundExecutor, cx: &mut gpui::Test
let all_hunks = editor_hunks(editor, &snapshot, cx);
let all_expanded_hunks = expanded_hunks(&editor, &snapshot, cx);
assert_eq!(
expanded_hunks_background_highlights(editor, &snapshot),
vec![9..11, 13..15, 19..20],
expanded_hunks_background_highlights(editor, cx),
vec![9..=10, 13..=14, 19..=19],
"After unfolding, all hunk diffs should be visible again"
);
assert_eq!(
@@ -10172,10 +10172,7 @@ async fn test_toggle_diff_expand_in_multi_buffer(cx: &mut gpui::TestAppContext)
let snapshot = editor.snapshot(cx);
let all_hunks = editor_hunks(editor, &snapshot, cx);
let all_expanded_hunks = expanded_hunks(&editor, &snapshot, cx);
assert_eq!(
expanded_hunks_background_highlights(editor, &snapshot),
Vec::new(),
);
assert_eq!(expanded_hunks_background_highlights(editor, cx), Vec::new());
assert_eq!(all_hunks, expected_all_hunks);
assert_eq!(all_expanded_hunks, Vec::new());
});
@@ -10190,8 +10187,8 @@ async fn test_toggle_diff_expand_in_multi_buffer(cx: &mut gpui::TestAppContext)
let all_hunks = editor_hunks(editor, &snapshot, cx);
let all_expanded_hunks = expanded_hunks(&editor, &snapshot, cx);
assert_eq!(
expanded_hunks_background_highlights(editor, &snapshot),
vec![18..19, 33..34],
expanded_hunks_background_highlights(editor, cx),
vec![18..=18, 33..=33],
);
assert_eq!(all_hunks, expected_all_hunks_shifted);
assert_eq!(all_hunks, all_expanded_hunks);
@@ -10205,10 +10202,7 @@ async fn test_toggle_diff_expand_in_multi_buffer(cx: &mut gpui::TestAppContext)
let snapshot = editor.snapshot(cx);
let all_hunks = editor_hunks(editor, &snapshot, cx);
let all_expanded_hunks = expanded_hunks(&editor, &snapshot, cx);
assert_eq!(
expanded_hunks_background_highlights(editor, &snapshot),
Vec::new(),
);
assert_eq!(expanded_hunks_background_highlights(editor, cx), Vec::new());
assert_eq!(all_hunks, expected_all_hunks);
assert_eq!(all_expanded_hunks, Vec::new());
});
@@ -10222,8 +10216,8 @@ async fn test_toggle_diff_expand_in_multi_buffer(cx: &mut gpui::TestAppContext)
let all_hunks = editor_hunks(editor, &snapshot, cx);
let all_expanded_hunks = expanded_hunks(&editor, &snapshot, cx);
assert_eq!(
expanded_hunks_background_highlights(editor, &snapshot),
vec![18..19, 33..34],
expanded_hunks_background_highlights(editor, cx),
vec![18..=18, 33..=33],
);
assert_eq!(all_hunks, expected_all_hunks_shifted);
assert_eq!(all_hunks, all_expanded_hunks);
@@ -10237,10 +10231,7 @@ async fn test_toggle_diff_expand_in_multi_buffer(cx: &mut gpui::TestAppContext)
let snapshot = editor.snapshot(cx);
let all_hunks = editor_hunks(editor, &snapshot, cx);
let all_expanded_hunks = expanded_hunks(&editor, &snapshot, cx);
assert_eq!(
expanded_hunks_background_highlights(editor, &snapshot),
Vec::new(),
);
assert_eq!(expanded_hunks_background_highlights(editor, cx), Vec::new());
assert_eq!(all_hunks, expected_all_hunks);
assert_eq!(all_expanded_hunks, Vec::new());
});
@@ -10329,8 +10320,8 @@ async fn test_edits_around_toggled_additions(
vec![("".to_string(), DiffHunkStatus::Added, 4..7)]
);
assert_eq!(
expanded_hunks_background_highlights(editor, &snapshot),
vec![4..7]
expanded_hunks_background_highlights(editor, cx),
vec![4..=6]
);
assert_eq!(all_hunks, all_expanded_hunks);
});
@@ -10365,8 +10356,8 @@ async fn test_edits_around_toggled_additions(
vec![("".to_string(), DiffHunkStatus::Added, 4..8)]
);
assert_eq!(
expanded_hunks_background_highlights(editor, &snapshot),
vec![4..8],
expanded_hunks_background_highlights(editor, cx),
vec![4..=6],
"Edited hunk should have one more line added"
);
assert_eq!(
@@ -10406,8 +10397,8 @@ async fn test_edits_around_toggled_additions(
vec![("".to_string(), DiffHunkStatus::Added, 4..9)]
);
assert_eq!(
expanded_hunks_background_highlights(editor, &snapshot),
vec![4..9],
expanded_hunks_background_highlights(editor, cx),
vec![4..=6],
"Edited hunk should have one more line added"
);
assert_eq!(all_hunks, all_expanded_hunks);
@@ -10446,8 +10437,8 @@ async fn test_edits_around_toggled_additions(
vec![("".to_string(), DiffHunkStatus::Added, 4..8)]
);
assert_eq!(
expanded_hunks_background_highlights(editor, &snapshot),
vec![4..8],
expanded_hunks_background_highlights(editor, cx),
vec![4..=6],
"Deleting a line should shrint the hunk"
);
assert_eq!(
@@ -10490,8 +10481,8 @@ async fn test_edits_around_toggled_additions(
vec![("".to_string(), DiffHunkStatus::Added, 5..6)]
);
assert_eq!(
expanded_hunks_background_highlights(editor, &snapshot),
vec![5..6]
expanded_hunks_background_highlights(editor, cx),
vec![5..=5]
);
assert_eq!(all_hunks, all_expanded_hunks);
});
@@ -10533,7 +10524,7 @@ async fn test_edits_around_toggled_additions(
]
);
assert_eq!(
expanded_hunks_background_highlights(editor, &snapshot),
expanded_hunks_background_highlights(editor, cx),
Vec::new(),
"Should close all stale expanded addition hunks"
);
@@ -10632,10 +10623,7 @@ async fn test_edits_around_toggled_deletions(
let snapshot = editor.snapshot(cx);
let all_hunks = editor_hunks(editor, &snapshot, cx);
let all_expanded_hunks = expanded_hunks(&editor, &snapshot, cx);
assert_eq!(
expanded_hunks_background_highlights(editor, &snapshot),
Vec::new()
);
assert_eq!(expanded_hunks_background_highlights(editor, cx), Vec::new());
assert_eq!(
all_hunks,
vec![(
@@ -10672,7 +10660,7 @@ async fn test_edits_around_toggled_deletions(
let all_hunks = editor_hunks(editor, &snapshot, cx);
let all_expanded_hunks = expanded_hunks(&editor, &snapshot, cx);
assert_eq!(
expanded_hunks_background_highlights(editor, &snapshot),
expanded_hunks_background_highlights(editor, cx),
Vec::new(),
"Deleted hunks do not highlight current editor's background"
);
@@ -10710,10 +10698,7 @@ async fn test_edits_around_toggled_deletions(
let snapshot = editor.snapshot(cx);
let all_hunks = editor_hunks(editor, &snapshot, cx);
let all_expanded_hunks = expanded_hunks(&editor, &snapshot, cx);
assert_eq!(
expanded_hunks_background_highlights(editor, &snapshot),
Vec::new()
);
assert_eq!(expanded_hunks_background_highlights(editor, cx), Vec::new());
assert_eq!(
all_hunks,
vec![(
@@ -10757,8 +10742,8 @@ async fn test_edits_around_toggled_deletions(
)]
);
assert_eq!(
expanded_hunks_background_highlights(editor, &snapshot),
vec![7..8],
expanded_hunks_background_highlights(editor, cx),
vec![7..=7],
"Modified expanded hunks should display additions and highlight their background"
);
assert_eq!(all_hunks, all_expanded_hunks);
@@ -10851,8 +10836,8 @@ async fn test_edits_around_toggled_modifications(
let all_hunks = editor_hunks(editor, &snapshot, cx);
let all_expanded_hunks = expanded_hunks(&editor, &snapshot, cx);
assert_eq!(
expanded_hunks_background_highlights(editor, &snapshot),
vec![6..7],
expanded_hunks_background_highlights(editor, cx),
vec![6..=6],
);
assert_eq!(
all_hunks,
@@ -10894,8 +10879,8 @@ async fn test_edits_around_toggled_modifications(
let all_hunks = editor_hunks(editor, &snapshot, cx);
let all_expanded_hunks = expanded_hunks(&editor, &snapshot, cx);
assert_eq!(
expanded_hunks_background_highlights(editor, &snapshot),
vec![6..9],
expanded_hunks_background_highlights(editor, cx),
vec![6..=6],
"Modified hunk should grow highlighted lines on more text additions"
);
assert_eq!(
@@ -10940,9 +10925,8 @@ async fn test_edits_around_toggled_modifications(
let all_hunks = editor_hunks(editor, &snapshot, cx);
let all_expanded_hunks = expanded_hunks(&editor, &snapshot, cx);
assert_eq!(
expanded_hunks_background_highlights(editor, &snapshot),
vec![6..9],
"Modified hunk should grow deleted lines on text deletions above"
expanded_hunks_background_highlights(editor, cx),
vec![6..=8],
);
assert_eq!(
all_hunks,
@@ -10950,7 +10934,8 @@ async fn test_edits_around_toggled_modifications(
"const B: u32 = 42;\nconst C: u32 = 42;\n".to_string(),
DiffHunkStatus::Modified,
6..9
)]
)],
"Modified hunk should grow deleted lines on text deletions above"
);
assert_eq!(all_hunks, all_expanded_hunks);
});
@@ -10984,8 +10969,8 @@ async fn test_edits_around_toggled_modifications(
let all_hunks = editor_hunks(editor, &snapshot, cx);
let all_expanded_hunks = expanded_hunks(&editor, &snapshot, cx);
assert_eq!(
expanded_hunks_background_highlights(editor, &snapshot),
vec![6..10],
expanded_hunks_background_highlights(editor, cx),
vec![6..=9],
"Modified hunk should grow deleted lines on text modifications above"
);
assert_eq!(
@@ -11028,8 +11013,8 @@ async fn test_edits_around_toggled_modifications(
let all_hunks = editor_hunks(editor, &snapshot, cx);
let all_expanded_hunks = expanded_hunks(&editor, &snapshot, cx);
assert_eq!(
expanded_hunks_background_highlights(editor, &snapshot),
vec![6..9],
expanded_hunks_background_highlights(editor, cx),
vec![6..=8],
"Modified hunk should grow shrink lines on modification lines removal"
);
assert_eq!(
@@ -11069,7 +11054,7 @@ async fn test_edits_around_toggled_modifications(
let all_hunks = editor_hunks(editor, &snapshot, cx);
let all_expanded_hunks = expanded_hunks(&editor, &snapshot, cx);
assert_eq!(
expanded_hunks_background_highlights(editor, &snapshot),
expanded_hunks_background_highlights(editor, cx),
Vec::new(),
"Modified hunk should turn into a removed one on all modified lines removal"
);
@@ -11172,8 +11157,8 @@ async fn test_multiple_expanded_hunks_merge(
let all_hunks = editor_hunks(editor, &snapshot, cx);
let all_expanded_hunks = expanded_hunks(&editor, &snapshot, cx);
assert_eq!(
expanded_hunks_background_highlights(editor, &snapshot),
vec![6..7],
expanded_hunks_background_highlights(editor, cx),
vec![6..=6],
);
assert_eq!(
all_hunks,

View File

@@ -638,7 +638,11 @@ impl EditorElement {
editor.update_hovered_link(point_for_position, &position_map.snapshot, modifiers, cx);
if let Some(point) = point_for_position.as_valid() {
hover_at(editor, Some((point, &position_map.snapshot)), cx);
let anchor = position_map
.snapshot
.buffer_snapshot
.anchor_before(point.to_offset(&position_map.snapshot, Bias::Left));
hover_at(editor, Some(anchor), cx);
Self::update_visible_cursor(editor, point, position_map, cx);
} else {
hover_at(editor, None, cx);

View File

@@ -10,9 +10,10 @@ use gpui::{
ParentElement, Pixels, SharedString, Size, StatefulInteractiveElement, Styled, Task,
ViewContext, WeakView,
};
use language::{markdown, Bias, DiagnosticEntry, Language, LanguageRegistry, ParsedMarkdown};
use language::{markdown, DiagnosticEntry, Language, LanguageRegistry, ParsedMarkdown};
use lsp::DiagnosticSeverity;
use multi_buffer::ToOffset;
use project::{HoverBlock, HoverBlockKind, InlayHintLabelPart};
use settings::Settings;
use smol::stream::StreamExt;
@@ -30,21 +31,16 @@ pub const HOVER_POPOVER_GAP: Pixels = px(10.);
/// Bindable action which uses the most recent selection head to trigger a hover
pub fn hover(editor: &mut Editor, _: &Hover, cx: &mut ViewContext<Editor>) {
let head = editor.selections.newest_display(cx).head();
let snapshot = editor.snapshot(cx);
show_hover(editor, head, &snapshot, true, cx);
let head = editor.selections.newest_anchor().head();
show_hover(editor, head, true, cx);
}
/// The internal hover action dispatches between `show_hover` or `hide_hover`
/// depending on whether a point to hover over is provided.
pub fn hover_at(
editor: &mut Editor,
point: Option<(DisplayPoint, &EditorSnapshot)>,
cx: &mut ViewContext<Editor>,
) {
pub fn hover_at(editor: &mut Editor, anchor: Option<Anchor>, cx: &mut ViewContext<Editor>) {
if EditorSettings::get_global(cx).hover_popover_enabled {
if let Some((point, snapshot)) = point {
show_hover(editor, point, snapshot, false, cx);
if let Some(anchor) = anchor {
show_hover(editor, anchor, false, cx);
} else {
hide_hover(editor, cx);
}
@@ -164,8 +160,7 @@ pub fn hide_hover(editor: &mut Editor, cx: &mut ViewContext<Editor>) -> bool {
/// Triggered by the `Hover` action when the cursor may be over a symbol.
fn show_hover(
editor: &mut Editor,
point: DisplayPoint,
snapshot: &EditorSnapshot,
anchor: Anchor,
ignore_timeout: bool,
cx: &mut ViewContext<Editor>,
) {
@@ -173,27 +168,21 @@ fn show_hover(
return;
}
let multibuffer_offset = point.to_offset(&snapshot.display_snapshot, Bias::Left);
let snapshot = editor.snapshot(cx);
let (buffer, buffer_position) = if let Some(output) = editor
.buffer
.read(cx)
.text_anchor_for_position(multibuffer_offset, cx)
{
output
} else {
return;
};
let (buffer, buffer_position) =
if let Some(output) = editor.buffer.read(cx).text_anchor_for_position(anchor, cx) {
output
} else {
return;
};
let excerpt_id = if let Some((excerpt_id, _, _)) = editor
.buffer()
.read(cx)
.excerpt_containing(multibuffer_offset, cx)
{
excerpt_id
} else {
return;
};
let excerpt_id =
if let Some((excerpt_id, _, _)) = editor.buffer().read(cx).excerpt_containing(anchor, cx) {
excerpt_id
} else {
return;
};
let project = if let Some(project) = editor.project.clone() {
project
@@ -211,9 +200,10 @@ fn show_hover(
.as_text_range()
.map(|range| {
let hover_range = range.to_offset(&snapshot.buffer_snapshot);
let offset = anchor.to_offset(&snapshot.buffer_snapshot);
// LSP returns a hover result for the end index of ranges that should be hovered, so we need to
// use an inclusive range here to check if we should dismiss the popover
(hover_range.start..=hover_range.end).contains(&multibuffer_offset)
(hover_range.start..=hover_range.end).contains(&offset)
})
.unwrap_or(false)
})
@@ -225,11 +215,6 @@ fn show_hover(
}
}
// Get input anchor
let anchor = snapshot
.buffer_snapshot
.anchor_at(multibuffer_offset, Bias::Left);
// 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
@@ -239,7 +224,6 @@ fn show_hover(
return;
}
}
let snapshot = snapshot.clone();
let task = cx.spawn(|this, mut cx| {
async move {
@@ -273,7 +257,7 @@ fn show_hover(
// If there's a diagnostic, assign it on the hover state and notify
let local_diagnostic = snapshot
.buffer_snapshot
.diagnostics_in_range::<_, usize>(multibuffer_offset..multibuffer_offset, false)
.diagnostics_in_range::<_, usize>(anchor..anchor, false)
// Find the entry with the most specific range
.min_by_key(|entry| entry.range.end - entry.range.start)
.map(|entry| DiagnosticEntry {
@@ -641,6 +625,7 @@ mod tests {
use lsp::LanguageServerId;
use project::{HoverBlock, HoverBlockKind};
use smol::stream::StreamExt;
use text::Bias;
use unindent::Unindent;
use util::test::marked_text_ranges;
@@ -667,7 +652,10 @@ mod tests {
cx.update_editor(|editor, cx| {
let snapshot = editor.snapshot(cx);
hover_at(editor, Some((hover_point, &snapshot)), cx)
let anchor = snapshot
.buffer_snapshot
.anchor_before(hover_point.to_offset(&snapshot, Bias::Left));
hover_at(editor, Some(anchor), cx)
});
assert!(!cx.editor(|editor, _| editor.hover_state.visible()));
@@ -716,7 +704,10 @@ mod tests {
.handle_request::<lsp::request::HoverRequest, _, _>(|_, _| async move { Ok(None) });
cx.update_editor(|editor, cx| {
let snapshot = editor.snapshot(cx);
hover_at(editor, Some((hover_point, &snapshot)), cx)
let anchor = snapshot
.buffer_snapshot
.anchor_before(hover_point.to_offset(&snapshot, Bias::Left));
hover_at(editor, Some(anchor), cx)
});
cx.background_executor
.advance_clock(Duration::from_millis(HOVER_DELAY_MILLIS + 100));

View File

@@ -1,4 +1,7 @@
use std::{ops::Range, sync::Arc};
use std::{
ops::{Range, RangeInclusive},
sync::Arc,
};
use collections::{hash_map, HashMap, HashSet};
use git::diff::{DiffHunk, DiffHunkStatus};
@@ -14,8 +17,8 @@ use util::{debug_panic, RangeExt};
use crate::{
git::{diff_hunk_to_display, DisplayDiffHunk},
hunks_for_selections, BlockDisposition, BlockId, BlockProperties, BlockStyle, DiffRowHighlight,
Editor, ExpandAllHunkDiffs, RangeToAnchorExt, RevertSelectedHunks, ToDisplayPoint,
ToggleHunkDiff,
Editor, EditorSnapshot, ExpandAllHunkDiffs, RangeToAnchorExt, RevertSelectedHunks,
ToDisplayPoint, ToggleHunkDiff,
};
#[derive(Debug, Clone)]
@@ -184,7 +187,11 @@ impl Editor {
}
for removed_rows in highlights_to_remove {
editor.highlight_rows::<DiffRowHighlight>(removed_rows, None, cx);
editor.highlight_rows::<DiffRowHighlight>(
to_inclusive_row_range(removed_rows, &snapshot),
None,
cx,
);
}
editor.remove_blocks(blocks_to_remove, None, cx);
for hunk in hunks_to_expand {
@@ -216,9 +223,9 @@ impl Editor {
let hunk_end = hunk.multi_buffer_range.end;
let buffer = self.buffer().clone();
let snapshot = self.snapshot(cx);
let (diff_base_buffer, deleted_text_lines) = buffer.update(cx, |buffer, cx| {
let snapshot = buffer.snapshot(cx);
let hunk = buffer_diff_hunk(&snapshot, multi_buffer_row_range.clone())?;
let hunk = buffer_diff_hunk(&snapshot.buffer_snapshot, multi_buffer_row_range.clone())?;
let mut buffer_ranges = buffer.range_to_buffer_ranges(multi_buffer_row_range, cx);
if buffer_ranges.len() == 1 {
let (buffer, _, _) = buffer_ranges.pop()?;
@@ -256,7 +263,7 @@ impl Editor {
}
DiffHunkStatus::Added => {
self.highlight_rows::<DiffRowHighlight>(
hunk_start..hunk_end,
to_inclusive_row_range(hunk_start..hunk_end, &snapshot),
Some(added_hunk_color(cx)),
cx,
);
@@ -264,7 +271,7 @@ impl Editor {
}
DiffHunkStatus::Modified => {
self.highlight_rows::<DiffRowHighlight>(
hunk_start..hunk_end,
to_inclusive_row_range(hunk_start..hunk_end, &snapshot),
Some(added_hunk_color(cx)),
cx,
);
@@ -461,7 +468,11 @@ impl Editor {
});
for removed_rows in highlights_to_remove {
editor.highlight_rows::<DiffRowHighlight>(removed_rows, None, cx);
editor.highlight_rows::<DiffRowHighlight>(
to_inclusive_row_range(removed_rows, &snapshot),
None,
cx,
);
}
editor.remove_blocks(blocks_to_remove, None, cx);
@@ -565,7 +576,7 @@ fn editor_with_deleted_text(
.buffer_snapshot
.anchor_after(editor.buffer.read(cx).len(cx));
editor.highlight_rows::<DiffRowHighlight>(start..end, Some(deleted_color), cx);
editor.highlight_rows::<DiffRowHighlight>(start..=end, Some(deleted_color), cx);
let hunk_related_subscription = cx.on_blur(&editor.focus_handle, |editor, cx| {
editor.change_selections(None, cx, |s| {
s.try_cancel();
@@ -619,3 +630,18 @@ fn buffer_diff_hunk(
}
None
}
fn to_inclusive_row_range(
row_range: Range<Anchor>,
snapshot: &EditorSnapshot,
) -> RangeInclusive<Anchor> {
let mut display_row_range =
row_range.start.to_display_point(snapshot)..row_range.end.to_display_point(snapshot);
if display_row_range.end.row() > display_row_range.start.row() {
*display_row_range.end.row_mut() -= 1;
}
let point_range = display_row_range.start.to_point(&snapshot.display_snapshot)
..display_row_range.end.to_point(&snapshot.display_snapshot);
let new_range = point_range.to_anchors(&snapshot.buffer_snapshot);
new_range.start..=new_range.end
}

View File

@@ -148,18 +148,31 @@ pub fn expanded_hunks(
#[cfg(any(test, feature = "test-support"))]
pub fn expanded_hunks_background_highlights(
editor: &Editor,
snapshot: &DisplaySnapshot,
) -> Vec<core::ops::Range<u32>> {
use itertools::Itertools;
editor: &mut Editor,
cx: &mut gpui::WindowContext,
) -> Vec<std::ops::RangeInclusive<u32>> {
let mut highlights = Vec::new();
editor
.highlighted_rows::<crate::DiffRowHighlight>()
.into_iter()
.flatten()
.map(|(range, _)| {
range.start.to_display_point(snapshot).row()..range.end.to_display_point(snapshot).row()
})
.unique()
.collect()
let mut range_start = 0;
let mut previous_highlighted_row = None;
for (highlighted_row, _) in editor.highlighted_display_rows(collections::HashSet::default(), cx)
{
match previous_highlighted_row {
Some(previous_row) => {
if previous_row + 1 != highlighted_row {
highlights.push(range_start..=previous_row);
range_start = highlighted_row;
}
}
None => {
range_start = highlighted_row;
}
}
previous_highlighted_row = Some(highlighted_row);
}
if let Some(previous_row) = previous_highlighted_row {
highlights.push(range_start..=previous_row);
}
highlights
}

View File

@@ -120,7 +120,7 @@ impl GoToLine {
let anchor = snapshot.buffer_snapshot.anchor_before(point);
active_editor.clear_row_highlights::<GoToLineRowHighlights>();
active_editor.highlight_rows::<GoToLineRowHighlights>(
anchor..anchor,
anchor..=anchor,
Some(cx.theme().colors().editor_highlighted_line_background),
cx,
);

View File

@@ -2,7 +2,7 @@ use crate::{
AtlasKey, AtlasTextureId, AtlasTextureKind, AtlasTile, Bounds, DevicePixels, PlatformAtlas,
Point, Size,
};
use anyhow::Result;
use anyhow::{anyhow, Result};
use collections::FxHashMap;
use derive_more::{Deref, DerefMut};
use etagere::BucketedAtlasAllocator;
@@ -31,7 +31,7 @@ impl MetalAtlas {
&self,
size: Size<DevicePixels>,
texture_kind: AtlasTextureKind,
) -> AtlasTile {
) -> Option<AtlasTile> {
self.0.lock().allocate(size, texture_kind)
}
@@ -67,7 +67,9 @@ impl PlatformAtlas for MetalAtlas {
Ok(tile.clone())
} else {
let (size, bytes) = build()?;
let tile = lock.allocate(size, key.texture_kind());
let tile = lock
.allocate(size, key.texture_kind())
.ok_or_else(|| anyhow!("failed to allocate"))?;
let texture = lock.texture(tile.texture_id);
texture.upload(tile.bounds, &bytes);
lock.tiles_by_key.insert(key.clone(), tile.clone());
@@ -77,7 +79,11 @@ impl PlatformAtlas for MetalAtlas {
}
impl MetalAtlasState {
fn allocate(&mut self, size: Size<DevicePixels>, texture_kind: AtlasTextureKind) -> AtlasTile {
fn allocate(
&mut self,
size: Size<DevicePixels>,
texture_kind: AtlasTextureKind,
) -> Option<AtlasTile> {
let textures = match texture_kind {
AtlasTextureKind::Monochrome => &mut self.monochrome_textures,
AtlasTextureKind::Polychrome => &mut self.polychrome_textures,
@@ -88,9 +94,9 @@ impl MetalAtlasState {
.iter_mut()
.rev()
.find_map(|texture| texture.allocate(size))
.unwrap_or_else(|| {
.or_else(|| {
let texture = self.push_texture(size, texture_kind);
texture.allocate(size).unwrap()
texture.allocate(size)
})
}

View File

@@ -417,7 +417,7 @@ impl MetalRenderer {
let tile = self
.sprite_atlas
.allocate(clipped_bounds.size.map(Into::into), AtlasTextureKind::Path);
.allocate(clipped_bounds.size.map(Into::into), AtlasTextureKind::Path)?;
vertices_by_texture_id
.entry(tile.texture_id)
.or_insert(Vec::new())

View File

@@ -142,7 +142,7 @@ impl OutlineViewDelegate {
self.active_editor.update(cx, |active_editor, cx| {
active_editor.clear_row_highlights::<OutlineRowHighlights>();
active_editor.highlight_rows::<OutlineRowHighlights>(
outline_item.range.clone(),
outline_item.range.start..=outline_item.range.end,
Some(cx.theme().colors().editor_highlighted_line_background),
cx,
);
@@ -243,7 +243,7 @@ impl PickerDelegate for OutlineViewDelegate {
.and_then(|highlights| highlights.into_iter().next().map(|(rows, _)| rows.clone()))
{
active_editor.change_selections(Some(Autoscroll::center()), cx, |s| {
s.select_ranges([rows.start..rows.start])
s.select_ranges([*rows.start()..*rows.start()])
});
active_editor.clear_row_highlights::<OutlineRowHighlights>();
active_editor.focus(cx);

View File

@@ -2,7 +2,7 @@
description = "The fast, collaborative code editor."
edition = "2021"
name = "zed"
version = "0.135.0"
version = "0.135.2"
publish = false
license = "GPL-3.0-or-later"
authors = ["Zed Team <hi@zed.dev>"]

View File

@@ -1 +1 @@
dev
stable

View File

@@ -88,4 +88,4 @@ else
fi
rm -rf "${archive}"
tar -czvf $archive -C ${temp_dir} "zed$suffix.app"
tar -czvf target/release/$archive -C ${temp_dir} "zed$suffix.app"