One big cleanup pass of clippy lints

Co-authored-by: Mikayla <mikayla@zed.dev>
This commit is contained in:
ForLoveOfCats
2022-08-10 16:51:01 -07:00
committed by K Simmons
co-authored by Mikayla
parent e7540d2833
commit 8ba2f77148
138 changed files with 1328 additions and 1366 deletions
+15 -22
View File
@@ -253,7 +253,7 @@ impl DisplaySnapshot {
self.buffer_snapshot.len() == 0
}
pub fn buffer_rows<'a>(&'a self, start_row: u32) -> DisplayBufferRows<'a> {
pub fn buffer_rows(&self, start_row: u32) -> DisplayBufferRows {
self.blocks_snapshot.buffer_rows(start_row)
}
@@ -313,7 +313,7 @@ impl DisplaySnapshot {
fn point_to_display_point(&self, point: Point, bias: Bias) -> DisplayPoint {
let fold_point = self.folds_snapshot.to_fold_point(point, bias);
let tab_point = self.tabs_snapshot.to_tab_point(fold_point);
let wrap_point = self.wraps_snapshot.from_tab_point(tab_point);
let wrap_point = self.wraps_snapshot.tab_point_to_wrap_point(tab_point);
let block_point = self.blocks_snapshot.to_block_point(wrap_point);
DisplayPoint(block_point)
}
@@ -336,16 +336,12 @@ impl DisplaySnapshot {
.map(|h| h.text)
}
pub fn chunks<'a>(
&'a self,
display_rows: Range<u32>,
language_aware: bool,
) -> DisplayChunks<'a> {
pub fn chunks(&self, display_rows: Range<u32>, language_aware: bool) -> DisplayChunks<'_> {
self.blocks_snapshot
.chunks(display_rows, language_aware, Some(&self.text_highlights))
}
pub fn chars_at<'a>(&'a self, point: DisplayPoint) -> impl Iterator<Item = char> + 'a {
pub fn chars_at(&self, point: DisplayPoint) -> impl Iterator<Item = char> + '_ {
let mut column = 0;
let mut chars = self.text_chunks(point.row()).flat_map(str::chars);
while column < point.column() {
@@ -372,15 +368,15 @@ impl DisplaySnapshot {
}
pub fn column_from_chars(&self, display_row: u32, char_count: u32) -> u32 {
let mut count = 0;
let mut column = 0;
for c in self.chars_at(DisplayPoint::new(display_row, 0)) {
if c == '\n' || count >= char_count {
for (count, c) in self.chars_at(DisplayPoint::new(display_row, 0)).enumerate() {
if c == '\n' || count >= char_count as usize {
break;
}
count += 1;
column += c.len_utf8() as u32;
}
column
}
@@ -401,20 +397,17 @@ impl DisplaySnapshot {
DisplayPoint(point)
}
pub fn folds_in_range<'a, T>(
&'a self,
range: Range<T>,
) -> impl Iterator<Item = &'a Range<Anchor>>
pub fn folds_in_range<T>(&self, range: Range<T>) -> impl Iterator<Item = &Range<Anchor>>
where
T: ToOffset,
{
self.folds_snapshot.folds_in_range(range)
}
pub fn blocks_in_range<'a>(
&'a self,
pub fn blocks_in_range(
&self,
rows: Range<u32>,
) -> impl Iterator<Item = (u32, &'a TransformBlock)> {
) -> impl Iterator<Item = (u32, &TransformBlock)> {
self.blocks_snapshot.blocks_in_range(rows)
}
@@ -1015,7 +1008,7 @@ pub mod tests {
});
let buffer = cx.add_model(|cx| Buffer::new(0, text, cx).with_language(language, cx));
buffer.condition(&cx, |buf, _| !buf.is_parsing()).await;
buffer.condition(cx, |buf, _| !buf.is_parsing()).await;
let buffer = cx.add_model(|cx| MultiBuffer::singleton(buffer, cx));
let font_cache = cx.font_cache();
@@ -1102,7 +1095,7 @@ pub mod tests {
cx.update(|cx| cx.set_global(Settings::test(cx)));
let buffer = cx.add_model(|cx| Buffer::new(0, text, cx).with_language(language, cx));
buffer.condition(&cx, |buf, _| !buf.is_parsing()).await;
buffer.condition(cx, |buf, _| !buf.is_parsing()).await;
let buffer = cx.add_model(|cx| MultiBuffer::singleton(buffer, cx));
let font_cache = cx.font_cache();
@@ -1173,7 +1166,7 @@ pub mod tests {
let (text, highlighted_ranges) = marked_text_ranges(r#"constˇ «a»: B = "c «d»""#, false);
let buffer = cx.add_model(|cx| Buffer::new(0, text, cx).with_language(language, cx));
buffer.condition(&cx, |buf, _| !buf.is_parsing()).await;
buffer.condition(cx, |buf, _| !buf.is_parsing()).await;
let buffer = cx.add_model(|cx| MultiBuffer::singleton(buffer, cx));
let buffer_snapshot = buffer.read_with(cx, |buffer, cx| buffer.snapshot(cx));
+23 -22
View File
@@ -20,7 +20,7 @@ use std::{
use sum_tree::{Bias, SumTree};
use text::{Edit, Point};
const NEWLINES: &'static [u8] = &[b'\n'; u8::MAX as usize];
const NEWLINES: &[u8] = &[b'\n'; u8::MAX as usize];
pub struct BlockMap {
next_block_id: AtomicUsize,
@@ -102,6 +102,7 @@ struct Transform {
block: Option<TransformBlock>,
}
#[allow(clippy::large_enum_variant)]
#[derive(Clone)]
pub enum TransformBlock {
Custom(Arc<Block>),
@@ -317,7 +318,7 @@ impl BlockMap {
let start_block_ix = match self.blocks[last_block_ix..].binary_search_by(|probe| {
probe
.position
.to_point(&buffer)
.to_point(buffer)
.cmp(&new_buffer_start)
.then(Ordering::Greater)
}) {
@@ -335,7 +336,7 @@ impl BlockMap {
match self.blocks[start_block_ix..].binary_search_by(|probe| {
probe
.position
.to_point(&buffer)
.to_point(buffer)
.cmp(&new_buffer_end)
.then(Ordering::Greater)
}) {
@@ -349,14 +350,14 @@ impl BlockMap {
self.blocks[start_block_ix..end_block_ix]
.iter()
.map(|block| {
let mut position = block.position.to_point(&buffer);
let mut position = block.position.to_point(buffer);
match block.disposition {
BlockDisposition::Above => position.column = 0,
BlockDisposition::Below => {
position.column = buffer.line_len(position.row)
}
}
let position = wrap_snapshot.from_point(position, Bias::Left);
let position = wrap_snapshot.make_wrap_point(position, Bias::Left);
(position.row(), TransformBlock::Custom(block.clone()))
}),
);
@@ -366,7 +367,7 @@ impl BlockMap {
.map(|excerpt_boundary| {
(
wrap_snapshot
.from_point(Point::new(excerpt_boundary.row, 0), Bias::Left)
.make_wrap_point(Point::new(excerpt_boundary.row, 0), Bias::Left)
.row(),
TransformBlock::ExcerptHeader {
key: excerpt_boundary.key,
@@ -385,7 +386,7 @@ impl BlockMap {
// Place excerpt headers above custom blocks on the same row.
blocks_in_edit.sort_unstable_by(|(row_a, block_a), (row_b, block_b)| {
row_a.cmp(&row_b).then_with(|| match (block_a, block_b) {
row_a.cmp(row_b).then_with(|| match (block_a, block_b) {
(
TransformBlock::ExcerptHeader { .. },
TransformBlock::ExcerptHeader { .. },
@@ -498,9 +499,9 @@ impl<'a> BlockMapWriter<'a> {
ids.push(id);
let position = block.position;
let point = position.to_point(&buffer);
let point = position.to_point(buffer);
let wrap_row = wrap_snapshot
.from_point(Point::new(point.row, 0), Bias::Left)
.make_wrap_point(Point::new(point.row, 0), Bias::Left)
.row();
let start_row = wrap_snapshot.prev_row_boundary(WrapPoint::new(wrap_row, 0));
let end_row = wrap_snapshot
@@ -510,7 +511,7 @@ impl<'a> BlockMapWriter<'a> {
let block_ix = match self
.0
.blocks
.binary_search_by(|probe| probe.position.cmp(&position, &buffer))
.binary_search_by(|probe| probe.position.cmp(&position, buffer))
{
Ok(ix) | Err(ix) => ix,
};
@@ -543,11 +544,11 @@ impl<'a> BlockMapWriter<'a> {
let mut last_block_buffer_row = None;
self.0.blocks.retain(|block| {
if block_ids.contains(&block.id) {
let buffer_row = block.position.to_point(&buffer).row;
let buffer_row = block.position.to_point(buffer).row;
if last_block_buffer_row != Some(buffer_row) {
last_block_buffer_row = Some(buffer_row);
let wrap_row = wrap_snapshot
.from_point(Point::new(buffer_row, 0), Bias::Left)
.make_wrap_point(Point::new(buffer_row, 0), Bias::Left)
.row();
let start_row = wrap_snapshot.prev_row_boundary(WrapPoint::new(wrap_row, 0));
let end_row = wrap_snapshot
@@ -620,7 +621,7 @@ impl BlockSnapshot {
}
}
pub fn buffer_rows<'a>(&'a self, start_row: u32) -> BlockBufferRows<'a> {
pub fn buffer_rows(&self, start_row: u32) -> BlockBufferRows {
let mut cursor = self.transforms.cursor::<(BlockRow, WrapRow)>();
cursor.seek(&BlockRow(start_row), Bias::Right, &());
let (output_start, input_start) = cursor.start();
@@ -638,10 +639,10 @@ impl BlockSnapshot {
}
}
pub fn blocks_in_range<'a>(
&'a self,
pub fn blocks_in_range(
&self,
rows: Range<u32>,
) -> impl Iterator<Item = (u32, &'a TransformBlock)> {
) -> impl Iterator<Item = (u32, &TransformBlock)> {
let mut cursor = self.transforms.cursor::<BlockRow>();
cursor.seek(&BlockRow(rows.start), Bias::Right, &());
std::iter::from_fn(move || {
@@ -1025,7 +1026,7 @@ mod tests {
let buffer_snapshot = buffer.read(cx).snapshot(cx);
let subscription = buffer.update(cx, |buffer, _| buffer.subscribe());
let (fold_map, folds_snapshot) = FoldMap::new(buffer_snapshot.clone());
let (tab_map, tabs_snapshot) = TabMap::new(folds_snapshot.clone(), 1.try_into().unwrap());
let (tab_map, tabs_snapshot) = TabMap::new(folds_snapshot, 1.try_into().unwrap());
let (wrap_map, wraps_snapshot) = WrapMap::new(tabs_snapshot, font_id, 14.0, None, cx);
let mut block_map = BlockMap::new(wraps_snapshot.clone(), 1, 1);
@@ -1194,7 +1195,7 @@ mod tests {
let buffer = MultiBuffer::build_simple(text, cx);
let buffer_snapshot = buffer.read(cx).snapshot(cx);
let (_, folds_snapshot) = FoldMap::new(buffer_snapshot.clone());
let (_, tabs_snapshot) = TabMap::new(folds_snapshot.clone(), 1.try_into().unwrap());
let (_, tabs_snapshot) = TabMap::new(folds_snapshot, 1.try_into().unwrap());
let (_, wraps_snapshot) = WrapMap::new(tabs_snapshot, font_id, 14.0, Some(60.), cx);
let mut block_map = BlockMap::new(wraps_snapshot.clone(), 1, 1);
@@ -1262,11 +1263,11 @@ mod tests {
let mut buffer_snapshot = buffer.read(cx).snapshot(cx);
let (fold_map, folds_snapshot) = FoldMap::new(buffer_snapshot.clone());
let (tab_map, tabs_snapshot) = TabMap::new(folds_snapshot.clone(), tab_size);
let (tab_map, tabs_snapshot) = TabMap::new(folds_snapshot, tab_size);
let (wrap_map, wraps_snapshot) =
WrapMap::new(tabs_snapshot, font_id, font_size, wrap_width, cx);
let mut block_map = BlockMap::new(
wraps_snapshot.clone(),
wraps_snapshot,
buffer_start_header_height,
excerpt_header_height,
);
@@ -1383,7 +1384,7 @@ mod tests {
position.column = buffer_snapshot.line_len(position.row);
}
};
let row = wraps_snapshot.from_point(position, Bias::Left).row();
let row = wraps_snapshot.make_wrap_point(position, Bias::Left).row();
(
row,
ExpectedBlock::Custom {
@@ -1396,7 +1397,7 @@ mod tests {
expected_blocks.extend(buffer_snapshot.excerpt_boundaries_in_range(0..).map(
|boundary| {
let position =
wraps_snapshot.from_point(Point::new(boundary.row, 0), Bias::Left);
wraps_snapshot.make_wrap_point(Point::new(boundary.row, 0), Bias::Left);
(
position.row(),
ExpectedBlock::ExcerptHeader {
+20 -29
View File
@@ -41,27 +41,27 @@ impl FoldPoint {
&mut self.0.column
}
pub fn to_buffer_point(&self, snapshot: &FoldSnapshot) -> Point {
pub fn to_buffer_point(self, snapshot: &FoldSnapshot) -> Point {
let mut cursor = snapshot.transforms.cursor::<(FoldPoint, Point)>();
cursor.seek(self, Bias::Right, &());
cursor.seek(&self, Bias::Right, &());
let overshoot = self.0 - cursor.start().0 .0;
cursor.start().1 + overshoot
}
pub fn to_buffer_offset(&self, snapshot: &FoldSnapshot) -> usize {
pub fn to_buffer_offset(self, snapshot: &FoldSnapshot) -> usize {
let mut cursor = snapshot.transforms.cursor::<(FoldPoint, Point)>();
cursor.seek(self, Bias::Right, &());
cursor.seek(&self, Bias::Right, &());
let overshoot = self.0 - cursor.start().0 .0;
snapshot
.buffer_snapshot
.point_to_offset(cursor.start().1 + overshoot)
}
pub fn to_offset(&self, snapshot: &FoldSnapshot) -> FoldOffset {
pub fn to_offset(self, snapshot: &FoldSnapshot) -> FoldOffset {
let mut cursor = snapshot
.transforms
.cursor::<(FoldPoint, TransformSummary)>();
cursor.seek(self, Bias::Right, &());
cursor.seek(&self, Bias::Right, &());
let overshoot = self.0 - cursor.start().1.output.lines;
let mut offset = cursor.start().1.output.len;
if !overshoot.is_zero() {
@@ -600,10 +600,7 @@ impl FoldSnapshot {
self.transforms.summary().output.longest_row
}
pub fn folds_in_range<'a, T>(
&'a self,
range: Range<T>,
) -> impl Iterator<Item = &'a Range<Anchor>>
pub fn folds_in_range<T>(&self, range: Range<T>) -> impl Iterator<Item = &Range<Anchor>>
where
T: ToOffset,
{
@@ -689,7 +686,7 @@ impl FoldSnapshot {
let ranges = &highlights.1;
let start_ix = match ranges.binary_search_by(|probe| {
let cmp = probe.end.cmp(&transform_start, &self.buffer_snapshot());
let cmp = probe.end.cmp(&transform_start, self.buffer_snapshot());
if cmp.is_gt() {
Ordering::Greater
} else {
@@ -1040,11 +1037,7 @@ impl<'a> Iterator for FoldChunks<'a> {
return None;
}
let transform = if let Some(item) = self.transform_cursor.item() {
item
} else {
return None;
};
let transform = self.transform_cursor.item()?;
// If we're in a fold, then return the fold's display text and
// advance the transform and buffer cursors to the end of the fold.
@@ -1150,11 +1143,11 @@ impl Ord for HighlightEndpoint {
pub struct FoldOffset(pub usize);
impl FoldOffset {
pub fn to_point(&self, snapshot: &FoldSnapshot) -> FoldPoint {
pub fn to_point(self, snapshot: &FoldSnapshot) -> FoldPoint {
let mut cursor = snapshot
.transforms
.cursor::<(FoldOffset, TransformSummary)>();
cursor.seek(self, Bias::Right, &());
cursor.seek(&self, Bias::Right, &());
let overshoot = if cursor.item().map_or(true, |t| t.is_fold()) {
Point::new(0, (self.0 - cursor.start().0 .0) as u32)
} else {
@@ -1214,7 +1207,7 @@ mod tests {
let buffer_snapshot = buffer.read(cx).snapshot(cx);
let mut map = FoldMap::new(buffer_snapshot.clone()).0;
let (mut writer, _, _) = map.write(buffer_snapshot.clone(), vec![]);
let (mut writer, _, _) = map.write(buffer_snapshot, vec![]);
let (snapshot2, edits) = writer.fold(vec![
Point::new(0, 2)..Point::new(2, 2),
Point::new(2, 4)..Point::new(4, 1),
@@ -1245,8 +1238,7 @@ mod tests {
);
buffer.snapshot(cx)
});
let (snapshot3, edits) =
map.read(buffer_snapshot.clone(), subscription.consume().into_inner());
let (snapshot3, edits) = map.read(buffer_snapshot, subscription.consume().into_inner());
assert_eq!(snapshot3.text(), "123a…c123c…eeeee");
assert_eq!(
edits,
@@ -1276,7 +1268,7 @@ mod tests {
let (mut writer, _, _) = map.write(buffer_snapshot.clone(), vec![]);
writer.unfold(Some(Point::new(0, 4)..Point::new(0, 4)), true);
let (snapshot6, _) = map.read(buffer_snapshot.clone(), vec![]);
let (snapshot6, _) = map.read(buffer_snapshot, vec![]);
assert_eq!(snapshot6.text(), "123aaaaa\nbbbbbb\nccc123456eee");
}
@@ -1314,7 +1306,7 @@ mod tests {
// Create two adjacent folds.
let (mut writer, _, _) = map.write(buffer_snapshot.clone(), vec![]);
writer.fold(vec![0..2, 2..5]);
let (snapshot, _) = map.read(buffer_snapshot.clone(), vec![]);
let (snapshot, _) = map.read(buffer_snapshot, vec![]);
assert_eq!(snapshot.text(), "…fghijkl");
// Edit within one of the folds.
@@ -1322,8 +1314,7 @@ mod tests {
buffer.edit([(0..1, "12345")], None, cx);
buffer.snapshot(cx)
});
let (snapshot, _) =
map.read(buffer_snapshot.clone(), subscription.consume().into_inner());
let (snapshot, _) = map.read(buffer_snapshot, subscription.consume().into_inner());
assert_eq!(snapshot.text(), "12345…fghijkl");
}
}
@@ -1340,7 +1331,7 @@ mod tests {
Point::new(1, 2)..Point::new(3, 2),
Point::new(3, 1)..Point::new(4, 1),
]);
let (snapshot, _) = map.read(buffer_snapshot.clone(), vec![]);
let (snapshot, _) = map.read(buffer_snapshot, vec![]);
assert_eq!(snapshot.text(), "aa…eeeee");
}
@@ -1357,14 +1348,14 @@ mod tests {
Point::new(0, 2)..Point::new(2, 2),
Point::new(3, 1)..Point::new(4, 1),
]);
let (snapshot, _) = map.read(buffer_snapshot.clone(), vec![]);
let (snapshot, _) = map.read(buffer_snapshot, vec![]);
assert_eq!(snapshot.text(), "aa…cccc\nd…eeeee");
let buffer_snapshot = buffer.update(cx, |buffer, cx| {
buffer.edit([(Point::new(2, 2)..Point::new(3, 1), "")], None, cx);
buffer.snapshot(cx)
});
let (snapshot, _) = map.read(buffer_snapshot.clone(), subscription.consume().into_inner());
let (snapshot, _) = map.read(buffer_snapshot, subscription.consume().into_inner());
assert_eq!(snapshot.text(), "aa…eeeee");
}
@@ -1661,7 +1652,7 @@ mod tests {
Point::new(3, 1)..Point::new(4, 1),
]);
let (snapshot, _) = map.read(buffer_snapshot.clone(), vec![]);
let (snapshot, _) = map.read(buffer_snapshot, vec![]);
assert_eq!(snapshot.text(), "aa…cccc\nd…eeeee\nffffff\n");
assert_eq!(
snapshot.buffer_rows(0).collect::<Vec<_>>(),
+5 -5
View File
@@ -253,7 +253,7 @@ impl TabSnapshot {
)
}
pub fn from_point(&self, point: Point, bias: Bias) -> TabPoint {
pub fn make_tab_point(&self, point: Point, bias: Bias) -> TabPoint {
self.to_tab_point(self.fold_snapshot.to_fold_point(point, bias))
}
@@ -290,7 +290,7 @@ impl TabSnapshot {
}
fn collapse_tabs(
mut chars: impl Iterator<Item = char>,
chars: impl Iterator<Item = char>,
column: usize,
bias: Bias,
tab_size: NonZeroU32,
@@ -298,7 +298,7 @@ impl TabSnapshot {
let mut expanded_bytes = 0;
let mut expanded_chars = 0;
let mut collapsed_bytes = 0;
while let Some(c) = chars.next() {
for c in chars {
if expanded_bytes >= column {
break;
}
@@ -410,7 +410,7 @@ impl<'a> std::ops::AddAssign<&'a Self> for TextSummary {
}
// Handles a tab width <= 16
const SPACES: &'static str = " ";
const SPACES: &str = " ";
pub struct TabChunks<'a> {
fold_chunks: fold_map::FoldChunks<'a>,
@@ -518,7 +518,7 @@ mod tests {
let (mut fold_map, _) = FoldMap::new(buffer_snapshot.clone());
fold_map.randomly_mutate(&mut rng);
let (folds_snapshot, _) = fold_map.read(buffer_snapshot.clone(), vec![]);
let (folds_snapshot, _) = fold_map.read(buffer_snapshot, vec![]);
log::info!("FoldMap text: {:?}", folds_snapshot.text());
let (_, tabs_snapshot) = TabMap::new(folds_snapshot.clone(), tab_size);
+7 -7
View File
@@ -285,7 +285,7 @@ impl WrapMap {
if tab_snapshot.version <= self.snapshot.tab_snapshot.version {
to_remove_len += 1;
} else {
let interpolated_edits = self.snapshot.interpolate(tab_snapshot.clone(), &edits);
let interpolated_edits = self.snapshot.interpolate(tab_snapshot.clone(), edits);
self.edits_since_sync = self.edits_since_sync.compose(&interpolated_edits);
self.interpolated_edits = self.interpolated_edits.compose(&interpolated_edits);
}
@@ -394,7 +394,7 @@ impl WrapSnapshot {
new_rows: Range<u32>,
}
let mut tab_edits_iter = tab_edits.into_iter().peekable();
let mut tab_edits_iter = tab_edits.iter().peekable();
let mut row_edits = Vec::new();
while let Some(edit) = tab_edits_iter.next() {
let mut row_edit = RowEdit {
@@ -671,11 +671,11 @@ impl WrapSnapshot {
self.tab_snapshot.to_point(self.to_tab_point(point), bias)
}
pub fn from_point(&self, point: Point, bias: Bias) -> WrapPoint {
self.from_tab_point(self.tab_snapshot.from_point(point, bias))
pub fn make_wrap_point(&self, point: Point, bias: Bias) -> WrapPoint {
self.tab_point_to_wrap_point(self.tab_snapshot.make_tab_point(point, bias))
}
pub fn from_tab_point(&self, point: TabPoint) -> WrapPoint {
pub fn tab_point_to_wrap_point(&self, point: TabPoint) -> WrapPoint {
let mut cursor = self.transforms.cursor::<(TabPoint, WrapPoint)>();
cursor.seek(&point, Bias::Right, &());
WrapPoint(cursor.start().1 .0 + (point.0 - cursor.start().0 .0))
@@ -691,7 +691,7 @@ impl WrapSnapshot {
}
}
self.from_tab_point(self.tab_snapshot.clip_point(self.to_tab_point(point), bias))
self.tab_point_to_wrap_point(self.tab_snapshot.clip_point(self.to_tab_point(point), bias))
}
pub fn prev_row_boundary(&self, mut point: WrapPoint) -> u32 {
@@ -1301,7 +1301,7 @@ mod tests {
end_row += 1;
let mut expected_text = self.text_chunks(start_row).collect::<String>();
if expected_text.ends_with("\n") {
if expected_text.ends_with('\n') {
expected_text.push('\n');
}
let mut expected_text = expected_text
+126 -127
View File
@@ -425,6 +425,7 @@ pub struct Editor {
vertical_scroll_margin: f32,
placeholder_text: Option<Arc<str>>,
highlighted_rows: Option<Range<u32>>,
#[allow(clippy::type_complexity)]
background_highlights: BTreeMap<TypeId, (fn(&Theme) -> Color, Vec<Range<Anchor>>)>,
nav_history: Option<ItemNavHistory>,
context_menu: Option<ContextMenu>,
@@ -475,6 +476,7 @@ impl Default for SelectionHistoryMode {
#[derive(Default)]
struct SelectionHistory {
#[allow(clippy::type_complexity)]
selections_by_transaction:
HashMap<TransactionId, (Arc<[Selection<Anchor>]>, Option<Arc<[Selection<Anchor>]>>)>,
mode: SelectionHistoryMode,
@@ -492,6 +494,7 @@ impl SelectionHistory {
.insert(transaction_id, (selections, None));
}
#[allow(clippy::type_complexity)]
fn transaction(
&self,
transaction_id: TransactionId,
@@ -499,6 +502,7 @@ impl SelectionHistory {
self.selections_by_transaction.get(&transaction_id)
}
#[allow(clippy::type_complexity)]
fn transaction_mut(
&mut self,
transaction_id: TransactionId,
@@ -1023,7 +1027,7 @@ impl Editor {
background_highlights: Default::default(),
nav_history: None,
context_menu: None,
mouse_context_menu: cx.add_view(|cx| context_menu::ContextMenu::new(cx)),
mouse_context_menu: cx.add_view(context_menu::ContextMenu::new),
completion_tasks: Default::default(),
next_completion_id: 0,
available_code_actions: Default::default(),
@@ -1649,7 +1653,7 @@ impl Editor {
if let Some(tail) = self.columnar_selection_tail.as_ref() {
let tail = tail.to_display_point(&display_map);
self.select_columns(tail, position, goal_column, &display_map, cx);
} else if let Some(mut pending) = self.selections.pending_anchor().clone() {
} else if let Some(mut pending) = self.selections.pending_anchor() {
let buffer = self.buffer.read(cx).snapshot(cx);
let head;
let tail;
@@ -1764,10 +1768,10 @@ impl Editor {
if start_column <= display_map.line_len(row) && !display_map.is_block_line(row) {
let start = display_map
.clip_point(DisplayPoint::new(row, start_column), Bias::Left)
.to_point(&display_map);
.to_point(display_map);
let end = display_map
.clip_point(DisplayPoint::new(row, end_column), Bias::Right)
.to_point(&display_map);
.to_point(display_map);
if reversed {
Some(end..start)
} else {
@@ -1915,7 +1919,7 @@ impl Editor {
cursor.row -= 1;
cursor.column = buffer.line_len(cursor.row);
}
new_selection.map(|_| cursor.clone())
new_selection.map(|_| cursor)
})
.collect();
@@ -2279,7 +2283,7 @@ impl Editor {
let query = Self::completion_query(&self.buffer.read(cx).read(cx), position.clone());
let completions = project.update(cx, |project, cx| {
project.completions(&buffer, buffer_position.clone(), cx)
project.completions(&buffer, buffer_position, cx)
});
let id = post_inc(&mut self.next_completion_id);
@@ -2369,7 +2373,7 @@ impl Editor {
};
let selections = self.selections.all::<usize>(cx);
let buffer = buffer_handle.read(cx);
let old_range = completion.old_range.to_offset(&buffer);
let old_range = completion.old_range.to_offset(buffer);
let old_text = buffer.text_for_range(old_range.clone()).collect::<String>();
let newest_selection = self.selections.newest_anchor();
@@ -2807,7 +2811,7 @@ impl Editor {
let mut tabstop_ranges = tabstop
.iter()
.flat_map(|tabstop_range| {
let mut delta = 0 as isize;
let mut delta = 0_isize;
insertion_ranges.iter().map(move |insertion_range| {
let insertion_start = insertion_range.start as isize + delta;
delta +=
@@ -2871,7 +2875,7 @@ impl Editor {
}
if let Some(current_ranges) = snippet.ranges.get(snippet.active_index) {
self.change_selections(Some(Autoscroll::Fit), cx, |s| {
s.select_anchor_ranges(current_ranges.into_iter().cloned())
s.select_anchor_ranges(current_ranges.iter().cloned())
});
// If snippet state is not at the last tabstop, push it back on the stack
if snippet.active_index + 1 < snippet.ranges.len() {
@@ -2953,7 +2957,7 @@ impl Editor {
}
})
});
this.insert(&"", cx);
this.insert("", cx);
});
}
@@ -3220,13 +3224,13 @@ impl Editor {
}
let buffer = &display_map.buffer_snapshot;
let mut edit_start = Point::new(rows.start, 0).to_offset(&buffer);
let mut edit_start = Point::new(rows.start, 0).to_offset(buffer);
let edit_end;
let cursor_buffer_row;
if buffer.max_point().row >= rows.end {
// If there's a line after the range, delete the \n from the end of the row range
// and position the cursor on the next line.
edit_end = Point::new(rows.end, 0).to_offset(&buffer);
edit_end = Point::new(rows.end, 0).to_offset(buffer);
cursor_buffer_row = rows.end;
} else {
// If there isn't a line after the range, delete the \n from the line before the
@@ -3292,7 +3296,7 @@ impl Editor {
while let Some(next_selection) = selections_iter.peek() {
let next_rows = next_selection.spanned_rows(false, &display_map);
if next_rows.start <= rows.end - 1 {
if next_rows.start < rows.end {
rows.end = next_rows.end;
selections_iter.next().unwrap();
} else {
@@ -3414,7 +3418,7 @@ impl Editor {
}
// If we didn't move line(s), preserve the existing selections
new_selections.extend(contiguous_row_selections.drain(..));
new_selections.append(&mut contiguous_row_selections);
}
self.transact(cx, |this, cx| {
@@ -3519,7 +3523,7 @@ impl Editor {
}
// If we didn't move line(s), preserve the existing selections
new_selections.extend(contiguous_row_selections.drain(..));
new_selections.append(&mut contiguous_row_selections);
}
self.transact(cx, |this, cx| {
@@ -3831,7 +3835,7 @@ impl Editor {
if !selection.is_empty() && !line_mode {
selection.goal = SelectionGoal::None;
}
let (cursor, goal) = movement::up(&map, selection.start, selection.goal, false);
let (cursor, goal) = movement::up(map, selection.start, selection.goal, false);
selection.collapse_to(cursor, goal);
});
})
@@ -3863,7 +3867,7 @@ impl Editor {
if !selection.is_empty() && !line_mode {
selection.goal = SelectionGoal::None;
}
let (cursor, goal) = movement::down(&map, selection.end, selection.goal, false);
let (cursor, goal) = movement::down(map, selection.end, selection.goal, false);
selection.collapse_to(cursor, goal);
});
});
@@ -4779,12 +4783,10 @@ impl Editor {
} else {
search_start = buffer.len();
}
} else if search_start == 0 {
break;
} else {
if search_start == 0 {
break;
} else {
search_start = 0;
}
search_start = 0;
}
}
}
@@ -5107,13 +5109,7 @@ impl Editor {
})?;
let rename = workspace.project().clone().update(cx, |project, cx| {
project.perform_rename(
buffer.clone(),
range.start.clone(),
new_name.clone(),
true,
cx,
)
project.perform_rename(buffer.clone(), range.start, new_name.clone(), true, cx)
});
Some(cx.spawn(|workspace, mut cx| async move {
@@ -5292,7 +5288,7 @@ impl Editor {
fn push_to_selection_history(&mut self) {
self.selection_history.push(SelectionHistoryEntry {
selections: self.selections.disjoint_anchors().clone(),
selections: self.selections.disjoint_anchors(),
select_next_state: self.select_next_state.clone(),
add_selections_state: self.add_selections_state.clone(),
});
@@ -5325,7 +5321,7 @@ impl Editor {
.update(cx, |buffer, cx| buffer.start_transaction_at(now, cx))
{
self.selection_history
.insert_transaction(tx_id, self.selections.disjoint_anchors().clone());
.insert_transaction(tx_id, self.selections.disjoint_anchors());
}
}
@@ -5339,7 +5335,7 @@ impl Editor {
.update(cx, |buffer, cx| buffer.end_transaction_at(now, cx))
{
if let Some((_, end_selections)) = self.selection_history.transaction_mut(tx_id) {
*end_selections = Some(self.selections.disjoint_anchors().clone());
*end_selections = Some(self.selections.disjoint_anchors());
} else {
log::error!("unexpectedly ended a transaction that wasn't started by this editor");
}
@@ -5441,7 +5437,7 @@ impl Editor {
}
let end = end.unwrap_or(max_point);
return start.to_point(display_map)..end.to_point(display_map);
start.to_point(display_map)..end.to_point(display_map)
}
pub fn fold_selected_ranges(&mut self, _: &FoldSelectedRanges, cx: &mut ViewContext<Self>) {
@@ -5588,6 +5584,7 @@ impl Editor {
cx.notify();
}
#[allow(clippy::type_complexity)]
pub fn clear_background_highlights<T: 'static>(
&mut self,
cx: &mut ViewContext<Self>,
@@ -5629,7 +5626,7 @@ impl Editor {
.chain(write_highlights)
.flat_map(move |ranges| {
let start_ix = match ranges.binary_search_by(|probe| {
let cmp = probe.end.cmp(&left_position, &buffer);
let cmp = probe.end.cmp(&left_position, buffer);
if cmp.is_ge() {
Ordering::Greater
} else {
@@ -5642,7 +5639,7 @@ impl Editor {
let right_position = right_position.clone();
ranges[start_ix..]
.iter()
.take_while(move |range| range.start.cmp(&right_position, &buffer).is_le())
.take_while(move |range| range.start.cmp(&right_position, buffer).is_le())
})
}
@@ -5657,7 +5654,7 @@ impl Editor {
for (color_fetcher, ranges) in self.background_highlights.values() {
let color = color_fetcher(theme);
let start_ix = match ranges.binary_search_by(|probe| {
let cmp = probe.end.cmp(&search_range.start, &buffer);
let cmp = probe.end.cmp(&search_range.start, buffer);
if cmp.is_gt() {
Ordering::Greater
} else {
@@ -5667,7 +5664,7 @@ impl Editor {
Ok(i) | Err(i) => i,
};
for range in &ranges[start_ix..] {
if range.start.cmp(&search_range.end, &buffer).is_ge() {
if range.start.cmp(&search_range.end, buffer).is_ge() {
break;
}
let start = range
@@ -5899,7 +5896,7 @@ impl Editor {
let (_, ranges) = self.text_highlights::<InputComposition>(cx)?;
Some(
ranges
.into_iter()
.iter()
.map(move |range| {
range.start.to_offset_utf16(&snapshot)..range.end.to_offset_utf16(&snapshot)
})
@@ -6138,10 +6135,8 @@ impl View for Editor {
let new_selected_ranges = if let Some(range_utf16) = range_utf16 {
let range_utf16 = OffsetUtf16(range_utf16.start)..OffsetUtf16(range_utf16.end);
Some(this.selection_replacement_ranges(range_utf16, cx))
} else if let Some(marked_ranges) = this.marked_text_ranges(cx) {
Some(marked_ranges)
} else {
None
this.marked_text_ranges(cx)
};
if let Some(new_selected_ranges) = new_selected_ranges {
@@ -6202,7 +6197,7 @@ impl View for Editor {
let snapshot = this.buffer.read(cx).read(cx);
this.selections
.disjoint_anchors()
.into_iter()
.iter()
.map(|selection| {
selection.start.bias_left(&*snapshot)..selection.end.bias_right(&*snapshot)
})
@@ -6385,9 +6380,9 @@ impl<T: InvalidationRegion> InvalidationStack<T> {
if selections.len() == region.ranges().len() {
selections
.iter()
.zip(region.ranges().iter().map(|r| r.to_offset(&buffer)))
.zip(region.ranges().iter().map(|r| r.to_offset(buffer)))
.all(|(selection, invalidation_range)| {
let head = selection.head().to_offset(&buffer);
let head = selection.head().to_offset(buffer);
invalidation_range.start <= head && invalidation_range.end >= head
})
} else {
@@ -6602,7 +6597,7 @@ pub fn styled_runs_for_code_label<'a>(
} else {
return Default::default();
};
let mut muted_style = style.clone();
let mut muted_style = style;
muted_style.highlight(fade_out);
let mut runs = SmallVec::<[(Range<usize>, HighlightStyle); 3]>::new();
@@ -7104,7 +7099,7 @@ mod tests {
fn test_navigation_history(cx: &mut gpui::MutableAppContext) {
cx.set_global(Settings::test(cx));
use workspace::Item;
let (_, pane) = cx.add_window(Default::default(), |cx| Pane::new(cx));
let (_, pane) = cx.add_window(Default::default(), Pane::new);
let buffer = MultiBuffer::build_simple(&sample_text(300, 5, 'a'), cx);
cx.add_view(&pane, |cx| {
@@ -7194,7 +7189,7 @@ mod tests {
Box::new(NavigationData {
cursor_anchor: invalid_anchor.clone(),
cursor_position: invalid_point,
scroll_top_anchor: invalid_anchor.clone(),
scroll_top_anchor: invalid_anchor,
scroll_top_row: invalid_point.row,
scroll_position: Default::default(),
}),
@@ -8704,98 +8699,102 @@ mod tests {
fn test_transpose(cx: &mut gpui::MutableAppContext) {
cx.set_global(Settings::test(cx));
cx.add_window(Default::default(), |cx| {
let mut editor = build_editor(MultiBuffer::build_simple("abc", cx), cx);
_ = cx
.add_window(Default::default(), |cx| {
let mut editor = build_editor(MultiBuffer::build_simple("abc", cx), cx);
editor.change_selections(None, cx, |s| s.select_ranges([1..1]));
editor.transpose(&Default::default(), cx);
assert_eq!(editor.text(cx), "bac");
assert_eq!(editor.selections.ranges(cx), [2..2]);
editor.change_selections(None, cx, |s| s.select_ranges([1..1]));
editor.transpose(&Default::default(), cx);
assert_eq!(editor.text(cx), "bac");
assert_eq!(editor.selections.ranges(cx), [2..2]);
editor.transpose(&Default::default(), cx);
assert_eq!(editor.text(cx), "bca");
assert_eq!(editor.selections.ranges(cx), [3..3]);
editor.transpose(&Default::default(), cx);
assert_eq!(editor.text(cx), "bca");
assert_eq!(editor.selections.ranges(cx), [3..3]);
editor.transpose(&Default::default(), cx);
assert_eq!(editor.text(cx), "bac");
assert_eq!(editor.selections.ranges(cx), [3..3]);
editor.transpose(&Default::default(), cx);
assert_eq!(editor.text(cx), "bac");
assert_eq!(editor.selections.ranges(cx), [3..3]);
editor
})
.1;
editor
})
.1;
cx.add_window(Default::default(), |cx| {
let mut editor = build_editor(MultiBuffer::build_simple("abc\nde", cx), cx);
_ = cx
.add_window(Default::default(), |cx| {
let mut editor = build_editor(MultiBuffer::build_simple("abc\nde", cx), cx);
editor.change_selections(None, cx, |s| s.select_ranges([3..3]));
editor.transpose(&Default::default(), cx);
assert_eq!(editor.text(cx), "acb\nde");
assert_eq!(editor.selections.ranges(cx), [3..3]);
editor.change_selections(None, cx, |s| s.select_ranges([3..3]));
editor.transpose(&Default::default(), cx);
assert_eq!(editor.text(cx), "acb\nde");
assert_eq!(editor.selections.ranges(cx), [3..3]);
editor.change_selections(None, cx, |s| s.select_ranges([4..4]));
editor.transpose(&Default::default(), cx);
assert_eq!(editor.text(cx), "acbd\ne");
assert_eq!(editor.selections.ranges(cx), [5..5]);
editor.change_selections(None, cx, |s| s.select_ranges([4..4]));
editor.transpose(&Default::default(), cx);
assert_eq!(editor.text(cx), "acbd\ne");
assert_eq!(editor.selections.ranges(cx), [5..5]);
editor.transpose(&Default::default(), cx);
assert_eq!(editor.text(cx), "acbde\n");
assert_eq!(editor.selections.ranges(cx), [6..6]);
editor.transpose(&Default::default(), cx);
assert_eq!(editor.text(cx), "acbde\n");
assert_eq!(editor.selections.ranges(cx), [6..6]);
editor.transpose(&Default::default(), cx);
assert_eq!(editor.text(cx), "acbd\ne");
assert_eq!(editor.selections.ranges(cx), [6..6]);
editor.transpose(&Default::default(), cx);
assert_eq!(editor.text(cx), "acbd\ne");
assert_eq!(editor.selections.ranges(cx), [6..6]);
editor
})
.1;
editor
})
.1;
cx.add_window(Default::default(), |cx| {
let mut editor = build_editor(MultiBuffer::build_simple("abc\nde", cx), cx);
_ = cx
.add_window(Default::default(), |cx| {
let mut editor = build_editor(MultiBuffer::build_simple("abc\nde", cx), cx);
editor.change_selections(None, cx, |s| s.select_ranges([1..1, 2..2, 4..4]));
editor.transpose(&Default::default(), cx);
assert_eq!(editor.text(cx), "bacd\ne");
assert_eq!(editor.selections.ranges(cx), [2..2, 3..3, 5..5]);
editor.change_selections(None, cx, |s| s.select_ranges([1..1, 2..2, 4..4]));
editor.transpose(&Default::default(), cx);
assert_eq!(editor.text(cx), "bacd\ne");
assert_eq!(editor.selections.ranges(cx), [2..2, 3..3, 5..5]);
editor.transpose(&Default::default(), cx);
assert_eq!(editor.text(cx), "bcade\n");
assert_eq!(editor.selections.ranges(cx), [3..3, 4..4, 6..6]);
editor.transpose(&Default::default(), cx);
assert_eq!(editor.text(cx), "bcade\n");
assert_eq!(editor.selections.ranges(cx), [3..3, 4..4, 6..6]);
editor.transpose(&Default::default(), cx);
assert_eq!(editor.text(cx), "bcda\ne");
assert_eq!(editor.selections.ranges(cx), [4..4, 6..6]);
editor.transpose(&Default::default(), cx);
assert_eq!(editor.text(cx), "bcda\ne");
assert_eq!(editor.selections.ranges(cx), [4..4, 6..6]);
editor.transpose(&Default::default(), cx);
assert_eq!(editor.text(cx), "bcade\n");
assert_eq!(editor.selections.ranges(cx), [4..4, 6..6]);
editor.transpose(&Default::default(), cx);
assert_eq!(editor.text(cx), "bcade\n");
assert_eq!(editor.selections.ranges(cx), [4..4, 6..6]);
editor.transpose(&Default::default(), cx);
assert_eq!(editor.text(cx), "bcaed\n");
assert_eq!(editor.selections.ranges(cx), [5..5, 6..6]);
editor.transpose(&Default::default(), cx);
assert_eq!(editor.text(cx), "bcaed\n");
assert_eq!(editor.selections.ranges(cx), [5..5, 6..6]);
editor
})
.1;
editor
})
.1;
cx.add_window(Default::default(), |cx| {
let mut editor = build_editor(MultiBuffer::build_simple("🍐🏀✋", cx), cx);
_ = cx
.add_window(Default::default(), |cx| {
let mut editor = build_editor(MultiBuffer::build_simple("🍐🏀✋", cx), cx);
editor.change_selections(None, cx, |s| s.select_ranges([4..4]));
editor.transpose(&Default::default(), cx);
assert_eq!(editor.text(cx), "🏀🍐✋");
assert_eq!(editor.selections.ranges(cx), [8..8]);
editor.change_selections(None, cx, |s| s.select_ranges([4..4]));
editor.transpose(&Default::default(), cx);
assert_eq!(editor.text(cx), "🏀🍐✋");
assert_eq!(editor.selections.ranges(cx), [8..8]);
editor.transpose(&Default::default(), cx);
assert_eq!(editor.text(cx), "🏀✋🍐");
assert_eq!(editor.selections.ranges(cx), [11..11]);
editor.transpose(&Default::default(), cx);
assert_eq!(editor.text(cx), "🏀✋🍐");
assert_eq!(editor.selections.ranges(cx), [11..11]);
editor.transpose(&Default::default(), cx);
assert_eq!(editor.text(cx), "🏀🍐✋");
assert_eq!(editor.selections.ranges(cx), [11..11]);
editor.transpose(&Default::default(), cx);
assert_eq!(editor.text(cx), "🏀🍐✋");
assert_eq!(editor.selections.ranges(cx), [11..11]);
editor
})
.1;
editor
})
.1;
}
#[gpui::test]
@@ -9347,7 +9346,7 @@ mod tests {
let buffer = cx.add_model(|cx| Buffer::new(0, text, cx).with_language(language, cx));
let buffer = cx.add_model(|cx| MultiBuffer::singleton(buffer, cx));
let (_, view) = cx.add_window(|cx| build_editor(buffer, cx));
view.condition(&cx, |view, cx| !view.buffer.read(cx).is_parsing(cx))
view.condition(cx, |view, cx| !view.buffer.read(cx).is_parsing(cx))
.await;
view.update(cx, |view, cx| {
@@ -9506,7 +9505,7 @@ mod tests {
let buffer = cx.add_model(|cx| MultiBuffer::singleton(buffer, cx));
let (_, editor) = cx.add_window(|cx| build_editor(buffer, cx));
editor
.condition(&cx, |editor, cx| !editor.buffer.read(cx).is_parsing(cx))
.condition(cx, |editor, cx| !editor.buffer.read(cx).is_parsing(cx))
.await;
editor.update(cx, |editor, cx| {
@@ -9566,7 +9565,7 @@ mod tests {
let buffer = cx.add_model(|cx| Buffer::new(0, text, cx).with_language(language, cx));
let buffer = cx.add_model(|cx| MultiBuffer::singleton(buffer, cx));
let (_, view) = cx.add_window(|cx| build_editor(buffer, cx));
view.condition(&cx, |view, cx| !view.buffer.read(cx).is_parsing(cx))
view.condition(cx, |view, cx| !view.buffer.read(cx).is_parsing(cx))
.await;
view.update(cx, |view, cx| {
@@ -9742,7 +9741,7 @@ mod tests {
let buffer = cx.add_model(|cx| Buffer::new(0, text, cx).with_language(language, cx));
let buffer = cx.add_model(|cx| MultiBuffer::singleton(buffer, cx));
let (_, view) = cx.add_window(|cx| build_editor(buffer, cx));
view.condition(&cx, |view, cx| !view.buffer.read(cx).is_parsing(cx))
view.condition(cx, |view, cx| !view.buffer.read(cx).is_parsing(cx))
.await;
view.update(cx, |view, cx| {
@@ -9824,7 +9823,7 @@ mod tests {
let buffer = cx.add_model(|cx| MultiBuffer::singleton(buffer, cx));
let (_, editor) = cx.add_window(|cx| build_editor(buffer, cx));
editor
.condition(&cx, |view, cx| !view.buffer.read(cx).is_parsing(cx))
.condition(cx, |view, cx| !view.buffer.read(cx).is_parsing(cx))
.await;
editor.update(cx, |editor, cx| {
@@ -10028,7 +10027,7 @@ mod tests {
}))
.await;
let fs = FakeFs::new(cx.background().clone());
let fs = FakeFs::new(cx.background());
fs.insert_file("/file.rs", Default::default()).await;
let project = Project::test(fs, ["/file.rs".as_ref()], cx).await;
@@ -10142,7 +10141,7 @@ mod tests {
}))
.await;
let fs = FakeFs::new(cx.background().clone());
let fs = FakeFs::new(cx.background());
fs.insert_file("/file.rs", Default::default()).await;
let project = Project::test(fs, ["/file.rs".as_ref()], cx).await;
@@ -10425,7 +10424,7 @@ mod tests {
.map(|completion_text| lsp::CompletionItem {
label: completion_text.to_string(),
text_edit: Some(lsp::CompletionTextEdit::Edit(lsp::TextEdit {
range: replace_range.clone(),
range: replace_range,
new_text: completion_text.to_string(),
})),
..Default::default()
@@ -10856,7 +10855,7 @@ mod tests {
let buffer = cx.add_model(|cx| Buffer::new(0, text, cx).with_language(language, cx));
let buffer = cx.add_model(|cx| MultiBuffer::singleton(buffer, cx));
let (_, view) = cx.add_window(|cx| build_editor(buffer, cx));
view.condition(&cx, |view, cx| !view.buffer.read(cx).is_parsing(cx))
view.condition(cx, |view, cx| !view.buffer.read(cx).is_parsing(cx))
.await;
view.update(cx, |view, cx| {
@@ -11084,7 +11083,7 @@ mod tests {
let match_indices = [4, 6, 7, 8];
assert_eq!(
combine_syntax_and_fuzzy_match_highlights(
&string,
string,
Default::default(),
syntax_ranges.into_iter(),
&match_indices,
+19 -14
View File
@@ -110,6 +110,7 @@ impl EditorElement {
self.update_view(cx, |view, cx| view.snapshot(cx))
}
#[allow(clippy::too_many_arguments)]
fn mouse_down(
&self,
position: Vector2F,
@@ -696,6 +697,7 @@ impl EditorElement {
cx.scene.pop_layer();
}
#[allow(clippy::too_many_arguments)]
fn paint_highlighted_range(
&self,
range: Range<DisplayPoint>,
@@ -857,7 +859,7 @@ impl EditorElement {
.style
.placeholder_text
.as_ref()
.unwrap_or_else(|| &self.style.text);
.unwrap_or(&self.style.text);
let placeholder_text = snapshot.placeholder_text();
let placeholder_lines = placeholder_text
.as_ref()
@@ -866,7 +868,7 @@ impl EditorElement {
.skip(rows.start as usize)
.chain(iter::repeat(""))
.take(rows.len());
return placeholder_lines
placeholder_lines
.map(|line| {
cx.text_layout_cache.layout_str(
line,
@@ -881,7 +883,7 @@ impl EditorElement {
)],
)
})
.collect();
.collect()
} else {
let style = &self.style;
let chunks = snapshot.chunks(rows.clone(), true).map(|chunk| {
@@ -926,14 +928,15 @@ impl EditorElement {
layout_highlighted_chunks(
chunks,
&style.text,
&cx.text_layout_cache,
&cx.font_cache,
cx.text_layout_cache,
cx.font_cache,
MAX_LINE_LEN,
rows.len() as usize,
)
}
}
#[allow(clippy::too_many_arguments)]
fn layout_blocks(
&mut self,
rows: Range<u32>,
@@ -1299,7 +1302,9 @@ impl Element for EditorElement {
}
// Render the local selections in the leader's color when following.
let local_replica_id = view.leader_replica_id.unwrap_or(view.replica_id(cx));
let local_replica_id = view
.leader_replica_id
.unwrap_or_else(|| view.replica_id(cx));
selections.push((
local_replica_id,
@@ -1357,19 +1362,19 @@ impl Element for EditorElement {
self.update_view(cx.app, |view, cx| {
let clamped = view.clamp_scroll_left(scroll_max.x());
let autoscrolled;
if autoscroll_horizontally {
autoscrolled = view.autoscroll_horizontally(
let autoscrolled = if autoscroll_horizontally {
view.autoscroll_horizontally(
start_row,
text_size.x(),
scroll_width,
em_width,
&line_layouts,
cx,
);
)
} else {
autoscrolled = false;
}
false
};
if clamped || autoscrolled {
snapshot = view.snapshot(cx);
@@ -1991,8 +1996,8 @@ mod tests {
let layouts = editor.update(cx, |editor, cx| {
let snapshot = editor.snapshot(cx);
let mut presenter = cx.build_presenter(window_id, 30.);
let mut layout_cx = presenter.build_layout_context(Vector2F::zero(), false, cx);
element.layout_line_numbers(0..6, &Default::default(), &snapshot, &mut layout_cx)
let layout_cx = presenter.build_layout_context(Vector2F::zero(), false, cx);
element.layout_line_numbers(0..6, &Default::default(), &snapshot, &layout_cx)
});
assert_eq!(layouts.len(), 6);
}
+2 -2
View File
@@ -158,7 +158,7 @@ fn show_hover(
// query the LSP for hover info
let hover_request = cx.update(|cx| {
project.update(cx, |project, cx| {
project.hover(&buffer, buffer_position.clone(), cx)
project.hover(&buffer, buffer_position, cx)
})
});
@@ -222,7 +222,7 @@ fn show_hover(
Some(InfoPopover {
project: project.clone(),
symbol_range: range.clone(),
symbol_range: range,
contents: hover_result.contents,
})
});
+20 -17
View File
@@ -76,14 +76,14 @@ impl FollowableItem for Editor {
})
.collect::<Result<Vec<_>>>()?;
if !selections.is_empty() {
editor.set_selections_from_remote(selections.into(), cx);
editor.set_selections_from_remote(selections, cx);
}
if let Some(anchor) = state.scroll_top_anchor {
editor.set_scroll_top_anchor(
Anchor {
buffer_id: Some(state.buffer_id as usize),
excerpt_id: excerpt_id.clone(),
excerpt_id,
text_anchor: language::proto::deserialize_anchor(anchor)
.ok_or_else(|| anyhow!("invalid scroll top"))?,
},
@@ -198,19 +198,17 @@ impl FollowableItem for Editor {
if !selections.is_empty() {
self.set_selections_from_remote(selections, cx);
self.request_autoscroll_remotely(Autoscroll::Newest, cx);
} else {
if let Some(anchor) = message.scroll_top_anchor {
self.set_scroll_top_anchor(
Anchor {
buffer_id: Some(buffer_id),
excerpt_id: excerpt_id.clone(),
text_anchor: language::proto::deserialize_anchor(anchor)
.ok_or_else(|| anyhow!("invalid scroll top"))?,
},
vec2f(message.scroll_x, message.scroll_y),
cx,
);
}
} else if let Some(anchor) = message.scroll_top_anchor {
self.set_scroll_top_anchor(
Anchor {
buffer_id: Some(buffer_id),
excerpt_id,
text_anchor: language::proto::deserialize_anchor(anchor)
.ok_or_else(|| anyhow!("invalid scroll top"))?,
},
vec2f(message.scroll_x, message.scroll_y),
cx,
);
}
}
}
@@ -436,8 +434,7 @@ impl Item for Editor {
.buffer()
.read(cx)
.as_singleton()
.expect("cannot call save_as on an excerpt list")
.clone();
.expect("cannot call save_as on an excerpt list");
project.update(cx, |project, cx| {
project.save_buffer_as(buffer, abs_path, cx)
@@ -503,6 +500,12 @@ pub struct CursorPosition {
_observe_active_editor: Option<Subscription>,
}
impl Default for CursorPosition {
fn default() -> Self {
Self::new()
}
}
impl CursorPosition {
pub fn new() -> Self {
Self {
+5 -7
View File
@@ -83,7 +83,7 @@ pub fn update_go_to_definition_link(
&point,
&editor.link_go_to_definition_state.last_mouse_location,
) {
if a.cmp(&b, &snapshot.buffer_snapshot).is_eq() {
if a.cmp(b, &snapshot.buffer_snapshot).is_eq() {
return;
}
}
@@ -126,7 +126,7 @@ pub fn cmd_shift_changed(
LinkDefinitionKind::Symbol
};
show_link_definition(kind, editor, point.clone(), snapshot, cx);
show_link_definition(kind, editor, point, snapshot, cx);
} else {
hide_link_definition(editor, cx)
}
@@ -204,12 +204,10 @@ pub fn show_link_definition(
// query the LSP for definition info
let definition_request = cx.update(|cx| {
project.update(cx, |project, cx| match definition_kind {
LinkDefinitionKind::Symbol => {
project.definition(&buffer, buffer_position.clone(), cx)
}
LinkDefinitionKind::Symbol => project.definition(&buffer, buffer_position, cx),
LinkDefinitionKind::Type => {
project.type_definition(&buffer, buffer_position.clone(), cx)
project.type_definition(&buffer, buffer_position, cx)
}
})
});
@@ -363,7 +361,7 @@ fn go_to_fetched_definition_of_kind(
editor_handle.update(cx, |editor, cx| {
editor.select(
&Select(SelectPhase::Begin {
position: point.clone(),
position: point,
add: false,
click_count: 1,
}),
+59 -67
View File
@@ -33,7 +33,7 @@ use text::{
use theme::SyntaxTheme;
use util::post_inc;
const NEWLINES: &'static [u8] = &[b'\n'; u8::MAX as usize];
const NEWLINES: &[u8] = &[b'\n'; u8::MAX as usize];
pub type ExcerptId = Locator;
@@ -289,10 +289,16 @@ impl MultiBuffer {
self.read(cx).has_conflict()
}
// The `is_empty` signature doesn't match what clippy expects
#[allow(clippy::len_without_is_empty)]
pub fn len(&self, cx: &AppContext) -> usize {
self.read(cx).len()
}
pub fn is_empty(&self, cx: &AppContext) -> bool {
self.len(cx) != 0
}
pub fn symbols_containing<T: ToOffset>(
&self,
offset: T,
@@ -338,6 +344,7 @@ impl MultiBuffer {
_ => Default::default(),
};
#[allow(clippy::type_complexity)]
let mut buffer_edits: HashMap<usize, Vec<(Range<usize>, Arc<str>, bool, u32)>> =
Default::default();
let mut cursor = snapshot.excerpts.cursor::<usize>();
@@ -594,13 +601,13 @@ impl MultiBuffer {
break;
}
let mut start = excerpt.range.context.start.clone();
let mut end = excerpt.range.context.end.clone();
let mut start = excerpt.range.context.start;
let mut end = excerpt.range.context.end;
if excerpt.id == selection.start.excerpt_id {
start = selection.start.text_anchor.clone();
start = selection.start.text_anchor;
}
if excerpt.id == selection.end.excerpt_id {
end = selection.end.text_anchor.clone();
end = selection.end.text_anchor;
}
selections_by_buffer
.entry(excerpt.buffer_id)
@@ -666,7 +673,7 @@ impl MultiBuffer {
while let Some(transaction) = self.history.pop_undo() {
let mut undone = false;
for (buffer_id, buffer_transaction_id) in &mut transaction.buffer_transactions {
if let Some(BufferState { buffer, .. }) = self.buffers.borrow().get(&buffer_id) {
if let Some(BufferState { buffer, .. }) = self.buffers.borrow().get(buffer_id) {
undone |= buffer.update(cx, |buffer, cx| {
let undo_to = *buffer_transaction_id;
if let Some(entry) = buffer.peek_undo_stack() {
@@ -693,7 +700,7 @@ impl MultiBuffer {
while let Some(transaction) = self.history.pop_redo() {
let mut redone = false;
for (buffer_id, buffer_transaction_id) in &mut transaction.buffer_transactions {
if let Some(BufferState { buffer, .. }) = self.buffers.borrow().get(&buffer_id) {
if let Some(BufferState { buffer, .. }) = self.buffers.borrow().get(buffer_id) {
redone |= buffer.update(cx, |buffer, cx| {
let redo_to = *buffer_transaction_id;
if let Some(entry) = buffer.peek_redo_stack() {
@@ -982,8 +989,8 @@ impl MultiBuffer {
}
// If point is at the end of the buffer, the last excerpt is returned
pub fn point_to_buffer_offset<'a, T: ToOffset>(
&'a self,
pub fn point_to_buffer_offset<T: ToOffset>(
&self,
point: T,
cx: &AppContext,
) -> Option<(ModelHandle<Buffer>, usize)> {
@@ -1004,8 +1011,8 @@ impl MultiBuffer {
})
}
pub fn range_to_buffer_ranges<'a, T: ToOffset>(
&'a self,
pub fn range_to_buffer_ranges<T: ToOffset>(
&self,
range: Range<T>,
cx: &AppContext,
) -> Vec<(ModelHandle<Buffer>, Range<usize>)> {
@@ -1112,8 +1119,8 @@ impl MultiBuffer {
cx.notify();
}
pub fn text_anchor_for_position<'a, T: ToOffset>(
&'a self,
pub fn text_anchor_for_position<T: ToOffset>(
&self,
position: T,
cx: &AppContext,
) -> Option<(ModelHandle<Buffer>, language::Anchor)> {
@@ -1439,7 +1446,7 @@ impl MultiBuffer {
.flat_map(|b| &b.excerpts)
.cloned()
.collect::<Vec<_>>();
if excerpt_ids.len() == 0 || (rng.gen() && excerpt_ids.len() < max_excerpts) {
if excerpt_ids.is_empty() || (rng.gen() && excerpt_ids.len() < max_excerpts) {
let buffer_handle = if rng.gen() || self.buffers.borrow().is_empty() {
let text = RandomCharIter::new(&mut *rng).take(10).collect::<String>();
buffers.push(cx.add_model(|cx| Buffer::new(0, text, cx)));
@@ -1514,8 +1521,8 @@ impl MultiBuffer {
.choose(rng)
.map(|state| state.buffer.clone());
if rng.gen() && buffer.is_some() {
buffer.unwrap().update(cx, |buffer, cx| {
if let Some(buffer) = buffer {
buffer.update(cx, |buffer, cx| {
if rng.gen() {
buffer.randomly_edit(rng, mutation_count, cx);
} else {
@@ -1542,10 +1549,7 @@ impl MultiBufferSnapshot {
.collect()
}
pub fn reversed_chars_at<'a, T: ToOffset>(
&'a self,
position: T,
) -> impl Iterator<Item = char> + 'a {
pub fn reversed_chars_at<T: ToOffset>(&self, position: T) -> impl Iterator<Item = char> + '_ {
let mut offset = position.to_offset(self);
let mut cursor = self.excerpts.cursor::<usize>();
cursor.seek(&offset, Bias::Left, &());
@@ -1579,16 +1583,13 @@ impl MultiBufferSnapshot {
.flat_map(|c| c.chars().rev())
}
pub fn chars_at<'a, T: ToOffset>(&'a self, position: T) -> impl Iterator<Item = char> + 'a {
pub fn chars_at<T: ToOffset>(&self, position: T) -> impl Iterator<Item = char> + '_ {
let offset = position.to_offset(self);
self.text_for_range(offset..self.len())
.flat_map(|chunk| chunk.chars())
}
pub fn text_for_range<'a, T: ToOffset>(
&'a self,
range: Range<T>,
) -> impl Iterator<Item = &'a str> {
pub fn text_for_range<T: ToOffset>(&self, range: Range<T>) -> impl Iterator<Item = &str> + '_ {
self.chunks(range, false).map(|chunk| chunk.text)
}
@@ -1655,6 +1656,10 @@ impl MultiBufferSnapshot {
self.excerpts.summary().text.len
}
pub fn is_empty(&self) -> bool {
self.excerpts.summary().text.len == 0
}
pub fn max_buffer_row(&self) -> u32 {
self.excerpts.summary().max_buffer_row
}
@@ -1737,7 +1742,7 @@ impl MultiBufferSnapshot {
*cursor.start() + overshoot
}
pub fn bytes_in_range<'a, T: ToOffset>(&'a self, range: Range<T>) -> MultiBufferBytes<'a> {
pub fn bytes_in_range<T: ToOffset>(&self, range: Range<T>) -> MultiBufferBytes {
let range = range.start.to_offset(self)..range.end.to_offset(self);
let mut excerpts = self.excerpts.cursor::<usize>();
excerpts.seek(&range.start, Bias::Right, &());
@@ -1760,7 +1765,7 @@ impl MultiBufferSnapshot {
}
}
pub fn buffer_rows<'a>(&'a self, start_row: u32) -> MultiBufferRows<'a> {
pub fn buffer_rows(&self, start_row: u32) -> MultiBufferRows {
let mut result = MultiBufferRows {
buffer_row_range: 0..0,
excerpts: self.excerpts.cursor(),
@@ -1769,11 +1774,7 @@ impl MultiBufferSnapshot {
result
}
pub fn chunks<'a, T: ToOffset>(
&'a self,
range: Range<T>,
language_aware: bool,
) -> MultiBufferChunks<'a> {
pub fn chunks<T: ToOffset>(&self, range: Range<T>, language_aware: bool) -> MultiBufferChunks {
let range = range.start.to_offset(self)..range.end.to_offset(self);
let mut chunks = MultiBufferChunks {
range: range.clone(),
@@ -2033,7 +2034,7 @@ impl MultiBufferSnapshot {
self.excerpts.summary().text.clone()
}
pub fn text_summary_for_range<'a, D, O>(&'a self, range: Range<O>) -> D
pub fn text_summary_for_range<D, O>(&self, range: Range<O>) -> D
where
D: TextDimension,
O: ToOffset,
@@ -2204,15 +2205,15 @@ impl MultiBufferSnapshot {
let (anchor_ix, anchor) = anchors.next().unwrap();
let mut anchor = anchor.clone();
// Leave min and max anchors unchanged.
if *old_excerpt_id == ExcerptId::max() || *old_excerpt_id == ExcerptId::min() {
kept_position = true;
}
// If the old excerpt still exists at this location, then leave
// the anchor unchanged.
else if next_excerpt.map_or(false, |excerpt| {
let id_invalid =
*old_excerpt_id == ExcerptId::max() || *old_excerpt_id == ExcerptId::min();
let still_exists = next_excerpt.map_or(false, |excerpt| {
excerpt.id == *old_excerpt_id && excerpt.contains(&anchor)
}) {
});
// Leave min and max anchors unchanged if invalid or
// if the old excerpt still exists at this location
if id_invalid || still_exists {
kept_position = true;
}
// If the old excerpt no longer exists at this location, then attempt to
@@ -2239,7 +2240,7 @@ impl MultiBufferSnapshot {
.cmp(&excerpt.range.context.end, &excerpt.buffer)
.is_gt()
{
text_anchor = excerpt.range.context.end.clone();
text_anchor = excerpt.range.context.end;
}
Anchor {
buffer_id: Some(excerpt.buffer_id),
@@ -2256,7 +2257,7 @@ impl MultiBufferSnapshot {
.cmp(&excerpt.range.context.start, &excerpt.buffer)
.is_lt()
{
text_anchor = excerpt.range.context.start.clone();
text_anchor = excerpt.range.context.start;
}
Anchor {
buffer_id: Some(excerpt.buffer_id),
@@ -2349,10 +2350,10 @@ impl MultiBufferSnapshot {
}
}
pub fn excerpt_boundaries_in_range<'a, R, T>(
&'a self,
pub fn excerpt_boundaries_in_range<R, T>(
&self,
range: R,
) -> impl Iterator<Item = ExcerptBoundary> + 'a
) -> impl Iterator<Item = ExcerptBoundary> + '_
where
R: RangeBounds<T>,
T: ToOffset,
@@ -2635,13 +2636,12 @@ impl MultiBufferSnapshot {
cursor
.take_while(move |excerpt| excerpt.id <= range.end.excerpt_id)
.flat_map(move |excerpt| {
let mut query_range =
excerpt.range.context.start.clone()..excerpt.range.context.end.clone();
let mut query_range = excerpt.range.context.start..excerpt.range.context.end;
if excerpt.id == range.start.excerpt_id {
query_range.start = range.start.text_anchor.clone();
query_range.start = range.start.text_anchor;
}
if excerpt.id == range.end.excerpt_id {
query_range.end = range.end.text_anchor.clone();
query_range.end = range.end.text_anchor;
}
excerpt
@@ -2652,12 +2652,12 @@ impl MultiBufferSnapshot {
let mut start = Anchor {
buffer_id: Some(excerpt.buffer_id),
excerpt_id: excerpt.id.clone(),
text_anchor: selection.start.clone(),
text_anchor: selection.start,
};
let mut end = Anchor {
buffer_id: Some(excerpt.buffer_id),
excerpt_id: excerpt.id.clone(),
text_anchor: selection.end.clone(),
text_anchor: selection.end,
};
if range.start.cmp(&start, self).is_gt() {
start = range.start.clone();
@@ -2862,11 +2862,7 @@ impl Excerpt {
}
}
fn chunks_in_range<'a>(
&'a self,
range: Range<usize>,
language_aware: bool,
) -> ExcerptChunks<'a> {
fn chunks_in_range(&self, range: Range<usize>, language_aware: bool) -> ExcerptChunks {
let content_start = self.range.context.start.to_offset(&self.buffer);
let chunks_start = content_start + range.start;
let chunks_end = content_start + cmp::min(range.end, self.text_summary.len);
@@ -2913,12 +2909,12 @@ impl Excerpt {
.cmp(&self.range.context.start, &self.buffer)
.is_lt()
{
self.range.context.start.clone()
self.range.context.start
} else if text_anchor
.cmp(&self.range.context.end, &self.buffer)
.is_gt()
{
self.range.context.end.clone()
self.range.context.end
} else {
text_anchor
}
@@ -3835,7 +3831,7 @@ mod tests {
"Removing excerpt {}: {:?}",
ix,
buffer
.text_for_range(range.to_offset(&buffer))
.text_for_range(range.to_offset(buffer))
.collect::<String>(),
);
}
@@ -3851,7 +3847,7 @@ mod tests {
let bias = if rng.gen() { Bias::Left } else { Bias::Right };
log::info!("Creating anchor at {} with bias {:?}", offset, bias);
anchors.push(multibuffer.anchor_at(offset, bias));
anchors.sort_by(|a, b| a.cmp(&b, &multibuffer));
anchors.sort_by(|a, b| a.cmp(b, &multibuffer));
}
40..=44 if !anchors.is_empty() => {
let multibuffer = multibuffer.read(cx).read(cx);
@@ -3896,7 +3892,7 @@ mod tests {
let prev_excerpt_id = excerpt_ids
.get(prev_excerpt_ix)
.cloned()
.unwrap_or(ExcerptId::max());
.unwrap_or_else(ExcerptId::max);
let excerpt_ix = (prev_excerpt_ix + 1).min(expected_excerpts.len());
log::info!(
@@ -3984,11 +3980,7 @@ mod tests {
assert_eq!(
snapshot.max_buffer_row(),
expected_buffer_rows
.into_iter()
.filter_map(|r| r)
.max()
.unwrap()
expected_buffer_rows.into_iter().flatten().max().unwrap()
);
let mut excerpt_starts = excerpt_starts.into_iter();
+4 -4
View File
@@ -34,7 +34,7 @@ impl Anchor {
&self.excerpt_id
}
pub fn cmp<'a>(&self, other: &Anchor, snapshot: &MultiBufferSnapshot) -> Ordering {
pub fn cmp(&self, other: &Anchor, snapshot: &MultiBufferSnapshot) -> Ordering {
let excerpt_id_cmp = self.excerpt_id.cmp(&other.excerpt_id);
if excerpt_id_cmp.is_eq() {
if self.excerpt_id == ExcerptId::min() || self.excerpt_id == ExcerptId::max() {
@@ -111,15 +111,15 @@ impl AnchorRangeExt for Range<Anchor> {
fn cmp(&self, other: &Range<Anchor>, buffer: &MultiBufferSnapshot) -> Ordering {
match self.start.cmp(&other.start, buffer) {
Ordering::Equal => other.end.cmp(&self.end, buffer),
ord @ _ => ord,
ord => ord,
}
}
fn to_offset(&self, content: &MultiBufferSnapshot) -> Range<usize> {
self.start.to_offset(&content)..self.end.to_offset(&content)
self.start.to_offset(content)..self.end.to_offset(content)
}
fn to_point(&self, content: &MultiBufferSnapshot) -> Range<Point> {
self.start.to_point(&content)..self.end.to_point(&content)
self.start.to_point(content)..self.end.to_point(content)
}
}
+7 -10
View File
@@ -68,7 +68,7 @@ impl SelectionsCollection {
self.pending = other.pending.clone();
}
pub fn count<'a>(&self) -> usize {
pub fn count(&self) -> usize {
let mut count = self.disjoint.len();
if self.pending.is_some() {
count += 1;
@@ -365,7 +365,7 @@ impl<'a> MutableSelectionsCollection<'a> {
let mut changed = false;
self.collection.disjoint = self
.disjoint
.into_iter()
.iter()
.filter(|selection| {
let found = selection.id == selection_id;
changed |= found;
@@ -464,7 +464,7 @@ impl<'a> MutableSelectionsCollection<'a> {
return true;
}
return false;
false
}
pub fn insert_range<T>(&mut self, range: Range<T>)
@@ -729,8 +729,7 @@ impl<'a> MutableSelectionsCollection<'a> {
kept_end
};
if !kept_head {
selections_with_lost_position
.insert(selection.id, selection.head().excerpt_id.clone());
selections_with_lost_position.insert(selection.id, selection.head().excerpt_id);
}
Selection {
@@ -761,10 +760,8 @@ impl<'a> MutableSelectionsCollection<'a> {
kept_end
};
if !kept_head {
selections_with_lost_position.insert(
pending.selection.id,
pending.selection.head().excerpt_id.clone(),
);
selections_with_lost_position
.insert(pending.selection.id, pending.selection.head().excerpt_id);
}
pending.selection.start = start;
@@ -814,5 +811,5 @@ fn resolve<D: TextDimension + Ord + Sub<D, Output = D>>(
selection: &Selection<Anchor>,
buffer: &MultiBufferSnapshot,
) -> Selection<D> {
selection.map(|p| p.summary::<D>(&buffer))
selection.map(|p| p.summary::<D>(buffer))
}