Avoid panicking when receiving a request for a dropped buffer

This commit is contained in:
Antonio Scandurra 2022-04-08 12:10:45 +02:00
parent 3daaef02ca
commit 663beab1b9

View file

@ -3850,7 +3850,7 @@ impl Project {
let buffer = this
.opened_buffers
.get(&buffer_id)
.map(|buffer| buffer.upgrade(cx).unwrap())
.and_then(|buffer| buffer.upgrade(cx))
.ok_or_else(|| anyhow!("unknown buffer id {}", buffer_id))?;
Ok::<_, anyhow::Error>((project_id, buffer))
})?;
@ -3882,7 +3882,7 @@ impl Project {
buffers.insert(
this.opened_buffers
.get(buffer_id)
.map(|buffer| buffer.upgrade(cx).unwrap())
.and_then(|buffer| buffer.upgrade(cx))
.ok_or_else(|| anyhow!("unknown buffer id {}", buffer_id))?,
);
}
@ -3911,7 +3911,7 @@ impl Project {
buffers.insert(
this.opened_buffers
.get(buffer_id)
.map(|buffer| buffer.upgrade(cx).unwrap())
.and_then(|buffer| buffer.upgrade(cx))
.ok_or_else(|| anyhow!("unknown buffer id {}", buffer_id))?,
);
}
@ -3942,7 +3942,7 @@ impl Project {
let buffer = this.read_with(&cx, |this, cx| {
this.opened_buffers
.get(&envelope.payload.buffer_id)
.map(|buffer| buffer.upgrade(cx).unwrap())
.and_then(|buffer| buffer.upgrade(cx))
.ok_or_else(|| anyhow!("unknown buffer id {}", envelope.payload.buffer_id))
})?;
buffer
@ -3972,7 +3972,7 @@ impl Project {
let buffer = this
.opened_buffers
.get(&envelope.payload.buffer_id)
.map(|buffer| buffer.upgrade(cx).unwrap())
.and_then(|buffer| buffer.upgrade(cx))
.ok_or_else(|| anyhow!("unknown buffer id {}", envelope.payload.buffer_id))?;
let language = buffer.read(cx).language();
let completion = language::proto::deserialize_completion(
@ -4014,7 +4014,7 @@ impl Project {
let buffer = this.update(&mut cx, |this, cx| {
this.opened_buffers
.get(&envelope.payload.buffer_id)
.map(|buffer| buffer.upgrade(cx).unwrap())
.and_then(|buffer| buffer.upgrade(cx))
.ok_or_else(|| anyhow!("unknown buffer id {}", envelope.payload.buffer_id))
})?;
buffer
@ -4055,7 +4055,7 @@ impl Project {
let buffer = this
.opened_buffers
.get(&envelope.payload.buffer_id)
.map(|buffer| buffer.upgrade(cx).unwrap())
.and_then(|buffer| buffer.upgrade(cx))
.ok_or_else(|| anyhow!("unknown buffer id {}", envelope.payload.buffer_id))?;
Ok::<_, anyhow::Error>(this.apply_code_action(buffer, action, false, cx))
})?;