Rename open_buffer_for_path to open_buffer

This commit is contained in:
Antonio Scandurra 2022-03-17 11:42:13 +01:00
parent e6755f4115
commit 6446660c88
5 changed files with 64 additions and 143 deletions

View File

@ -155,9 +155,7 @@ impl ProjectDiagnosticsEditor {
async move {
for path in paths {
let buffer = project
.update(&mut cx, |project, cx| {
project.open_buffer_for_path(path.clone(), cx)
})
.update(&mut cx, |project, cx| project.open_buffer(path.clone(), cx))
.await?;
this.update(&mut cx, |view, cx| view.populate_excerpts(path, buffer, cx))
}

View File

@ -8439,9 +8439,7 @@ mod tests {
.0
.read_with(cx, |tree, _| tree.id());
let buffer = project
.update(cx, |project, cx| {
project.open_buffer_for_path((worktree_id, ""), cx)
})
.update(cx, |project, cx| project.open_buffer((worktree_id, ""), cx))
.await
.unwrap();
let mut fake_server = fake_servers.next().await.unwrap();

View File

@ -818,19 +818,7 @@ impl Project {
Ok(buffer)
}
pub fn open_buffer_for_entry(
&mut self,
entry_id: ProjectEntryId,
cx: &mut ModelContext<Self>,
) -> Task<Result<ModelHandle<Buffer>>> {
if let Some(project_path) = self.path_for_entry(entry_id, cx) {
self.open_buffer_for_path(project_path, cx)
} else {
Task::ready(Err(anyhow!("entry not found")))
}
}
pub fn open_buffer_for_path(
pub fn open_buffer(
&mut self,
path: impl Into<ProjectPath>,
cx: &mut ModelContext<Self>,
@ -965,10 +953,8 @@ impl Project {
worktree_id: worktree.read_with(&cx, |worktree, _| worktree.id()),
path: relative_path.into(),
};
this.update(&mut cx, |this, cx| {
this.open_buffer_for_path(project_path, cx)
})
.await
this.update(&mut cx, |this, cx| this.open_buffer(project_path, cx))
.await
})
}
@ -2868,9 +2854,7 @@ impl Project {
let buffers_tx = buffers_tx.clone();
cx.spawn(|mut cx| async move {
if let Some(buffer) = this
.update(&mut cx, |this, cx| {
this.open_buffer_for_path(project_path, cx)
})
.update(&mut cx, |this, cx| this.open_buffer(project_path, cx))
.await
.log_err()
{
@ -3891,7 +3875,7 @@ impl Project {
let peer_id = envelope.original_sender_id()?;
let worktree_id = WorktreeId::from_proto(envelope.payload.worktree_id);
let open_buffer = this.update(&mut cx, |this, cx| {
this.open_buffer_for_path(
this.open_buffer(
ProjectPath {
worktree_id,
path: PathBuf::from(envelope.payload.path).into(),
@ -4688,7 +4672,7 @@ mod tests {
// Open a buffer without an associated language server.
let toml_buffer = project
.update(cx, |project, cx| {
project.open_buffer_for_path((worktree_id, "Cargo.toml"), cx)
project.open_buffer((worktree_id, "Cargo.toml"), cx)
})
.await
.unwrap();
@ -4696,7 +4680,7 @@ mod tests {
// Open a buffer with an associated language server.
let rust_buffer = project
.update(cx, |project, cx| {
project.open_buffer_for_path((worktree_id, "test.rs"), cx)
project.open_buffer((worktree_id, "test.rs"), cx)
})
.await
.unwrap();
@ -4743,7 +4727,7 @@ mod tests {
// Open a third buffer with a different associated language server.
let json_buffer = project
.update(cx, |project, cx| {
project.open_buffer_for_path((worktree_id, "package.json"), cx)
project.open_buffer((worktree_id, "package.json"), cx)
})
.await
.unwrap();
@ -4774,7 +4758,7 @@ mod tests {
// it is also configured based on the existing language server's capabilities.
let rust_buffer2 = project
.update(cx, |project, cx| {
project.open_buffer_for_path((worktree_id, "test2.rs"), cx)
project.open_buffer((worktree_id, "test2.rs"), cx)
})
.await
.unwrap();
@ -4885,7 +4869,7 @@ mod tests {
// Cause worktree to start the fake language server
let _buffer = project
.update(cx, |project, cx| {
project.open_buffer_for_path((worktree_id, Path::new("b.rs")), cx)
project.open_buffer((worktree_id, Path::new("b.rs")), cx)
})
.await
.unwrap();
@ -4932,9 +4916,7 @@ mod tests {
);
let buffer = project
.update(cx, |p, cx| {
p.open_buffer_for_path((worktree_id, "a.rs"), cx)
})
.update(cx, |p, cx| p.open_buffer((worktree_id, "a.rs"), cx))
.await
.unwrap();
@ -5001,7 +4983,7 @@ mod tests {
let buffer = project
.update(cx, |project, cx| {
project.open_buffer_for_path((worktree_id, "a.rs"), cx)
project.open_buffer((worktree_id, "a.rs"), cx)
})
.await
.unwrap();
@ -5277,7 +5259,7 @@ mod tests {
let buffer = project
.update(cx, |project, cx| {
project.open_buffer_for_path((worktree_id, "a.rs"), cx)
project.open_buffer((worktree_id, "a.rs"), cx)
})
.await
.unwrap();
@ -5382,7 +5364,7 @@ mod tests {
let buffer = project
.update(cx, |project, cx| {
project.open_buffer_for_path((worktree_id, "a.rs"), cx)
project.open_buffer((worktree_id, "a.rs"), cx)
})
.await
.unwrap();
@ -5540,7 +5522,7 @@ mod tests {
let buffer = project
.update(cx, |project, cx| {
project.open_buffer_for_path((worktree_id, "a.rs"), cx)
project.open_buffer((worktree_id, "a.rs"), cx)
})
.await
.unwrap();
@ -5723,7 +5705,7 @@ mod tests {
let buffer = project
.update(cx, |project, cx| {
project.open_buffer_for_path(
project.open_buffer(
ProjectPath {
worktree_id,
path: Path::new("").into(),
@ -5819,9 +5801,7 @@ mod tests {
.read_with(cx, |tree, _| tree.id());
let buffer = project
.update(cx, |p, cx| {
p.open_buffer_for_path((worktree_id, "file1"), cx)
})
.update(cx, |p, cx| p.open_buffer((worktree_id, "file1"), cx))
.await
.unwrap();
buffer
@ -5859,7 +5839,7 @@ mod tests {
.read_with(cx, |tree, _| tree.id());
let buffer = project
.update(cx, |p, cx| p.open_buffer_for_path((worktree_id, ""), cx))
.update(cx, |p, cx| p.open_buffer((worktree_id, ""), cx))
.await
.unwrap();
buffer
@ -5909,7 +5889,7 @@ mod tests {
let opened_buffer = project
.update(cx, |project, cx| {
project.open_buffer_for_path((worktree_id, "file1"), cx)
project.open_buffer((worktree_id, "file1"), cx)
})
.await
.unwrap();
@ -5944,8 +5924,7 @@ mod tests {
let worktree_id = tree.read_with(cx, |tree, _| tree.id());
let buffer_for_path = |path: &'static str, cx: &mut gpui::TestAppContext| {
let buffer =
project.update(cx, |p, cx| p.open_buffer_for_path((worktree_id, path), cx));
let buffer = project.update(cx, |p, cx| p.open_buffer((worktree_id, path), cx));
async move { buffer.await.unwrap() }
};
let id_for_path = |path: &'static str, cx: &gpui::TestAppContext| {
@ -6094,9 +6073,9 @@ mod tests {
// Spawn multiple tasks to open paths, repeating some paths.
let (buffer_a_1, buffer_b, buffer_a_2) = project.update(cx, |p, cx| {
(
p.open_buffer_for_path((worktree_id, "a.txt"), cx),
p.open_buffer_for_path((worktree_id, "b.txt"), cx),
p.open_buffer_for_path((worktree_id, "a.txt"), cx),
p.open_buffer((worktree_id, "a.txt"), cx),
p.open_buffer((worktree_id, "b.txt"), cx),
p.open_buffer((worktree_id, "a.txt"), cx),
)
});
@ -6113,9 +6092,7 @@ mod tests {
// Open the same path again while it is still open.
drop(buffer_a_1);
let buffer_a_3 = project
.update(cx, |p, cx| {
p.open_buffer_for_path((worktree_id, "a.txt"), cx)
})
.update(cx, |p, cx| p.open_buffer((worktree_id, "a.txt"), cx))
.await
.unwrap();
@ -6148,9 +6125,7 @@ mod tests {
.await;
let buffer1 = project
.update(cx, |p, cx| {
p.open_buffer_for_path((worktree_id, "file1"), cx)
})
.update(cx, |p, cx| p.open_buffer((worktree_id, "file1"), cx))
.await
.unwrap();
let events = Rc::new(RefCell::new(Vec::new()));
@ -6220,9 +6195,7 @@ mod tests {
// When a file is deleted, the buffer is considered dirty.
let events = Rc::new(RefCell::new(Vec::new()));
let buffer2 = project
.update(cx, |p, cx| {
p.open_buffer_for_path((worktree_id, "file2"), cx)
})
.update(cx, |p, cx| p.open_buffer((worktree_id, "file2"), cx))
.await
.unwrap();
buffer2.update(cx, |_, cx| {
@ -6243,9 +6216,7 @@ mod tests {
// When a file is already dirty when deleted, we don't emit a Dirtied event.
let events = Rc::new(RefCell::new(Vec::new()));
let buffer3 = project
.update(cx, |p, cx| {
p.open_buffer_for_path((worktree_id, "file3"), cx)
})
.update(cx, |p, cx| p.open_buffer((worktree_id, "file3"), cx))
.await
.unwrap();
buffer3.update(cx, |_, cx| {
@ -6291,9 +6262,7 @@ mod tests {
let abs_path = dir.path().join("the-file");
let buffer = project
.update(cx, |p, cx| {
p.open_buffer_for_path((worktree_id, "the-file"), cx)
})
.update(cx, |p, cx| p.open_buffer((worktree_id, "the-file"), cx))
.await
.unwrap();
@ -6399,9 +6368,7 @@ mod tests {
let worktree_id = worktree.read_with(cx, |tree, _| tree.id());
let buffer = project
.update(cx, |p, cx| {
p.open_buffer_for_path((worktree_id, "a.rs"), cx)
})
.update(cx, |p, cx| p.open_buffer((worktree_id, "a.rs"), cx))
.await
.unwrap();
@ -6674,7 +6641,7 @@ mod tests {
let buffer = project
.update(cx, |project, cx| {
project.open_buffer_for_path((worktree_id, Path::new("one.rs")), cx)
project.open_buffer((worktree_id, Path::new("one.rs")), cx)
})
.await
.unwrap();
@ -6812,7 +6779,7 @@ mod tests {
let buffer_4 = project
.update(cx, |project, cx| {
project.open_buffer_for_path((worktree_id, "four.rs"), cx)
project.open_buffer((worktree_id, "four.rs"), cx)
})
.await
.unwrap();

View File

@ -1137,9 +1137,7 @@ mod tests {
// Open the same file as client B and client A.
let buffer_b = project_b
.update(cx_b, |p, cx| {
p.open_buffer_for_path((worktree_id, "b.txt"), cx)
})
.update(cx_b, |p, cx| p.open_buffer((worktree_id, "b.txt"), cx))
.await
.unwrap();
let buffer_b = cx_b.add_model(|cx| MultiBuffer::singleton(buffer_b, cx));
@ -1150,9 +1148,7 @@ mod tests {
assert!(project.has_open_buffer((worktree_id, "b.txt"), cx))
});
let buffer_a = project_a
.update(cx_a, |p, cx| {
p.open_buffer_for_path((worktree_id, "b.txt"), cx)
})
.update(cx_a, |p, cx| p.open_buffer((worktree_id, "b.txt"), cx))
.await
.unwrap();
@ -1242,9 +1238,7 @@ mod tests {
.await
.unwrap();
project_b
.update(cx_b, |p, cx| {
p.open_buffer_for_path((worktree_id, "a.txt"), cx)
})
.update(cx_b, |p, cx| p.open_buffer((worktree_id, "a.txt"), cx))
.await
.unwrap();
@ -1279,9 +1273,7 @@ mod tests {
.await
.unwrap();
project_b2
.update(cx_b, |p, cx| {
p.open_buffer_for_path((worktree_id, "a.txt"), cx)
})
.update(cx_b, |p, cx| p.open_buffer((worktree_id, "a.txt"), cx))
.await
.unwrap();
}
@ -1360,15 +1352,11 @@ mod tests {
// Open and edit a buffer as both guests B and C.
let buffer_b = project_b
.update(cx_b, |p, cx| {
p.open_buffer_for_path((worktree_id, "file1"), cx)
})
.update(cx_b, |p, cx| p.open_buffer((worktree_id, "file1"), cx))
.await
.unwrap();
let buffer_c = project_c
.update(cx_c, |p, cx| {
p.open_buffer_for_path((worktree_id, "file1"), cx)
})
.update(cx_c, |p, cx| p.open_buffer((worktree_id, "file1"), cx))
.await
.unwrap();
buffer_b.update(cx_b, |buf, cx| buf.edit([0..0], "i-am-b, ", cx));
@ -1376,9 +1364,7 @@ mod tests {
// Open and edit that buffer as the host.
let buffer_a = project_a
.update(cx_a, |p, cx| {
p.open_buffer_for_path((worktree_id, "file1"), cx)
})
.update(cx_a, |p, cx| p.open_buffer((worktree_id, "file1"), cx))
.await
.unwrap();
@ -1528,9 +1514,7 @@ mod tests {
// Open a buffer as client B
let buffer_b = project_b
.update(cx_b, |p, cx| {
p.open_buffer_for_path((worktree_id, "a.txt"), cx)
})
.update(cx_b, |p, cx| p.open_buffer((worktree_id, "a.txt"), cx))
.await
.unwrap();
@ -1613,9 +1597,7 @@ mod tests {
// Open a buffer as client B
let buffer_b = project_b
.update(cx_b, |p, cx| {
p.open_buffer_for_path((worktree_id, "a.txt"), cx)
})
.update(cx_b, |p, cx| p.open_buffer((worktree_id, "a.txt"), cx))
.await
.unwrap();
buffer_b.read_with(cx_b, |buf, _| {
@ -1695,16 +1677,14 @@ mod tests {
// Open a buffer as client A
let buffer_a = project_a
.update(cx_a, |p, cx| {
p.open_buffer_for_path((worktree_id, "a.txt"), cx)
})
.update(cx_a, |p, cx| p.open_buffer((worktree_id, "a.txt"), cx))
.await
.unwrap();
// Start opening the same buffer as client B
let buffer_b = cx_b.background().spawn(project_b.update(cx_b, |p, cx| {
p.open_buffer_for_path((worktree_id, "a.txt"), cx)
}));
let buffer_b = cx_b
.background()
.spawn(project_b.update(cx_b, |p, cx| p.open_buffer((worktree_id, "a.txt"), cx)));
// Edit the buffer as client A while client B is still opening it.
cx_b.background().simulate_random_delay().await;
@ -1780,9 +1760,9 @@ mod tests {
.await;
// Begin opening a buffer as client B, but leave the project before the open completes.
let buffer_b = cx_b.background().spawn(project_b.update(cx_b, |p, cx| {
p.open_buffer_for_path((worktree_id, "a.txt"), cx)
}));
let buffer_b = cx_b
.background()
.spawn(project_b.update(cx_b, |p, cx| p.open_buffer((worktree_id, "a.txt"), cx)));
cx_b.update(|_| drop(project_b));
drop(buffer_b);
@ -1952,7 +1932,7 @@ mod tests {
let _ = cx_a
.background()
.spawn(project_a.update(cx_a, |project, cx| {
project.open_buffer_for_path(
project.open_buffer(
ProjectPath {
worktree_id,
path: Path::new("other.rs").into(),
@ -2073,9 +2053,7 @@ mod tests {
// Open the file with the errors on client B. They should be present.
let buffer_b = cx_b
.background()
.spawn(project_b.update(cx_b, |p, cx| {
p.open_buffer_for_path((worktree_id, "a.rs"), cx)
}))
.spawn(project_b.update(cx_b, |p, cx| p.open_buffer((worktree_id, "a.rs"), cx)))
.await
.unwrap();
@ -2193,9 +2171,7 @@ mod tests {
// Open a file in an editor as the guest.
let buffer_b = project_b
.update(cx_b, |p, cx| {
p.open_buffer_for_path((worktree_id, "main.rs"), cx)
})
.update(cx_b, |p, cx| p.open_buffer((worktree_id, "main.rs"), cx))
.await
.unwrap();
let (window_b, _) = cx_b.add_window(|_| EmptyView);
@ -2269,9 +2245,7 @@ mod tests {
// Open the buffer on the host.
let buffer_a = project_a
.update(cx_a, |p, cx| {
p.open_buffer_for_path((worktree_id, "main.rs"), cx)
})
.update(cx_a, |p, cx| p.open_buffer((worktree_id, "main.rs"), cx))
.await
.unwrap();
buffer_a
@ -2395,9 +2369,7 @@ mod tests {
let buffer_b = cx_b
.background()
.spawn(project_b.update(cx_b, |p, cx| {
p.open_buffer_for_path((worktree_id, "a.rs"), cx)
}))
.spawn(project_b.update(cx_b, |p, cx| p.open_buffer((worktree_id, "a.rs"), cx)))
.await
.unwrap();
@ -2505,9 +2477,7 @@ mod tests {
// Open the file on client B.
let buffer_b = cx_b
.background()
.spawn(project_b.update(cx_b, |p, cx| {
p.open_buffer_for_path((worktree_id, "a.rs"), cx)
}))
.spawn(project_b.update(cx_b, |p, cx| p.open_buffer((worktree_id, "a.rs"), cx)))
.await
.unwrap();
@ -2646,9 +2616,7 @@ mod tests {
// Open the file on client B.
let buffer_b = cx_b
.background()
.spawn(project_b.update(cx_b, |p, cx| {
p.open_buffer_for_path((worktree_id, "one.rs"), cx)
}))
.spawn(project_b.update(cx_b, |p, cx| p.open_buffer((worktree_id, "one.rs"), cx)))
.await
.unwrap();
@ -2877,9 +2845,7 @@ mod tests {
// Open the file on client B.
let buffer_b = cx_b
.background()
.spawn(project_b.update(cx_b, |p, cx| {
p.open_buffer_for_path((worktree_id, "main.rs"), cx)
}))
.spawn(project_b.update(cx_b, |p, cx| p.open_buffer((worktree_id, "main.rs"), cx)))
.await
.unwrap();
@ -3026,9 +2992,7 @@ mod tests {
// Cause the language server to start.
let _buffer = cx_b
.background()
.spawn(project_b.update(cx_b, |p, cx| {
p.open_buffer_for_path((worktree_id, "one.rs"), cx)
}))
.spawn(project_b.update(cx_b, |p, cx| p.open_buffer((worktree_id, "one.rs"), cx)))
.await
.unwrap();
@ -3159,9 +3123,7 @@ mod tests {
let buffer_b1 = cx_b
.background()
.spawn(project_b.update(cx_b, |p, cx| {
p.open_buffer_for_path((worktree_id, "a.rs"), cx)
}))
.spawn(project_b.update(cx_b, |p, cx| p.open_buffer((worktree_id, "a.rs"), cx)))
.await
.unwrap();
@ -3177,13 +3139,9 @@ mod tests {
let buffer_b2;
if rng.gen() {
definitions = project_b.update(cx_b, |p, cx| p.definition(&buffer_b1, 23, cx));
buffer_b2 = project_b.update(cx_b, |p, cx| {
p.open_buffer_for_path((worktree_id, "b.rs"), cx)
});
buffer_b2 = project_b.update(cx_b, |p, cx| p.open_buffer((worktree_id, "b.rs"), cx));
} else {
buffer_b2 = project_b.update(cx_b, |p, cx| {
p.open_buffer_for_path((worktree_id, "b.rs"), cx)
});
buffer_b2 = project_b.update(cx_b, |p, cx| p.open_buffer((worktree_id, "b.rs"), cx));
definitions = project_b.update(cx_b, |p, cx| p.definition(&buffer_b1, 23, cx));
}
@ -4800,7 +4758,7 @@ mod tests {
);
let buffer = project
.update(&mut cx, |project, cx| {
project.open_buffer_for_path(project_path, cx)
project.open_buffer(project_path, cx)
})
.await
.unwrap();
@ -4917,7 +4875,7 @@ mod tests {
);
let buffer = project
.update(&mut cx, |project, cx| {
project.open_buffer_for_path(project_path.clone(), cx)
project.open_buffer(project_path.clone(), cx)
})
.await
.unwrap();

View File

@ -816,7 +816,7 @@ impl Workspace {
)>,
> {
let project = self.project().clone();
let buffer = project.update(cx, |project, cx| project.open_buffer_for_path(path, cx));
let buffer = project.update(cx, |project, cx| project.open_buffer(path, cx));
cx.spawn(|this, mut cx| async move {
let buffer = buffer.await?;
let project_entry_id = buffer.read_with(&cx, |buffer, cx| {