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

@ -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)