Merge pull request #2402 from zed-industries/fix-panics

Fix panic in pane.rs
This commit is contained in:
Mikayla Maki 2023-04-22 05:53:48 +12:00 committed by Max Brunsfeld
parent 66776382b9
commit eeb3fd1cc9
5 changed files with 26 additions and 10 deletions

1
Cargo.lock generated
View file

@ -1358,7 +1358,6 @@ dependencies = [
"smol", "smol",
"theme", "theme",
"util", "util",
"workspace",
] ]
[[package]] [[package]]

View file

@ -47,4 +47,3 @@ lsp = { path = "../lsp", features = ["test-support"] }
rpc = { path = "../rpc", features = ["test-support"] } rpc = { path = "../rpc", features = ["test-support"] }
settings = { path = "../settings", features = ["test-support"] } settings = { path = "../settings", features = ["test-support"] }
util = { path = "../util", features = ["test-support"] } util = { path = "../util", features = ["test-support"] }
workspace = { path = "../workspace", features = ["test-support"] }

View file

@ -378,13 +378,6 @@ impl Copilot {
cx.clone(), cx.clone(),
)?; )?;
let server = server.initialize(Default::default()).await?;
let status = server
.request::<request::CheckStatus>(request::CheckStatusParams {
local_checks_only: false,
})
.await?;
server server
.on_notification::<LogMessage, _>(|params, _cx| { .on_notification::<LogMessage, _>(|params, _cx| {
match params.level { match params.level {
@ -405,6 +398,14 @@ impl Copilot {
) )
.detach(); .detach();
let server = server.initialize(Default::default()).await?;
let status = server
.request::<request::CheckStatus>(request::CheckStatusParams {
local_checks_only: false,
})
.await?;
server server
.request::<request::SetEditorInfo>(request::SetEditorInfoParams { .request::<request::SetEditorInfo>(request::SetEditorInfoParams {
editor_info: request::EditorInfo { editor_info: request::EditorInfo {

View file

@ -143,8 +143,8 @@ pub enum LogMessage {}
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct LogMessageParams { pub struct LogMessageParams {
pub message: String,
pub level: u8, pub level: u8,
pub message: String,
pub metadata_str: String, pub metadata_str: String,
pub extra: Vec<String>, pub extra: Vec<String>,
} }

View file

@ -785,6 +785,10 @@ impl Pane {
) -> Option<Task<Result<()>>> { ) -> Option<Task<Result<()>>> {
let pane_handle = workspace.active_pane().clone(); let pane_handle = workspace.active_pane().clone();
let pane = pane_handle.read(cx); let pane = pane_handle.read(cx);
if pane.items.is_empty() {
return None;
}
let active_item_id = pane.items[pane.active_item_index].id(); let active_item_id = pane.items[pane.active_item_index].id();
let task = Self::close_item_by_id(workspace, pane_handle, active_item_id, cx); let task = Self::close_item_by_id(workspace, pane_handle, active_item_id, cx);
@ -2098,6 +2102,19 @@ mod tests {
use gpui::{executor::Deterministic, TestAppContext}; use gpui::{executor::Deterministic, TestAppContext};
use project::FakeFs; use project::FakeFs;
#[gpui::test]
async fn test_remove_active_empty(cx: &mut TestAppContext) {
Settings::test_async(cx);
let fs = FakeFs::new(cx.background());
let project = Project::test(fs, None, cx).await;
let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
workspace.update(cx, |workspace, cx| {
assert!(Pane::close_active_item(workspace, &CloseActiveItem, cx).is_none())
});
}
#[gpui::test] #[gpui::test]
async fn test_add_item_with_new_item(cx: &mut TestAppContext) { async fn test_add_item_with_new_item(cx: &mut TestAppContext) {
cx.foreground().forbid_parking(); cx.foreground().forbid_parking();