Rename head text to indicate that it's not always going to be from head
Co-Authored-By: Mikayla Maki <mikayla@zed.dev>
This commit is contained in:
parent
a5c2f22bf7
commit
e6487de069
11 changed files with 78 additions and 78 deletions
|
@ -948,7 +948,7 @@ async fn test_propagate_saves_and_fs_changes(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[gpui::test(iterations = 10)]
|
#[gpui::test(iterations = 10)]
|
||||||
async fn test_git_head_text(
|
async fn test_git_diff_base_change(
|
||||||
executor: Arc<Deterministic>,
|
executor: Arc<Deterministic>,
|
||||||
cx_a: &mut TestAppContext,
|
cx_a: &mut TestAppContext,
|
||||||
cx_b: &mut TestAppContext,
|
cx_b: &mut TestAppContext,
|
||||||
|
@ -977,13 +977,13 @@ async fn test_git_head_text(
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
let head_text = "
|
let diff_base = "
|
||||||
one
|
one
|
||||||
three
|
three
|
||||||
"
|
"
|
||||||
.unindent();
|
.unindent();
|
||||||
|
|
||||||
let new_head_text = "
|
let new_diff_base = "
|
||||||
one
|
one
|
||||||
two
|
two
|
||||||
"
|
"
|
||||||
|
@ -992,9 +992,9 @@ async fn test_git_head_text(
|
||||||
client_a
|
client_a
|
||||||
.fs
|
.fs
|
||||||
.as_fake()
|
.as_fake()
|
||||||
.set_head_state_for_git_repository(
|
.set_index_for_repo(
|
||||||
Path::new("/dir/.git"),
|
Path::new("/dir/.git"),
|
||||||
&[(Path::new("a.txt"), head_text.clone())],
|
&[(Path::new("a.txt"), diff_base.clone())],
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
@ -1012,11 +1012,11 @@ async fn test_git_head_text(
|
||||||
|
|
||||||
// Smoke test diffing
|
// Smoke test diffing
|
||||||
buffer_a.read_with(cx_a, |buffer, _| {
|
buffer_a.read_with(cx_a, |buffer, _| {
|
||||||
assert_eq!(buffer.head_text(), Some(head_text.as_ref()));
|
assert_eq!(buffer.diff_base(), Some(diff_base.as_ref()));
|
||||||
git::diff::assert_hunks(
|
git::diff::assert_hunks(
|
||||||
buffer.snapshot().git_diff_hunks_in_range(0..4),
|
buffer.snapshot().git_diff_hunks_in_range(0..4),
|
||||||
&buffer,
|
&buffer,
|
||||||
&head_text,
|
&diff_base,
|
||||||
&[(1..2, "", "two\n")],
|
&[(1..2, "", "two\n")],
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -1032,11 +1032,11 @@ async fn test_git_head_text(
|
||||||
|
|
||||||
// Smoke test diffing
|
// Smoke test diffing
|
||||||
buffer_b.read_with(cx_b, |buffer, _| {
|
buffer_b.read_with(cx_b, |buffer, _| {
|
||||||
assert_eq!(buffer.head_text(), Some(head_text.as_ref()));
|
assert_eq!(buffer.diff_base(), Some(diff_base.as_ref()));
|
||||||
git::diff::assert_hunks(
|
git::diff::assert_hunks(
|
||||||
buffer.snapshot().git_diff_hunks_in_range(0..4),
|
buffer.snapshot().git_diff_hunks_in_range(0..4),
|
||||||
&buffer,
|
&buffer,
|
||||||
&head_text,
|
&diff_base,
|
||||||
&[(1..2, "", "two\n")],
|
&[(1..2, "", "two\n")],
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -1044,9 +1044,9 @@ async fn test_git_head_text(
|
||||||
client_a
|
client_a
|
||||||
.fs
|
.fs
|
||||||
.as_fake()
|
.as_fake()
|
||||||
.set_head_state_for_git_repository(
|
.set_index_for_repo(
|
||||||
Path::new("/dir/.git"),
|
Path::new("/dir/.git"),
|
||||||
&[(Path::new("a.txt"), new_head_text.clone())],
|
&[(Path::new("a.txt"), new_diff_base.clone())],
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
@ -1055,23 +1055,23 @@ async fn test_git_head_text(
|
||||||
|
|
||||||
// Smoke test new diffing
|
// Smoke test new diffing
|
||||||
buffer_a.read_with(cx_a, |buffer, _| {
|
buffer_a.read_with(cx_a, |buffer, _| {
|
||||||
assert_eq!(buffer.head_text(), Some(new_head_text.as_ref()));
|
assert_eq!(buffer.diff_base(), Some(new_diff_base.as_ref()));
|
||||||
|
|
||||||
git::diff::assert_hunks(
|
git::diff::assert_hunks(
|
||||||
buffer.snapshot().git_diff_hunks_in_range(0..4),
|
buffer.snapshot().git_diff_hunks_in_range(0..4),
|
||||||
&buffer,
|
&buffer,
|
||||||
&head_text,
|
&diff_base,
|
||||||
&[(2..3, "", "three\n")],
|
&[(2..3, "", "three\n")],
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Smoke test B
|
// Smoke test B
|
||||||
buffer_b.read_with(cx_b, |buffer, _| {
|
buffer_b.read_with(cx_b, |buffer, _| {
|
||||||
assert_eq!(buffer.head_text(), Some(new_head_text.as_ref()));
|
assert_eq!(buffer.diff_base(), Some(new_diff_base.as_ref()));
|
||||||
git::diff::assert_hunks(
|
git::diff::assert_hunks(
|
||||||
buffer.snapshot().git_diff_hunks_in_range(0..4),
|
buffer.snapshot().git_diff_hunks_in_range(0..4),
|
||||||
&buffer,
|
&buffer,
|
||||||
&head_text,
|
&diff_base,
|
||||||
&[(2..3, "", "three\n")],
|
&[(2..3, "", "three\n")],
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
|
@ -206,7 +206,7 @@ impl Server {
|
||||||
.add_message_handler(Server::unfollow)
|
.add_message_handler(Server::unfollow)
|
||||||
.add_message_handler(Server::update_followers)
|
.add_message_handler(Server::update_followers)
|
||||||
.add_request_handler(Server::get_channel_messages)
|
.add_request_handler(Server::get_channel_messages)
|
||||||
.add_message_handler(Server::update_head_text)
|
.add_message_handler(Server::update_diff_base)
|
||||||
.add_request_handler(Server::get_private_user_info);
|
.add_request_handler(Server::get_private_user_info);
|
||||||
|
|
||||||
Arc::new(server)
|
Arc::new(server)
|
||||||
|
@ -1729,9 +1729,9 @@ impl Server {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update_head_text(
|
async fn update_diff_base(
|
||||||
self: Arc<Server>,
|
self: Arc<Server>,
|
||||||
request: TypedEnvelope<proto::UpdateHeadText>,
|
request: TypedEnvelope<proto::UpdateDiffBase>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let receiver_ids = self.store().await.project_connection_ids(
|
let receiver_ids = self.store().await.project_connection_ids(
|
||||||
ProjectId::from_proto(request.payload.project_id),
|
ProjectId::from_proto(request.payload.project_id),
|
||||||
|
|
|
@ -111,11 +111,11 @@ impl BufferDiff {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update(&mut self, head_text: &str, buffer: &text::BufferSnapshot) {
|
pub async fn update(&mut self, diff_base: &str, buffer: &text::BufferSnapshot) {
|
||||||
let mut tree = SumTree::new();
|
let mut tree = SumTree::new();
|
||||||
|
|
||||||
let buffer_text = buffer.as_rope().to_string();
|
let buffer_text = buffer.as_rope().to_string();
|
||||||
let patch = Self::diff(&head_text, &buffer_text);
|
let patch = Self::diff(&diff_base, &buffer_text);
|
||||||
|
|
||||||
if let Some(patch) = patch {
|
if let Some(patch) = patch {
|
||||||
let mut divergence = 0;
|
let mut divergence = 0;
|
||||||
|
@ -228,7 +228,7 @@ impl BufferDiff {
|
||||||
pub fn assert_hunks<Iter>(
|
pub fn assert_hunks<Iter>(
|
||||||
diff_hunks: Iter,
|
diff_hunks: Iter,
|
||||||
buffer: &BufferSnapshot,
|
buffer: &BufferSnapshot,
|
||||||
head_text: &str,
|
diff_base: &str,
|
||||||
expected_hunks: &[(Range<u32>, &str, &str)],
|
expected_hunks: &[(Range<u32>, &str, &str)],
|
||||||
) where
|
) where
|
||||||
Iter: Iterator<Item = DiffHunk<u32>>,
|
Iter: Iterator<Item = DiffHunk<u32>>,
|
||||||
|
@ -237,7 +237,7 @@ pub fn assert_hunks<Iter>(
|
||||||
.map(|hunk| {
|
.map(|hunk| {
|
||||||
(
|
(
|
||||||
hunk.buffer_range.clone(),
|
hunk.buffer_range.clone(),
|
||||||
&head_text[hunk.head_byte_range],
|
&diff_base[hunk.head_byte_range],
|
||||||
buffer
|
buffer
|
||||||
.text_for_range(
|
.text_for_range(
|
||||||
Point::new(hunk.buffer_range.start, 0)
|
Point::new(hunk.buffer_range.start, 0)
|
||||||
|
@ -264,7 +264,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_buffer_diff_simple() {
|
fn test_buffer_diff_simple() {
|
||||||
let head_text = "
|
let diff_base = "
|
||||||
one
|
one
|
||||||
two
|
two
|
||||||
three
|
three
|
||||||
|
@ -280,27 +280,27 @@ mod tests {
|
||||||
|
|
||||||
let mut buffer = Buffer::new(0, 0, buffer_text);
|
let mut buffer = Buffer::new(0, 0, buffer_text);
|
||||||
let mut diff = BufferDiff::new();
|
let mut diff = BufferDiff::new();
|
||||||
smol::block_on(diff.update(&head_text, &buffer));
|
smol::block_on(diff.update(&diff_base, &buffer));
|
||||||
assert_hunks(
|
assert_hunks(
|
||||||
diff.hunks(&buffer),
|
diff.hunks(&buffer),
|
||||||
&buffer,
|
&buffer,
|
||||||
&head_text,
|
&diff_base,
|
||||||
&[(1..2, "two\n", "HELLO\n")],
|
&[(1..2, "two\n", "HELLO\n")],
|
||||||
);
|
);
|
||||||
|
|
||||||
buffer.edit([(0..0, "point five\n")]);
|
buffer.edit([(0..0, "point five\n")]);
|
||||||
smol::block_on(diff.update(&head_text, &buffer));
|
smol::block_on(diff.update(&diff_base, &buffer));
|
||||||
assert_hunks(
|
assert_hunks(
|
||||||
diff.hunks(&buffer),
|
diff.hunks(&buffer),
|
||||||
&buffer,
|
&buffer,
|
||||||
&head_text,
|
&diff_base,
|
||||||
&[(0..1, "", "point five\n"), (2..3, "two\n", "HELLO\n")],
|
&[(0..1, "", "point five\n"), (2..3, "two\n", "HELLO\n")],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_buffer_diff_range() {
|
fn test_buffer_diff_range() {
|
||||||
let head_text = "
|
let diff_base = "
|
||||||
one
|
one
|
||||||
two
|
two
|
||||||
three
|
three
|
||||||
|
@ -337,13 +337,13 @@ mod tests {
|
||||||
|
|
||||||
let buffer = Buffer::new(0, 0, buffer_text);
|
let buffer = Buffer::new(0, 0, buffer_text);
|
||||||
let mut diff = BufferDiff::new();
|
let mut diff = BufferDiff::new();
|
||||||
smol::block_on(diff.update(&head_text, &buffer));
|
smol::block_on(diff.update(&diff_base, &buffer));
|
||||||
assert_eq!(diff.hunks(&buffer).count(), 8);
|
assert_eq!(diff.hunks(&buffer).count(), 8);
|
||||||
|
|
||||||
assert_hunks(
|
assert_hunks(
|
||||||
diff.hunks_in_range(7..12, &buffer),
|
diff.hunks_in_range(7..12, &buffer),
|
||||||
&buffer,
|
&buffer,
|
||||||
&head_text,
|
&diff_base,
|
||||||
&[
|
&[
|
||||||
(6..7, "", "HELLO\n"),
|
(6..7, "", "HELLO\n"),
|
||||||
(9..10, "six\n", "SIXTEEN\n"),
|
(9..10, "six\n", "SIXTEEN\n"),
|
||||||
|
|
|
@ -10,12 +10,12 @@ pub use git2::Repository as LibGitRepository;
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
pub trait GitRepository: Send {
|
pub trait GitRepository: Send {
|
||||||
fn load_head_text(&self, relative_file_path: &Path) -> Option<String>;
|
fn load_index(&self, relative_file_path: &Path) -> Option<String>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
impl GitRepository for LibGitRepository {
|
impl GitRepository for LibGitRepository {
|
||||||
fn load_head_text(&self, relative_file_path: &Path) -> Option<String> {
|
fn load_index(&self, relative_file_path: &Path) -> Option<String> {
|
||||||
fn logic(repo: &LibGitRepository, relative_file_path: &Path) -> Result<Option<String>> {
|
fn logic(repo: &LibGitRepository, relative_file_path: &Path) -> Result<Option<String>> {
|
||||||
const STAGE_NORMAL: i32 = 0;
|
const STAGE_NORMAL: i32 = 0;
|
||||||
let index = repo.index()?;
|
let index = repo.index()?;
|
||||||
|
@ -25,8 +25,7 @@ impl GitRepository for LibGitRepository {
|
||||||
};
|
};
|
||||||
|
|
||||||
let content = repo.find_blob(oid)?.content().to_owned();
|
let content = repo.find_blob(oid)?.content().to_owned();
|
||||||
let head_text = String::from_utf8(content)?;
|
Ok(Some(String::from_utf8(content)?))
|
||||||
Ok(Some(head_text))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
match logic(&self, relative_file_path) {
|
match logic(&self, relative_file_path) {
|
||||||
|
@ -55,7 +54,7 @@ impl FakeGitRepository {
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
impl GitRepository for FakeGitRepository {
|
impl GitRepository for FakeGitRepository {
|
||||||
fn load_head_text(&self, path: &Path) -> Option<String> {
|
fn load_index(&self, path: &Path) -> Option<String> {
|
||||||
let state = self.state.lock();
|
let state = self.state.lock();
|
||||||
state.index_contents.get(path).cloned()
|
state.index_contents.get(path).cloned()
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ struct GitDiffStatus {
|
||||||
|
|
||||||
pub struct Buffer {
|
pub struct Buffer {
|
||||||
text: TextBuffer,
|
text: TextBuffer,
|
||||||
head_text: Option<String>,
|
diff_base: Option<String>,
|
||||||
git_diff_status: GitDiffStatus,
|
git_diff_status: GitDiffStatus,
|
||||||
file: Option<Arc<dyn File>>,
|
file: Option<Arc<dyn File>>,
|
||||||
saved_version: clock::Global,
|
saved_version: clock::Global,
|
||||||
|
@ -346,13 +346,13 @@ impl Buffer {
|
||||||
pub fn from_file<T: Into<String>>(
|
pub fn from_file<T: Into<String>>(
|
||||||
replica_id: ReplicaId,
|
replica_id: ReplicaId,
|
||||||
base_text: T,
|
base_text: T,
|
||||||
head_text: Option<T>,
|
diff_base: Option<T>,
|
||||||
file: Arc<dyn File>,
|
file: Arc<dyn File>,
|
||||||
cx: &mut ModelContext<Self>,
|
cx: &mut ModelContext<Self>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self::build(
|
Self::build(
|
||||||
TextBuffer::new(replica_id, cx.model_id() as u64, base_text.into()),
|
TextBuffer::new(replica_id, cx.model_id() as u64, base_text.into()),
|
||||||
head_text.map(|h| h.into().into_boxed_str().into()),
|
diff_base.map(|h| h.into().into_boxed_str().into()),
|
||||||
Some(file),
|
Some(file),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -365,7 +365,7 @@ impl Buffer {
|
||||||
let buffer = TextBuffer::new(replica_id, message.id, message.base_text);
|
let buffer = TextBuffer::new(replica_id, message.id, message.base_text);
|
||||||
let mut this = Self::build(
|
let mut this = Self::build(
|
||||||
buffer,
|
buffer,
|
||||||
message.head_text.map(|text| text.into_boxed_str().into()),
|
message.diff_base.map(|text| text.into_boxed_str().into()),
|
||||||
file,
|
file,
|
||||||
);
|
);
|
||||||
this.text.set_line_ending(proto::deserialize_line_ending(
|
this.text.set_line_ending(proto::deserialize_line_ending(
|
||||||
|
@ -380,7 +380,7 @@ impl Buffer {
|
||||||
id: self.remote_id(),
|
id: self.remote_id(),
|
||||||
file: self.file.as_ref().map(|f| f.to_proto()),
|
file: self.file.as_ref().map(|f| f.to_proto()),
|
||||||
base_text: self.base_text().to_string(),
|
base_text: self.base_text().to_string(),
|
||||||
head_text: self.head_text.as_ref().map(|h| h.to_string()),
|
diff_base: self.diff_base.as_ref().map(|h| h.to_string()),
|
||||||
line_ending: proto::serialize_line_ending(self.line_ending()) as i32,
|
line_ending: proto::serialize_line_ending(self.line_ending()) as i32,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -423,7 +423,7 @@ impl Buffer {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build(buffer: TextBuffer, head_text: Option<String>, file: Option<Arc<dyn File>>) -> Self {
|
fn build(buffer: TextBuffer, diff_base: Option<String>, file: Option<Arc<dyn File>>) -> Self {
|
||||||
let saved_mtime = if let Some(file) = file.as_ref() {
|
let saved_mtime = if let Some(file) = file.as_ref() {
|
||||||
file.mtime()
|
file.mtime()
|
||||||
} else {
|
} else {
|
||||||
|
@ -437,7 +437,7 @@ impl Buffer {
|
||||||
transaction_depth: 0,
|
transaction_depth: 0,
|
||||||
was_dirty_before_starting_transaction: None,
|
was_dirty_before_starting_transaction: None,
|
||||||
text: buffer,
|
text: buffer,
|
||||||
head_text,
|
diff_base,
|
||||||
git_diff_status: GitDiffStatus {
|
git_diff_status: GitDiffStatus {
|
||||||
diff: git::diff::BufferDiff::new(),
|
diff: git::diff::BufferDiff::new(),
|
||||||
update_in_progress: false,
|
update_in_progress: false,
|
||||||
|
@ -663,12 +663,12 @@ impl Buffer {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(test, feature = "test-support"))]
|
#[cfg(any(test, feature = "test-support"))]
|
||||||
pub fn head_text(&self) -> Option<&str> {
|
pub fn diff_base(&self) -> Option<&str> {
|
||||||
self.head_text.as_deref()
|
self.diff_base.as_deref()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_head_text(&mut self, head_text: Option<String>, cx: &mut ModelContext<Self>) {
|
pub fn update_diff_base(&mut self, diff_base: Option<String>, cx: &mut ModelContext<Self>) {
|
||||||
self.head_text = head_text;
|
self.diff_base = diff_base;
|
||||||
self.git_diff_recalc(cx);
|
self.git_diff_recalc(cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -682,13 +682,13 @@ impl Buffer {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(head_text) = &self.head_text {
|
if let Some(diff_base) = &self.diff_base {
|
||||||
let snapshot = self.snapshot();
|
let snapshot = self.snapshot();
|
||||||
let head_text = head_text.clone();
|
let diff_base = diff_base.clone();
|
||||||
|
|
||||||
let mut diff = self.git_diff_status.diff.clone();
|
let mut diff = self.git_diff_status.diff.clone();
|
||||||
let diff = cx.background().spawn(async move {
|
let diff = cx.background().spawn(async move {
|
||||||
diff.update(&head_text, &snapshot).await;
|
diff.update(&diff_base, &snapshot).await;
|
||||||
diff
|
diff
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -490,11 +490,7 @@ impl FakeFs {
|
||||||
.boxed()
|
.boxed()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn set_head_state_for_git_repository(
|
pub async fn set_index_for_repo(&self, dot_git: &Path, head_state: &[(&Path, String)]) {
|
||||||
&self,
|
|
||||||
dot_git: &Path,
|
|
||||||
head_state: &[(&Path, String)],
|
|
||||||
) {
|
|
||||||
let content_path = dot_git.parent().unwrap();
|
let content_path = dot_git.parent().unwrap();
|
||||||
let mut state = self.state.lock().await;
|
let mut state = self.state.lock().await;
|
||||||
let entry = state.read_path(dot_git).await.unwrap();
|
let entry = state.read_path(dot_git).await.unwrap();
|
||||||
|
|
|
@ -424,7 +424,7 @@ impl Project {
|
||||||
client.add_model_request_handler(Self::handle_open_buffer_by_id);
|
client.add_model_request_handler(Self::handle_open_buffer_by_id);
|
||||||
client.add_model_request_handler(Self::handle_open_buffer_by_path);
|
client.add_model_request_handler(Self::handle_open_buffer_by_path);
|
||||||
client.add_model_request_handler(Self::handle_save_buffer);
|
client.add_model_request_handler(Self::handle_save_buffer);
|
||||||
client.add_model_message_handler(Self::handle_update_head_text);
|
client.add_model_message_handler(Self::handle_update_diff_base);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn local(
|
pub fn local(
|
||||||
|
@ -4675,22 +4675,22 @@ impl Project {
|
||||||
let client = self.client.clone();
|
let client = self.client.clone();
|
||||||
|
|
||||||
cx.spawn(|_, mut cx| async move {
|
cx.spawn(|_, mut cx| async move {
|
||||||
let head_text = cx
|
let diff_base = cx
|
||||||
.background()
|
.background()
|
||||||
.spawn(async move { repo.repo.lock().load_head_text(&path) })
|
.spawn(async move { repo.repo.lock().load_index(&path) })
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
let buffer_id = buffer.update(&mut cx, |buffer, cx| {
|
let buffer_id = buffer.update(&mut cx, |buffer, cx| {
|
||||||
buffer.update_head_text(head_text.clone(), cx);
|
buffer.update_diff_base(diff_base.clone(), cx);
|
||||||
buffer.remote_id()
|
buffer.remote_id()
|
||||||
});
|
});
|
||||||
|
|
||||||
if let Some(project_id) = shared_remote_id {
|
if let Some(project_id) = shared_remote_id {
|
||||||
client
|
client
|
||||||
.send(proto::UpdateHeadText {
|
.send(proto::UpdateDiffBase {
|
||||||
project_id,
|
project_id,
|
||||||
buffer_id: buffer_id as u64,
|
buffer_id: buffer_id as u64,
|
||||||
head_text,
|
diff_base,
|
||||||
})
|
})
|
||||||
.log_err();
|
.log_err();
|
||||||
}
|
}
|
||||||
|
@ -5272,22 +5272,22 @@ impl Project {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_update_head_text(
|
async fn handle_update_diff_base(
|
||||||
this: ModelHandle<Self>,
|
this: ModelHandle<Self>,
|
||||||
envelope: TypedEnvelope<proto::UpdateHeadText>,
|
envelope: TypedEnvelope<proto::UpdateDiffBase>,
|
||||||
_: Arc<Client>,
|
_: Arc<Client>,
|
||||||
mut cx: AsyncAppContext,
|
mut cx: AsyncAppContext,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
this.update(&mut cx, |this, cx| {
|
this.update(&mut cx, |this, cx| {
|
||||||
let buffer_id = envelope.payload.buffer_id;
|
let buffer_id = envelope.payload.buffer_id;
|
||||||
let head_text = envelope.payload.head_text;
|
let diff_base = envelope.payload.diff_base;
|
||||||
let buffer = this
|
let buffer = this
|
||||||
.opened_buffers
|
.opened_buffers
|
||||||
.get_mut(&buffer_id)
|
.get_mut(&buffer_id)
|
||||||
.and_then(|b| b.upgrade(cx))
|
.and_then(|b| b.upgrade(cx))
|
||||||
.ok_or_else(|| anyhow!("No such buffer {}", buffer_id))?;
|
.ok_or_else(|| anyhow!("No such buffer {}", buffer_id))?;
|
||||||
|
|
||||||
buffer.update(cx, |buffer, cx| buffer.update_head_text(head_text, cx));
|
buffer.update(cx, |buffer, cx| buffer.update_diff_base(diff_base, cx));
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
|
|
|
@ -481,11 +481,11 @@ impl LocalWorktree {
|
||||||
) -> Task<Result<ModelHandle<Buffer>>> {
|
) -> Task<Result<ModelHandle<Buffer>>> {
|
||||||
let path = Arc::from(path);
|
let path = Arc::from(path);
|
||||||
cx.spawn(move |this, mut cx| async move {
|
cx.spawn(move |this, mut cx| async move {
|
||||||
let (file, contents, head_text) = this
|
let (file, contents, diff_base) = this
|
||||||
.update(&mut cx, |t, cx| t.as_local().unwrap().load(&path, cx))
|
.update(&mut cx, |t, cx| t.as_local().unwrap().load(&path, cx))
|
||||||
.await?;
|
.await?;
|
||||||
Ok(cx.add_model(|cx| {
|
Ok(cx.add_model(|cx| {
|
||||||
let mut buffer = Buffer::from_file(0, contents, head_text, Arc::new(file), cx);
|
let mut buffer = Buffer::from_file(0, contents, diff_base, Arc::new(file), cx);
|
||||||
buffer.git_diff_recalc(cx);
|
buffer.git_diff_recalc(cx);
|
||||||
buffer
|
buffer
|
||||||
}))
|
}))
|
||||||
|
@ -673,13 +673,13 @@ impl LocalWorktree {
|
||||||
cx.spawn(|this, mut cx| async move {
|
cx.spawn(|this, mut cx| async move {
|
||||||
let text = fs.load(&abs_path).await?;
|
let text = fs.load(&abs_path).await?;
|
||||||
|
|
||||||
let head_text = match files_included {
|
let diff_base = match files_included {
|
||||||
settings::GitFilesIncluded::All | settings::GitFilesIncluded::OnlyTracked => {
|
settings::GitFilesIncluded::All | settings::GitFilesIncluded::OnlyTracked => {
|
||||||
let results = if let Some(repo) = snapshot.repo_for(&abs_path) {
|
let results = if let Some(repo) = snapshot.repo_for(&abs_path) {
|
||||||
cx.background()
|
cx.background()
|
||||||
.spawn({
|
.spawn({
|
||||||
let path = path.clone();
|
let path = path.clone();
|
||||||
async move { repo.repo.lock().load_head_text(&path) }
|
async move { repo.repo.lock().load_index(&path) }
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
} else {
|
} else {
|
||||||
|
@ -714,7 +714,7 @@ impl LocalWorktree {
|
||||||
is_local: true,
|
is_local: true,
|
||||||
},
|
},
|
||||||
text,
|
text,
|
||||||
head_text,
|
diff_base,
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,7 +110,7 @@ message Envelope {
|
||||||
Unfollow unfollow = 95;
|
Unfollow unfollow = 95;
|
||||||
GetPrivateUserInfo get_private_user_info = 96;
|
GetPrivateUserInfo get_private_user_info = 96;
|
||||||
GetPrivateUserInfoResponse get_private_user_info_response = 97;
|
GetPrivateUserInfoResponse get_private_user_info_response = 97;
|
||||||
UpdateHeadText update_head_text = 98;
|
UpdateDiffBase update_diff_base = 98;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -830,7 +830,7 @@ message BufferState {
|
||||||
uint64 id = 1;
|
uint64 id = 1;
|
||||||
optional File file = 2;
|
optional File file = 2;
|
||||||
string base_text = 3;
|
string base_text = 3;
|
||||||
optional string head_text = 4;
|
optional string diff_base = 4;
|
||||||
LineEnding line_ending = 5;
|
LineEnding line_ending = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1002,8 +1002,8 @@ message WorktreeMetadata {
|
||||||
bool visible = 3;
|
bool visible = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
message UpdateHeadText {
|
message UpdateDiffBase {
|
||||||
uint64 project_id = 1;
|
uint64 project_id = 1;
|
||||||
uint64 buffer_id = 2;
|
uint64 buffer_id = 2;
|
||||||
optional string head_text = 3;
|
optional string diff_base = 3;
|
||||||
}
|
}
|
||||||
|
|
|
@ -167,7 +167,7 @@ messages!(
|
||||||
(UpdateProject, Foreground),
|
(UpdateProject, Foreground),
|
||||||
(UpdateWorktree, Foreground),
|
(UpdateWorktree, Foreground),
|
||||||
(UpdateWorktreeExtensions, Background),
|
(UpdateWorktreeExtensions, Background),
|
||||||
(UpdateHeadText, Background),
|
(UpdateDiffBase, Background),
|
||||||
(GetPrivateUserInfo, Foreground),
|
(GetPrivateUserInfo, Foreground),
|
||||||
(GetPrivateUserInfoResponse, Foreground),
|
(GetPrivateUserInfoResponse, Foreground),
|
||||||
);
|
);
|
||||||
|
@ -267,7 +267,7 @@ entity_messages!(
|
||||||
UpdateProject,
|
UpdateProject,
|
||||||
UpdateWorktree,
|
UpdateWorktree,
|
||||||
UpdateWorktreeExtensions,
|
UpdateWorktreeExtensions,
|
||||||
UpdateHeadText
|
UpdateDiffBase
|
||||||
);
|
);
|
||||||
|
|
||||||
entity_messages!(channel_id, ChannelMessageSent);
|
entity_messages!(channel_id, ChannelMessageSent);
|
||||||
|
|
|
@ -55,11 +55,11 @@ impl FeatureFlags {
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Default, Deserialize, JsonSchema)]
|
#[derive(Copy, Clone, Debug, Default, Deserialize, JsonSchema)]
|
||||||
pub struct GitSettings {
|
pub struct GitSettings {
|
||||||
pub git_gutter: Option<GitGutterSettings>,
|
pub git_gutter: Option<GitGutter>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Default, Deserialize, JsonSchema)]
|
#[derive(Clone, Copy, Debug, Default, Deserialize, JsonSchema)]
|
||||||
pub struct GitGutterSettings {
|
pub struct GitGutter {
|
||||||
pub files_included: GitFilesIncluded,
|
pub files_included: GitFilesIncluded,
|
||||||
pub debounce_delay_millis: Option<u64>,
|
pub debounce_delay_millis: Option<u64>,
|
||||||
}
|
}
|
||||||
|
@ -406,7 +406,12 @@ impl Settings {
|
||||||
editor_overrides: Default::default(),
|
editor_overrides: Default::default(),
|
||||||
terminal_defaults: Default::default(),
|
terminal_defaults: Default::default(),
|
||||||
terminal_overrides: Default::default(),
|
terminal_overrides: Default::default(),
|
||||||
git: Default::default(),
|
git: GitSettings {
|
||||||
|
git_gutter: Some(GitGutter {
|
||||||
|
files_included: GitFilesIncluded::All,
|
||||||
|
debounce_delay_millis: None,
|
||||||
|
}),
|
||||||
|
},
|
||||||
language_defaults: Default::default(),
|
language_defaults: Default::default(),
|
||||||
language_overrides: Default::default(),
|
language_overrides: Default::default(),
|
||||||
lsp: Default::default(),
|
lsp: Default::default(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue