Use read-only access methods for read-only entity operations (#31479)

Another follow-up to #31254

Release Notes:

- N/A
This commit is contained in:
Joseph T. Lyons 2025-05-26 23:04:31 -04:00 committed by GitHub
parent 4a577fff4a
commit c208532693
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
79 changed files with 319 additions and 306 deletions

View file

@ -1340,7 +1340,7 @@ impl BufferStore {
mut cx: AsyncApp,
) -> Result<proto::BufferSaved> {
let buffer_id = BufferId::new(envelope.payload.buffer_id)?;
let (buffer, project_id) = this.update(&mut cx, |this, _| {
let (buffer, project_id) = this.read_with(&mut cx, |this, _| {
anyhow::Ok((
this.get_existing(buffer_id)?,
this.downstream_client
@ -1354,7 +1354,7 @@ impl BufferStore {
buffer.wait_for_version(deserialize_version(&envelope.payload.version))
})?
.await?;
let buffer_id = buffer.update(&mut cx, |buffer, _| buffer.remote_id())?;
let buffer_id = buffer.read_with(&mut cx, |buffer, _| buffer.remote_id())?;
if let Some(new_path) = envelope.payload.new_path {
let new_path = ProjectPath::from_proto(new_path);
@ -1367,7 +1367,7 @@ impl BufferStore {
.await?;
}
buffer.update(&mut cx, |buffer, _| proto::BufferSaved {
buffer.read_with(&mut cx, |buffer, _| proto::BufferSaved {
project_id,
buffer_id: buffer_id.into(),
version: serialize_version(buffer.saved_version()),
@ -1524,7 +1524,7 @@ impl BufferStore {
};
cx.spawn(async move |this, cx| {
let Some(buffer) = this.update(cx, |this, _| this.get(buffer_id))? else {
let Some(buffer) = this.read_with(cx, |this, _| this.get(buffer_id))? else {
return anyhow::Ok(());
};

View file

@ -267,7 +267,7 @@ impl BreakpointStore {
message: TypedEnvelope<proto::ToggleBreakpoint>,
mut cx: AsyncApp,
) -> Result<proto::Ack> {
let breakpoints = this.update(&mut cx, |this, _| this.breakpoint_store())?;
let breakpoints = this.read_with(&mut cx, |this, _| this.breakpoint_store())?;
let path = this
.update(&mut cx, |this, cx| {
this.project_path_for_absolute_path(message.payload.path.as_ref(), cx)
@ -803,7 +803,7 @@ impl BreakpointStore {
log::error!("Todo: Serialized breakpoints which do not have buffer (yet)");
continue;
};
let snapshot = buffer.update(cx, |buffer, _| buffer.snapshot())?;
let snapshot = buffer.read_with(cx, |buffer, _| buffer.snapshot())?;
let mut breakpoints_for_file =
this.update(cx, |_, cx| BreakpointsInFile::new(buffer, cx))?;

View file

@ -232,7 +232,7 @@ impl DapStore {
cx.spawn(async move |_, cx| {
let response = request.await?;
let binary = DebugAdapterBinary::from_proto(response)?;
let mut ssh_command = ssh_client.update(cx, |ssh, _| {
let mut ssh_command = ssh_client.read_with(cx, |ssh, _| {
anyhow::Ok(SshCommand {
arguments: ssh.ssh_args().context("SSH arguments not found")?,
})
@ -609,7 +609,7 @@ impl DapStore {
});
}
VariableLookupKind::Expression => {
let Ok(eval_task) = session.update(cx, |session, _| {
let Ok(eval_task) = session.read_with(cx, |session, _| {
session.mode.request_dap(EvaluateCommand {
expression: inline_value_location.variable_name.clone(),
frame_id: Some(stack_frame_id),
@ -752,7 +752,7 @@ impl DapStore {
let this = this.clone();
async move |cx| {
while let Some(message) = rx.next().await {
this.update(cx, |this, _| {
this.read_with(cx, |this, _| {
if let Some((downstream, project_id)) = this.downstream_client.clone() {
downstream
.send(proto::LogToDebugConsole {

View file

@ -407,7 +407,7 @@ impl LocalMode {
let configuration_sequence = cx.spawn({
async move |cx| {
let breakpoint_store =
dap_store.update(cx, |dap_store, _| dap_store.breakpoint_store().clone())?;
dap_store.read_with(cx, |dap_store, _| dap_store.breakpoint_store().clone())?;
initialized_rx.await?;
let errors_by_path = cx
.update(|cx| this.send_source_breakpoints(false, &breakpoint_store, cx))?

View file

@ -2179,7 +2179,7 @@ impl GitStore {
id: RepositoryId,
cx: &mut AsyncApp,
) -> Result<Entity<Repository>> {
this.update(cx, |this, _| {
this.read_with(cx, |this, _| {
this.repositories
.get(&id)
.context("missing repository handle")
@ -4022,7 +4022,7 @@ impl Repository {
bail!("not a local repository")
};
let (snapshot, events) = this
.update(&mut cx, |this, _| {
.read_with(&mut cx, |this, _| {
compute_snapshot(
this.id,
this.work_directory_abs_path.clone(),

View file

@ -504,7 +504,8 @@ mod tests {
events_tx.send(event.clone()).ok();
})
});
let conflicts_snapshot = conflict_set.update(cx, |conflict_set, _| conflict_set.snapshot());
let conflicts_snapshot =
conflict_set.read_with(cx, |conflict_set, _| conflict_set.snapshot());
assert!(conflicts_snapshot.conflicts.is_empty());
buffer.update(cx, |buffer, cx| {
@ -543,7 +544,7 @@ mod tests {
assert_eq!(update.old_range, 0..0);
assert_eq!(update.new_range, 0..1);
let conflict = conflict_set.update(cx, |conflict_set, _| {
let conflict = conflict_set.read_with(cx, |conflict_set, _| {
conflict_set.snapshot().conflicts[0].clone()
});
cx.update(|cx| {

View file

@ -313,7 +313,7 @@ impl LspCommand for PrepareRename {
_: LanguageServerId,
mut cx: AsyncApp,
) -> Result<PrepareRenameResponse> {
buffer.update(&mut cx, |buffer, _| match message {
buffer.read_with(&mut cx, |buffer, _| match message {
Some(lsp::PrepareRenameResponse::Range(range))
| Some(lsp::PrepareRenameResponse::RangeWithPlaceholder { range, .. }) => {
let Range { start, end } = range_from_lsp(range);
@ -365,7 +365,7 @@ impl LspCommand for PrepareRename {
.await?;
Ok(Self {
position: buffer.update(&mut cx, |buffer, _| position.to_point_utf16(buffer))?,
position: buffer.read_with(&mut cx, |buffer, _| position.to_point_utf16(buffer))?,
})
}
@ -513,7 +513,7 @@ impl LspCommand for PerformRename {
})?
.await?;
Ok(Self {
position: buffer.update(&mut cx, |buffer, _| position.to_point_utf16(buffer))?,
position: buffer.read_with(&mut cx, |buffer, _| position.to_point_utf16(buffer))?,
new_name: message.new_name,
push_to_history: false,
})
@ -625,7 +625,7 @@ impl LspCommand for GetDefinition {
})?
.await?;
Ok(Self {
position: buffer.update(&mut cx, |buffer, _| position.to_point_utf16(buffer))?,
position: buffer.read_with(&mut cx, |buffer, _| position.to_point_utf16(buffer))?,
})
}
@ -724,7 +724,7 @@ impl LspCommand for GetDeclaration {
})?
.await?;
Ok(Self {
position: buffer.update(&mut cx, |buffer, _| position.to_point_utf16(buffer))?,
position: buffer.read_with(&mut cx, |buffer, _| position.to_point_utf16(buffer))?,
})
}
@ -816,7 +816,7 @@ impl LspCommand for GetImplementation {
})?
.await?;
Ok(Self {
position: buffer.update(&mut cx, |buffer, _| position.to_point_utf16(buffer))?,
position: buffer.read_with(&mut cx, |buffer, _| position.to_point_utf16(buffer))?,
})
}
@ -915,7 +915,7 @@ impl LspCommand for GetTypeDefinition {
})?
.await?;
Ok(Self {
position: buffer.update(&mut cx, |buffer, _| position.to_point_utf16(buffer))?,
position: buffer.read_with(&mut cx, |buffer, _| position.to_point_utf16(buffer))?,
})
}
@ -1296,7 +1296,7 @@ impl LspCommand for GetReferences {
target_buffer_handle
.clone()
.update(&mut cx, |target_buffer, _| {
.read_with(&mut cx, |target_buffer, _| {
let target_start = target_buffer
.clip_point_utf16(point_from_lsp(lsp_location.range.start), Bias::Left);
let target_end = target_buffer
@ -1340,7 +1340,7 @@ impl LspCommand for GetReferences {
})?
.await?;
Ok(Self {
position: buffer.update(&mut cx, |buffer, _| position.to_point_utf16(buffer))?,
position: buffer.read_with(&mut cx, |buffer, _| position.to_point_utf16(buffer))?,
})
}
@ -1449,7 +1449,7 @@ impl LspCommand for GetDocumentHighlights {
_: LanguageServerId,
mut cx: AsyncApp,
) -> Result<Vec<DocumentHighlight>> {
buffer.update(&mut cx, |buffer, _| {
buffer.read_with(&mut cx, |buffer, _| {
let mut lsp_highlights = lsp_highlights.unwrap_or_default();
lsp_highlights.sort_unstable_by_key(|h| (h.range.start, Reverse(h.range.end)));
lsp_highlights
@ -1497,7 +1497,7 @@ impl LspCommand for GetDocumentHighlights {
})?
.await?;
Ok(Self {
position: buffer.update(&mut cx, |buffer, _| position.to_point_utf16(buffer))?,
position: buffer.read_with(&mut cx, |buffer, _| position.to_point_utf16(buffer))?,
})
}
@ -1822,7 +1822,7 @@ impl LspCommand for GetSignatureHelp {
})?
.await
.with_context(|| format!("waiting for version for buffer {}", buffer.entity_id()))?;
let buffer_snapshot = buffer.update(&mut cx, |buffer, _| buffer.snapshot())?;
let buffer_snapshot = buffer.read_with(&mut cx, |buffer, _| buffer.snapshot())?;
Ok(Self {
position: payload
.position
@ -1906,7 +1906,7 @@ impl LspCommand for GetHover {
return Ok(None);
};
let (language, range) = buffer.update(&mut cx, |buffer, _| {
let (language, range) = buffer.read_with(&mut cx, |buffer, _| {
(
buffer.language().cloned(),
hover.range.map(|range| {
@ -1992,7 +1992,7 @@ impl LspCommand for GetHover {
})?
.await?;
Ok(Self {
position: buffer.update(&mut cx, |buffer, _| position.to_point_utf16(buffer))?,
position: buffer.read_with(&mut cx, |buffer, _| position.to_point_utf16(buffer))?,
})
}
@ -2066,7 +2066,7 @@ impl LspCommand for GetHover {
return Ok(None);
}
let language = buffer.update(&mut cx, |buffer, _| buffer.language().cloned())?;
let language = buffer.read_with(&mut cx, |buffer, _| buffer.language().cloned())?;
let range = if let (Some(start), Some(end)) = (message.start, message.end) {
language::proto::deserialize_anchor(start)
.and_then(|start| language::proto::deserialize_anchor(end).map(|end| start..end))
@ -2141,7 +2141,7 @@ impl LspCommand for GetCompletions {
};
let language_server_adapter = lsp_store
.update(&mut cx, |lsp_store, _| {
.read_with(&mut cx, |lsp_store, _| {
lsp_store.language_server_adapter_for_id(server_id)
})?
.with_context(|| format!("no language server with id {server_id}"))?;
@ -2317,7 +2317,7 @@ impl LspCommand for GetCompletions {
.position
.and_then(language::proto::deserialize_anchor)
.map(|p| {
buffer.update(&mut cx, |buffer, _| {
buffer.read_with(&mut cx, |buffer, _| {
buffer.clip_point_utf16(Unclipped(p.to_point_utf16(buffer)), Bias::Left)
})
})
@ -2773,7 +2773,7 @@ impl LspCommand for OnTypeFormatting {
})?;
Ok(Self {
position: buffer.update(&mut cx, |buffer, _| position.to_point_utf16(buffer))?,
position: buffer.read_with(&mut cx, |buffer, _| position.to_point_utf16(buffer))?,
trigger: message.trigger.clone(),
options,
push_to_history: false,
@ -2826,7 +2826,7 @@ impl InlayHints {
_ => None,
});
let position = buffer_handle.update(cx, |buffer, _| {
let position = buffer_handle.read_with(cx, |buffer, _| {
let position = buffer.clip_point_utf16(point_from_lsp(lsp_hint.position), Bias::Left);
if kind == Some(InlayHintKind::Parameter) {
buffer.anchor_before(position)
@ -3387,7 +3387,7 @@ impl LspCommand for GetCodeLens {
server_id: LanguageServerId,
mut cx: AsyncApp,
) -> anyhow::Result<Vec<CodeAction>> {
let snapshot = buffer.update(&mut cx, |buffer, _| buffer.snapshot())?;
let snapshot = buffer.read_with(&mut cx, |buffer, _| buffer.snapshot())?;
let language_server = cx.update(|cx| {
lsp_store
.read(cx)

View file

@ -535,8 +535,8 @@ impl LocalLspStore {
let this = this.clone();
let mut cx = cx.clone();
async move {
let Some(server) =
this.update(&mut cx, |this, _| this.language_server_for_id(server_id))?
let Some(server) = this
.read_with(&mut cx, |this, _| this.language_server_for_id(server_id))?
else {
return Ok(None);
};
@ -600,7 +600,7 @@ impl LocalLspStore {
}
}
"textDocument/rangeFormatting" => {
this.update(&mut cx, |this, _| {
this.read_with(&mut cx, |this, _| {
if let Some(server) = this.language_server_for_id(server_id)
{
let options = reg
@ -626,7 +626,7 @@ impl LocalLspStore {
})??;
}
"textDocument/onTypeFormatting" => {
this.update(&mut cx, |this, _| {
this.read_with(&mut cx, |this, _| {
if let Some(server) = this.language_server_for_id(server_id)
{
let options = reg
@ -651,7 +651,7 @@ impl LocalLspStore {
})??;
}
"textDocument/formatting" => {
this.update(&mut cx, |this, _| {
this.read_with(&mut cx, |this, _| {
if let Some(server) = this.language_server_for_id(server_id)
{
let options = reg
@ -680,7 +680,7 @@ impl LocalLspStore {
// Ignore payload since we notify clients of setting changes unconditionally, relying on them pulling the latest settings.
}
"textDocument/rename" => {
this.update(&mut cx, |this, _| {
this.read_with(&mut cx, |this, _| {
if let Some(server) = this.language_server_for_id(server_id)
{
let options = reg
@ -734,7 +734,7 @@ impl LocalLspStore {
// Ignore payload since we notify clients of setting changes unconditionally, relying on them pulling the latest settings.
}
"textDocument/rename" => {
this.update(&mut cx, |this, _| {
this.read_with(&mut cx, |this, _| {
if let Some(server) = this.language_server_for_id(server_id)
{
server.update_capabilities(|capabilities| {
@ -744,7 +744,7 @@ impl LocalLspStore {
})?;
}
"textDocument/rangeFormatting" => {
this.update(&mut cx, |this, _| {
this.read_with(&mut cx, |this, _| {
if let Some(server) = this.language_server_for_id(server_id)
{
server.update_capabilities(|capabilities| {
@ -755,7 +755,7 @@ impl LocalLspStore {
})?;
}
"textDocument/onTypeFormatting" => {
this.update(&mut cx, |this, _| {
this.read_with(&mut cx, |this, _| {
if let Some(server) = this.language_server_for_id(server_id)
{
server.update_capabilities(|capabilities| {
@ -766,7 +766,7 @@ impl LocalLspStore {
})?;
}
"textDocument/formatting" => {
this.update(&mut cx, |this, _| {
this.read_with(&mut cx, |this, _| {
if let Some(server) = this.language_server_for_id(server_id)
{
server.update_capabilities(|capabilities| {
@ -1954,7 +1954,7 @@ impl LocalLspStore {
} else if matches!(range_formatting_provider, Some(p) if *p != OneOf::Left(false)) {
let _timer = zlog::time!(logger => "format-range");
let buffer_start = lsp::Position::new(0, 0);
let buffer_end = buffer.update(cx, |b, _| point_to_lsp(b.max_point_utf16()))?;
let buffer_end = buffer.read_with(cx, |b, _| point_to_lsp(b.max_point_utf16()))?;
language_server
.request::<lsp::request::RangeFormatting>(lsp::DocumentRangeFormattingParams {
text_document: text_document.clone(),
@ -2029,7 +2029,7 @@ impl LocalLspStore {
let stdin = child.stdin.as_mut().context("failed to acquire stdin")?;
let text = buffer
.handle
.update(cx, |buffer, _| buffer.as_rope().clone())?;
.read_with(cx, |buffer, _| buffer.as_rope().clone())?;
for chunk in text.chunks() {
stdin.write_all(chunk.as_bytes()).await?;
}
@ -3038,7 +3038,7 @@ impl LocalLspStore {
) -> Result<lsp::ApplyWorkspaceEditResponse> {
let this = this.upgrade().context("project project closed")?;
let language_server = this
.update(cx, |this, _| this.language_server_for_id(server_id))?
.read_with(cx, |this, _| this.language_server_for_id(server_id))?
.context("language server not found")?;
let transaction = Self::deserialize_workspace_edit(
this.clone(),
@ -3851,9 +3851,9 @@ impl LspStore {
}
fn on_buffer_added(&mut self, buffer: &Entity<Buffer>, cx: &mut Context<Self>) -> Result<()> {
buffer.update(cx, |buffer, _| {
buffer.set_language_registry(self.languages.clone())
});
buffer
.read(cx)
.set_language_registry(self.languages.clone());
cx.subscribe(buffer, |this, buffer, event, cx| {
this.on_buffer_event(buffer, event, cx);
@ -4691,7 +4691,9 @@ impl LspStore {
kind: kind.as_str().to_owned(),
buffer_ids: buffers
.iter()
.map(|buffer| buffer.update(cx, |buffer, _| buffer.remote_id().into()))
.map(|buffer| {
buffer.read_with(cx, |buffer, _| buffer.remote_id().into())
})
.collect::<Result<_>>()?,
})
.await
@ -6760,7 +6762,7 @@ impl LspStore {
})
})?
.await?;
if worktree.update(cx, |worktree, _| worktree.is_local())? {
if worktree.read_with(cx, |worktree, _| worktree.is_local())? {
lsp_store
.update(cx, |lsp_store, cx| {
lsp_store.register_local_language_server(
@ -6772,7 +6774,7 @@ impl LspStore {
})
.ok();
}
let worktree_root = worktree.update(cx, |worktree, _| worktree.abs_path())?;
let worktree_root = worktree.read_with(cx, |worktree, _| worktree.abs_path())?;
let relative_path = if let Some(known_path) = known_relative_path {
known_path
} else {
@ -6781,7 +6783,7 @@ impl LspStore {
(worktree, relative_path)
};
let project_path = ProjectPath {
worktree_id: worktree.update(cx, |worktree, _| worktree.id())?,
worktree_id: worktree.read_with(cx, |worktree, _| worktree.id())?,
path: relative_path,
};
lsp_store
@ -6897,7 +6899,7 @@ impl LspStore {
envelope: TypedEnvelope<proto::MultiLspQuery>,
mut cx: AsyncApp,
) -> Result<proto::MultiLspQueryResponse> {
let response_from_ssh = this.update(&mut cx, |this, _| {
let response_from_ssh = this.read_with(&mut cx, |this, _| {
let (upstream_client, project_id) = this.upstream_client()?;
let mut payload = envelope.payload.clone();
payload.project_id = project_id;
@ -6919,7 +6921,7 @@ impl LspStore {
buffer.wait_for_version(version.clone())
})?
.await?;
let buffer_version = buffer.update(&mut cx, |buffer, _| buffer.version())?;
let buffer_version = buffer.read_with(&mut cx, |buffer, _| buffer.version())?;
match envelope
.payload
.strategy
@ -7188,7 +7190,7 @@ impl LspStore {
})?
.context("worktree not found")?;
let (old_abs_path, new_abs_path) = {
let root_path = worktree.update(&mut cx, |this, _| this.abs_path())?;
let root_path = worktree.read_with(&mut cx, |this, _| this.abs_path())?;
let new_path = PathBuf::from_proto(envelope.payload.new_path.clone());
(root_path.join(&old_path), root_path.join(&new_path))
};
@ -7203,7 +7205,7 @@ impl LspStore {
)
.await;
let response = Worktree::handle_rename_entry(worktree, envelope.payload, cx.clone()).await;
this.update(&mut cx, |this, _| {
this.read_with(&mut cx, |this, _| {
this.did_rename_entry(worktree_id, &old_abs_path, &new_abs_path, is_dir);
})
.ok();
@ -7386,7 +7388,7 @@ impl LspStore {
mut cx: AsyncApp,
) -> Result<proto::Ack> {
let server_id = LanguageServerId(envelope.payload.language_server_id as usize);
lsp_store.update(&mut cx, |lsp_store, _| {
lsp_store.read_with(&mut cx, |lsp_store, _| {
if let Some(server) = lsp_store.language_server_for_id(server_id) {
server
.notify::<lsp_store::lsp_ext_command::LspExtCancelFlycheck>(&())
@ -7438,7 +7440,7 @@ impl LspStore {
mut cx: AsyncApp,
) -> Result<proto::Ack> {
let server_id = LanguageServerId(envelope.payload.language_server_id as usize);
lsp_store.update(&mut cx, |lsp_store, _| {
lsp_store.read_with(&mut cx, |lsp_store, _| {
if let Some(server) = lsp_store.language_server_for_id(server_id) {
server
.notify::<lsp_store::lsp_ext_command::LspExtClearFlycheck>(&())
@ -8097,7 +8099,7 @@ impl LspStore {
let peer_id = envelope.original_sender_id().unwrap_or_default();
let symbol = envelope.payload.symbol.context("invalid symbol")?;
let symbol = Self::deserialize_symbol(symbol)?;
let symbol = this.update(&mut cx, |this, _| {
let symbol = this.read_with(&mut cx, |this, _| {
let signature = this.symbol_signature(&symbol.path);
anyhow::ensure!(signature == symbol.signature, "invalid symbol signature");
Ok(symbol)
@ -8392,7 +8394,7 @@ impl LspStore {
trigger: trigger as i32,
buffer_ids: buffers
.iter()
.map(|buffer| buffer.update(cx, |buffer, _| buffer.remote_id().into()))
.map(|buffer| buffer.read_with(cx, |buffer, _| buffer.remote_id().into()))
.collect::<Result<_>>()?,
})
.await

View file

@ -117,7 +117,7 @@ impl LspCommand for ExpandMacro {
.and_then(deserialize_anchor)
.context("invalid position")?;
Ok(Self {
position: buffer.update(&mut cx, |buffer, _| position.to_point_utf16(buffer))?,
position: buffer.read_with(&mut cx, |buffer, _| position.to_point_utf16(buffer))?,
})
}
@ -247,7 +247,7 @@ impl LspCommand for OpenDocs {
.and_then(deserialize_anchor)
.context("invalid position")?;
Ok(Self {
position: buffer.update(&mut cx, |buffer, _| position.to_point_utf16(buffer))?,
position: buffer.read_with(&mut cx, |buffer, _| position.to_point_utf16(buffer))?,
})
}
@ -452,7 +452,7 @@ impl LspCommand for GoToParentModule {
.and_then(deserialize_anchor)
.context("bad request with bad position")?;
Ok(Self {
position: buffer.update(&mut cx, |buffer, _| position.to_point_utf16(buffer))?,
position: buffer.read_with(&mut cx, |buffer, _| position.to_point_utf16(buffer))?,
})
}

View file

@ -109,7 +109,7 @@ pub fn cancel_flycheck(
else {
return Ok(());
};
let buffer_id = buffer.update(cx, |buffer, _| buffer.remote_id().to_proto())?;
let buffer_id = buffer.read_with(cx, |buffer, _| buffer.remote_id().to_proto())?;
if let Some((client, project_id)) = upstream_client {
let request = proto::LspExtCancelFlycheck {
@ -123,7 +123,7 @@ pub fn cancel_flycheck(
.context("lsp ext cancel flycheck proto request")?;
} else {
lsp_store
.update(cx, |lsp_store, _| {
.read_with(cx, |lsp_store, _| {
if let Some(server) = lsp_store.language_server_for_id(rust_analyzer_server) {
server.notify::<lsp_store::lsp_ext_command::LspExtCancelFlycheck>(&())?;
}
@ -160,7 +160,7 @@ pub fn run_flycheck(
else {
return Ok(());
};
let buffer_id = buffer.update(cx, |buffer, _| buffer.remote_id().to_proto())?;
let buffer_id = buffer.read_with(cx, |buffer, _| buffer.remote_id().to_proto())?;
if let Some((client, project_id)) = upstream_client {
let request = proto::LspExtRunFlycheck {
@ -175,7 +175,7 @@ pub fn run_flycheck(
.context("lsp ext run flycheck proto request")?;
} else {
lsp_store
.update(cx, |lsp_store, _| {
.read_with(cx, |lsp_store, _| {
if let Some(server) = lsp_store.language_server_for_id(rust_analyzer_server) {
server.notify::<lsp_store::lsp_ext_command::LspExtRunFlycheck>(
&lsp_store::lsp_ext_command::RunFlycheckParams {
@ -216,7 +216,7 @@ pub fn clear_flycheck(
else {
return Ok(());
};
let buffer_id = buffer.update(cx, |buffer, _| buffer.remote_id().to_proto())?;
let buffer_id = buffer.read_with(cx, |buffer, _| buffer.remote_id().to_proto())?;
if let Some((client, project_id)) = upstream_client {
let request = proto::LspExtClearFlycheck {
@ -230,7 +230,7 @@ pub fn clear_flycheck(
.context("lsp ext clear flycheck proto request")?;
} else {
lsp_store
.update(cx, |lsp_store, _| {
.read_with(cx, |lsp_store, _| {
if let Some(server) = lsp_store.language_server_for_id(rust_analyzer_server) {
server.notify::<lsp_store::lsp_ext_command::LspExtClearFlycheck>(&())?;
}

View file

@ -133,7 +133,7 @@ impl ManifestTree {
};
let key = TriePath::from(&*path);
worktree_roots.update(cx, |this, _| {
worktree_roots.read_with(cx, |this, _| {
this.roots.walk(&key, &mut |path, labels| {
for (label, presence) in labels {
if let Some((marked_path, current_presence)) = roots.get_mut(label) {

View file

@ -279,7 +279,7 @@ impl PrettierStore {
) -> PrettierTask {
cx.spawn(async move |prettier_store, cx| {
log::info!("Starting prettier at path {prettier_dir:?}");
let new_server_id = prettier_store.update(cx, |prettier_store, _| {
let new_server_id = prettier_store.read_with(cx, |prettier_store, _| {
prettier_store.languages.next_language_server_id()
})?;
@ -306,7 +306,7 @@ impl PrettierStore {
cx: &mut Context<PrettierStore>,
) -> Task<anyhow::Result<PrettierTask>> {
cx.spawn(async move |prettier_store, cx| {
let installation_task = prettier_store.update(cx, |prettier_store, _| {
let installation_task = prettier_store.read_with(cx, |prettier_store, _| {
match &prettier_store.default_prettier.prettier {
PrettierInstallation::NotInstalled {
installation_task, ..
@ -407,7 +407,7 @@ impl PrettierStore {
.read(cx)
.worktree_for_id(id, cx)
})
.map(|worktree| worktree.update(cx, |worktree, _| worktree.abs_path()));
.map(|worktree| worktree.read(cx).abs_path());
let name = match worktree_path {
Some(worktree_path) => {
if prettier_dir == worktree_path.as_ref() {

View file

@ -1540,7 +1540,7 @@ impl Project {
.unwrap()
.await
.unwrap();
tree.update(cx, |tree, _| tree.as_local().unwrap().scan_complete())
tree.read_with(cx, |tree, _| tree.as_local().unwrap().scan_complete())
.unwrap()
.await;
}
@ -1579,7 +1579,7 @@ impl Project {
.await
.unwrap();
tree.update(cx, |tree, _| tree.as_local().unwrap().scan_complete())
tree.read_with(cx, |tree, _| tree.as_local().unwrap().scan_complete())
.await;
}
project
@ -1945,7 +1945,7 @@ impl Project {
let lsp_store = self.lsp_store().downgrade();
cx.spawn(async move |_, cx| {
let (old_abs_path, new_abs_path) = {
let root_path = worktree.update(cx, |this, _| this.abs_path())?;
let root_path = worktree.read_with(cx, |this, _| this.abs_path())?;
let new_abs_path = if is_root_entry {
root_path.parent().unwrap().join(&new_path)
} else {
@ -1970,7 +1970,7 @@ impl Project {
.await?;
lsp_store
.update(cx, |this, _| {
.read_with(cx, |this, _| {
this.did_rename_entry(worktree_id, &old_abs_path, &new_abs_path, is_dir);
})
.ok();
@ -2550,7 +2550,7 @@ impl Project {
cx: &mut AsyncApp,
) -> Result<()> {
for (buffer_id, operations) in operations_by_buffer_id.drain() {
let request = this.update(cx, |this, _| {
let request = this.read_with(cx, |this, _| {
let project_id = this.remote_id()?;
Some(this.client.request(proto::UpdateBuffer {
buffer_id: buffer_id.into(),
@ -2572,7 +2572,7 @@ impl Project {
let mut changes = rx.ready_chunks(MAX_BATCH_SIZE);
while let Some(changes) = changes.next().await {
let is_local = this.update(cx, |this, _| this.is_local())?;
let is_local = this.read_with(cx, |this, _| this.is_local())?;
for change in changes {
match change {
@ -2614,7 +2614,7 @@ impl Project {
)
.await?;
this.update(cx, |this, _| {
this.read_with(cx, |this, _| {
if let Some(project_id) = this.remote_id() {
this.client
.send(proto::UpdateLanguageServer {
@ -4007,7 +4007,7 @@ impl Project {
cx: &mut AsyncApp,
) -> Option<ResolvedPath> {
worktree
.update(cx, |worktree, _| {
.read_with(cx, |worktree, _| {
let root_entry_path = &worktree.root_entry()?.path;
let resolved = resolve_path(root_entry_path, path);
let stripped = resolved.strip_prefix(root_entry_path).unwrap_or(&resolved);

View file

@ -902,7 +902,7 @@ impl SettingsObserver {
let user_tasks_content = cx.background_executor().block(user_tasks_file_rx.next());
let weak_entry = cx.weak_entity();
cx.spawn(async move |settings_observer, cx| {
let Ok(task_store) = settings_observer.update(cx, |settings_observer, _| {
let Ok(task_store) = settings_observer.read_with(cx, |settings_observer, _| {
settings_observer.task_store.clone()
}) else {
return;

View file

@ -70,7 +70,7 @@ impl TaskStore {
.payload
.location
.context("no location given for task context handling")?;
let (buffer_store, is_remote) = store.update(&mut cx, |store, _| {
let (buffer_store, is_remote) = store.read_with(&mut cx, |store, _| {
Ok(match store {
TaskStore::Functional(state) => (
state.buffer_store.clone(),

View file

@ -367,7 +367,7 @@ impl WorktreeStore {
let handle_id = worktree.entity_id();
cx.subscribe(worktree, |_, worktree, event, cx| {
let worktree_id = worktree.update(cx, |worktree, _| worktree.id());
let worktree_id = worktree.read(cx).id();
match event {
worktree::Event::UpdatedEntries(changes) => {
cx.emit(WorktreeStoreEvent::WorktreeUpdatedEntries(

View file

@ -93,7 +93,7 @@ impl YarnPathStore {
let zip_file: Arc<Path> = Arc::from(zip_file);
cx.spawn(async move |this, cx| {
let dir = this
.update(cx, |this, _| {
.read_with(cx, |this, _| {
this.temp_dirs
.get(&zip_file)
.map(|temp| temp.path().to_owned())