Introduce diff crate to unite BufferDiff and BufferChangeSet (#24392)
This is a refactoring PR that does three things: - First, it introduces a new `diff` crate that holds the previous contents of the `git::diff` module, plus the `BufferChangeSet` type formerly of `project::buffer_store`. The new crate is necessary since simply moving `BufferChangeSet` into `git::diff` results in a dependency cycle due to the use of `language::Buffer` to represent the diff base in `BufferChangeSet`. - Second, it renames the two main types in the new diff crate: `BufferDiff` becomes `BufferDiffSnapshot`, and `BufferChangeSet` becomes `BufferDiff`. This reflects that the relationship between these two types (immutable cheaply-cloneable "value" type + stateful "resource type" with subscriptions) mirrors existing pairs like `Buffer`/`BufferSnapshot`. References to "change sets" throughout the codebase are updated to refer to "diffs" instead. - Finally, it moves the base_text field of the new BufferDiff type to BufferDiffSnapshot. Release Notes: - N/A --------- Co-authored-by: maxbrunsfeld <max@zed.dev>
This commit is contained in:
parent
ffcad71bfa
commit
73c487c222
31 changed files with 922 additions and 875 deletions
|
@ -70,15 +70,15 @@ impl Anchor {
|
|||
return text_cmp;
|
||||
}
|
||||
if self.diff_base_anchor.is_some() || other.diff_base_anchor.is_some() {
|
||||
if let Some(diff_base) = snapshot.diffs.get(&excerpt.buffer_id) {
|
||||
let self_anchor = self
|
||||
.diff_base_anchor
|
||||
.filter(|a| diff_base.base_text.can_resolve(a));
|
||||
let other_anchor = other
|
||||
.diff_base_anchor
|
||||
.filter(|a| diff_base.base_text.can_resolve(a));
|
||||
if let Some(base_text) = snapshot
|
||||
.diffs
|
||||
.get(&excerpt.buffer_id)
|
||||
.and_then(|diff| diff.base_text.as_ref())
|
||||
{
|
||||
let self_anchor = self.diff_base_anchor.filter(|a| base_text.can_resolve(a));
|
||||
let other_anchor = other.diff_base_anchor.filter(|a| base_text.can_resolve(a));
|
||||
return match (self_anchor, other_anchor) {
|
||||
(Some(a), Some(b)) => a.cmp(&b, &diff_base.base_text),
|
||||
(Some(a), Some(b)) => a.cmp(&b, base_text),
|
||||
(Some(_), None) => match other.text_anchor.bias {
|
||||
Bias::Left => Ordering::Greater,
|
||||
Bias::Right => Ordering::Less,
|
||||
|
@ -107,9 +107,13 @@ impl Anchor {
|
|||
excerpt_id: self.excerpt_id,
|
||||
text_anchor: self.text_anchor.bias_left(&excerpt.buffer),
|
||||
diff_base_anchor: self.diff_base_anchor.map(|a| {
|
||||
if let Some(base) = snapshot.diffs.get(&excerpt.buffer_id) {
|
||||
if a.buffer_id == Some(base.base_text.remote_id()) {
|
||||
return a.bias_left(&base.base_text);
|
||||
if let Some(base_text) = snapshot
|
||||
.diffs
|
||||
.get(&excerpt.buffer_id)
|
||||
.and_then(|diff| diff.base_text.as_ref())
|
||||
{
|
||||
if a.buffer_id == Some(base_text.remote_id()) {
|
||||
return a.bias_left(base_text);
|
||||
}
|
||||
}
|
||||
a
|
||||
|
@ -128,9 +132,13 @@ impl Anchor {
|
|||
excerpt_id: self.excerpt_id,
|
||||
text_anchor: self.text_anchor.bias_right(&excerpt.buffer),
|
||||
diff_base_anchor: self.diff_base_anchor.map(|a| {
|
||||
if let Some(base) = snapshot.diffs.get(&excerpt.buffer_id) {
|
||||
if a.buffer_id == Some(base.base_text.remote_id()) {
|
||||
return a.bias_right(&base.base_text);
|
||||
if let Some(base_text) = snapshot
|
||||
.diffs
|
||||
.get(&excerpt.buffer_id)
|
||||
.and_then(|diff| diff.base_text.as_ref())
|
||||
{
|
||||
if a.buffer_id == Some(base_text.remote_id()) {
|
||||
return a.bias_right(&base_text);
|
||||
}
|
||||
}
|
||||
a
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue