Fix failing test
This commit is contained in:
parent
5e4d113308
commit
fc811d14b1
4 changed files with 52 additions and 26 deletions
|
@ -77,14 +77,14 @@ use std::{
|
||||||
cmp::{self, Ordering, Reverse},
|
cmp::{self, Ordering, Reverse},
|
||||||
mem,
|
mem,
|
||||||
num::NonZeroU32,
|
num::NonZeroU32,
|
||||||
ops::{Deref, DerefMut, Range, RangeInclusive},
|
ops::{Deref, DerefMut, Range},
|
||||||
path::Path,
|
path::Path,
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
time::{Duration, Instant},
|
time::{Duration, Instant},
|
||||||
};
|
};
|
||||||
pub use sum_tree::Bias;
|
pub use sum_tree::Bias;
|
||||||
use theme::{DiagnosticStyle, Theme};
|
use theme::{DiagnosticStyle, Theme};
|
||||||
use util::{post_inc, ResultExt, TryFutureExt};
|
use util::{post_inc, ResultExt, TryFutureExt, RangeExt};
|
||||||
use workspace::{ItemNavHistory, ViewId, Workspace, WorkspaceId};
|
use workspace::{ItemNavHistory, ViewId, Workspace, WorkspaceId};
|
||||||
|
|
||||||
use crate::git::diff_hunk_to_display;
|
use crate::git::diff_hunk_to_display;
|
||||||
|
@ -6959,21 +6959,6 @@ pub fn split_words<'a>(text: &'a str) -> impl std::iter::Iterator<Item = &'a str
|
||||||
.flat_map(|word| word.split_inclusive('_'))
|
.flat_map(|word| word.split_inclusive('_'))
|
||||||
}
|
}
|
||||||
|
|
||||||
trait RangeExt<T> {
|
|
||||||
fn sorted(&self) -> Range<T>;
|
|
||||||
fn to_inclusive(&self) -> RangeInclusive<T>;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: Ord + Clone> RangeExt<T> for Range<T> {
|
|
||||||
fn sorted(&self) -> Self {
|
|
||||||
cmp::min(&self.start, &self.end).clone()..cmp::max(&self.start, &self.end).clone()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn to_inclusive(&self) -> RangeInclusive<T> {
|
|
||||||
self.start.clone()..=self.end.clone()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
trait RangeToAnchorExt {
|
trait RangeToAnchorExt {
|
||||||
fn to_anchors(self, snapshot: &MultiBufferSnapshot) -> Range<Anchor>;
|
fn to_anchors(self, snapshot: &MultiBufferSnapshot) -> Range<Anchor>;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2961,14 +2961,14 @@ impl MultiBufferSnapshot {
|
||||||
let range = range.start.to_offset(self)..range.end.to_offset(self);
|
let range = range.start.to_offset(self)..range.end.to_offset(self);
|
||||||
|
|
||||||
let mut cursor = self.excerpts.cursor::<usize>();
|
let mut cursor = self.excerpts.cursor::<usize>();
|
||||||
cursor.seek(&dbg!(range.start), Bias::Right, &());
|
cursor.seek(&range.start, Bias::Right, &());
|
||||||
let start_excerpt = cursor.item();
|
let start_excerpt = cursor.item();
|
||||||
|
|
||||||
if range.start == range.end {
|
if range.start == range.end {
|
||||||
return start_excerpt.map(|excerpt| (excerpt, *cursor.start()));
|
return start_excerpt.map(|excerpt| (excerpt, *cursor.start()));
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor.seek(&dbg!(range.end), Bias::Right, &());
|
cursor.seek(&range.end, Bias::Right, &());
|
||||||
let end_excerpt = cursor.item();
|
let end_excerpt = cursor.item();
|
||||||
|
|
||||||
start_excerpt
|
start_excerpt
|
||||||
|
|
|
@ -41,7 +41,7 @@ pub use text::{Buffer as TextBuffer, BufferSnapshot as TextBufferSnapshot, Opera
|
||||||
use theme::SyntaxTheme;
|
use theme::SyntaxTheme;
|
||||||
#[cfg(any(test, feature = "test-support"))]
|
#[cfg(any(test, feature = "test-support"))]
|
||||||
use util::RandomCharIter;
|
use util::RandomCharIter;
|
||||||
use util::TryFutureExt as _;
|
use util::{RangeExt, TryFutureExt as _};
|
||||||
|
|
||||||
#[cfg(any(test, feature = "test-support"))]
|
#[cfg(any(test, feature = "test-support"))]
|
||||||
pub use {tree_sitter_rust, tree_sitter_typescript};
|
pub use {tree_sitter_rust, tree_sitter_typescript};
|
||||||
|
@ -2382,7 +2382,7 @@ impl BufferSnapshot {
|
||||||
let Some((open, close)) = open.zip(close) else { continue };
|
let Some((open, close)) = open.zip(close) else { continue };
|
||||||
|
|
||||||
let bracket_range = open.start..=close.end;
|
let bracket_range = open.start..=close.end;
|
||||||
if !bracket_range.contains(&range.start) && !bracket_range.contains(&range.end) {
|
if !bracket_range.overlaps(&range) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,16 +3,17 @@ pub mod paths;
|
||||||
#[cfg(any(test, feature = "test-support"))]
|
#[cfg(any(test, feature = "test-support"))]
|
||||||
pub mod test;
|
pub mod test;
|
||||||
|
|
||||||
pub use backtrace::Backtrace;
|
|
||||||
use futures::Future;
|
|
||||||
use rand::{seq::SliceRandom, Rng};
|
|
||||||
use std::{
|
use std::{
|
||||||
cmp::Ordering,
|
cmp::{self, Ordering},
|
||||||
ops::AddAssign,
|
ops::{AddAssign, Range, RangeInclusive},
|
||||||
pin::Pin,
|
pin::Pin,
|
||||||
task::{Context, Poll},
|
task::{Context, Poll},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub use backtrace::Backtrace;
|
||||||
|
use futures::Future;
|
||||||
|
use rand::{seq::SliceRandom, Rng};
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct StaffMode(pub bool);
|
pub struct StaffMode(pub bool);
|
||||||
|
|
||||||
|
@ -245,6 +246,46 @@ macro_rules! async_iife {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait RangeExt<T> {
|
||||||
|
fn sorted(&self) -> Self;
|
||||||
|
fn to_inclusive(&self) -> RangeInclusive<T>;
|
||||||
|
fn overlaps(&self, other: &Range<T>) -> bool;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: Ord + Clone> RangeExt<T> for Range<T> {
|
||||||
|
fn sorted(&self) -> Self {
|
||||||
|
cmp::min(&self.start, &self.end).clone()..cmp::max(&self.start, &self.end).clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn to_inclusive(&self) -> RangeInclusive<T> {
|
||||||
|
self.start.clone()..=self.end.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn overlaps(&self, other: &Range<T>) -> bool {
|
||||||
|
self.contains(&other.start)
|
||||||
|
|| self.contains(&other.end)
|
||||||
|
|| other.contains(&self.start)
|
||||||
|
|| other.contains(&self.end)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: Ord + Clone> RangeExt<T> for RangeInclusive<T> {
|
||||||
|
fn sorted(&self) -> Self {
|
||||||
|
cmp::min(self.start(), self.end()).clone()..=cmp::max(self.start(), self.end()).clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn to_inclusive(&self) -> RangeInclusive<T> {
|
||||||
|
self.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn overlaps(&self, other: &Range<T>) -> bool {
|
||||||
|
self.contains(&other.start)
|
||||||
|
|| self.contains(&other.end)
|
||||||
|
|| other.contains(&self.start())
|
||||||
|
|| other.contains(&self.end())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue