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:
parent
4a577fff4a
commit
c208532693
79 changed files with 319 additions and 306 deletions
|
@ -39,12 +39,12 @@ pub fn switch_source_header(
|
|||
else {
|
||||
return Ok(());
|
||||
};
|
||||
let source_file = buffer.update(cx, |buffer, _| {
|
||||
let source_file = buffer.read_with(cx, |buffer, _| {
|
||||
buffer.file().map(|file| file.path()).map(|path| path.to_string_lossy().to_string()).unwrap_or_else(|| "Unknown".to_string())
|
||||
})?;
|
||||
|
||||
let switch_source_header = if let Some((client, project_id)) = upstream_client {
|
||||
let buffer_id = buffer.update(cx, |buffer, _| buffer.remote_id())?;
|
||||
let buffer_id = buffer.read_with(cx, |buffer, _| buffer.remote_id())?;
|
||||
let request = proto::LspExtSwitchSourceHeader {
|
||||
project_id,
|
||||
buffer_id: buffer_id.to_proto(),
|
||||
|
|
|
@ -14610,7 +14610,7 @@ impl Editor {
|
|||
let location = match location_task {
|
||||
Some(task) => Some({
|
||||
let target_buffer_handle = task.await.context("open local buffer")?;
|
||||
let range = target_buffer_handle.update(cx, |target_buffer, _| {
|
||||
let range = target_buffer_handle.read_with(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
|
||||
|
@ -14799,7 +14799,7 @@ impl Editor {
|
|||
} else {
|
||||
if PreviewTabsSettings::get_global(cx).enable_preview_from_code_navigation {
|
||||
let (preview_item_id, preview_item_idx) =
|
||||
workspace.active_pane().update(cx, |pane, _| {
|
||||
workspace.active_pane().read_with(cx, |pane, _| {
|
||||
(pane.preview_item_id(), pane.preview_item_idx())
|
||||
});
|
||||
|
||||
|
@ -20115,7 +20115,7 @@ impl SemanticsProvider for Entity<Project> {
|
|||
PrepareRenameResponse::InvalidPosition => None,
|
||||
PrepareRenameResponse::OnlyUnpreparedRenameSupported => {
|
||||
// Fallback on using TreeSitter info to determine identifier range
|
||||
buffer.update(cx, |buffer, _| {
|
||||
buffer.read_with(cx, |buffer, _| {
|
||||
let snapshot = buffer.snapshot();
|
||||
let (range, kind) = snapshot.surrounding_word(position);
|
||||
if kind != Some(CharKind::Word) {
|
||||
|
|
|
@ -2193,7 +2193,7 @@ impl EditorElement {
|
|||
) {
|
||||
let mouse_position = window.mouse_position();
|
||||
let mouse_over_inline_blame = parent_bounds.contains(&mouse_position);
|
||||
let mouse_over_popover = self.editor.update(cx, |editor, _| {
|
||||
let mouse_over_popover = self.editor.read_with(cx, |editor, _| {
|
||||
editor
|
||||
.inline_blame_popover
|
||||
.as_ref()
|
||||
|
@ -2209,7 +2209,7 @@ impl EditorElement {
|
|||
}
|
||||
});
|
||||
|
||||
let should_draw = self.editor.update(cx, |editor, _| {
|
||||
let should_draw = self.editor.read_with(cx, |editor, _| {
|
||||
editor
|
||||
.inline_blame_popover
|
||||
.as_ref()
|
||||
|
@ -2243,7 +2243,7 @@ impl EditorElement {
|
|||
|
||||
if let Some(mut element) = maybe_element {
|
||||
let size = element.layout_as_root(AvailableSpace::min_size(), window, cx);
|
||||
let origin = self.editor.update(cx, |editor, _| {
|
||||
let origin = self.editor.read_with(cx, |editor, _| {
|
||||
let target_point = editor
|
||||
.inline_blame_popover
|
||||
.as_ref()
|
||||
|
@ -4322,7 +4322,7 @@ impl EditorElement {
|
|||
..Default::default()
|
||||
};
|
||||
window.with_text_style(Some(text_style), |window| {
|
||||
let mut element = self.editor.update(cx, |editor, _| {
|
||||
let mut element = self.editor.read_with(cx, |editor, _| {
|
||||
let mouse_context_menu = editor.mouse_context_menu.as_ref()?;
|
||||
let context_menu = mouse_context_menu.context_menu.clone();
|
||||
|
||||
|
|
|
@ -786,7 +786,7 @@ mod tests {
|
|||
})
|
||||
.await
|
||||
.unwrap();
|
||||
let buffer_id = buffer.update(cx, |buffer, _| buffer.remote_id());
|
||||
let buffer_id = buffer.read_with(cx, |buffer, _| buffer.remote_id());
|
||||
|
||||
let git_blame = cx.new(|cx| GitBlame::new(buffer.clone(), project, false, true, cx));
|
||||
|
||||
|
@ -896,7 +896,7 @@ mod tests {
|
|||
})
|
||||
.await
|
||||
.unwrap();
|
||||
let buffer_id = buffer.update(cx, |buffer, _| buffer.remote_id());
|
||||
let buffer_id = buffer.read_with(cx, |buffer, _| buffer.remote_id());
|
||||
|
||||
let git_blame = cx.new(|cx| GitBlame::new(buffer.clone(), project, false, true, cx));
|
||||
|
||||
|
|
|
@ -539,7 +539,7 @@ pub fn show_link_definition(
|
|||
let result = match &trigger_point {
|
||||
TriggerPoint::Text(_) => {
|
||||
if let Some((url_range, url)) = find_url(&buffer, buffer_position, cx.clone()) {
|
||||
this.update(cx, |_, _| {
|
||||
this.read_with(cx, |_, _| {
|
||||
let range = maybe!({
|
||||
let start =
|
||||
snapshot.anchor_in_excerpt(excerpt_id, url_range.start)?;
|
||||
|
@ -665,7 +665,7 @@ pub(crate) fn find_url(
|
|||
) -> Option<(Range<text::Anchor>, String)> {
|
||||
const LIMIT: usize = 2048;
|
||||
|
||||
let Ok(snapshot) = buffer.update(&mut cx, |buffer, _| buffer.snapshot()) else {
|
||||
let Ok(snapshot) = buffer.read_with(&mut cx, |buffer, _| buffer.snapshot()) else {
|
||||
return None;
|
||||
};
|
||||
|
||||
|
@ -727,7 +727,7 @@ pub(crate) fn find_url_from_range(
|
|||
) -> Option<String> {
|
||||
const LIMIT: usize = 2048;
|
||||
|
||||
let Ok(snapshot) = buffer.update(&mut cx, |buffer, _| buffer.snapshot()) else {
|
||||
let Ok(snapshot) = buffer.read_with(&mut cx, |buffer, _| buffer.snapshot()) else {
|
||||
return None;
|
||||
};
|
||||
|
||||
|
@ -786,7 +786,7 @@ pub(crate) async fn find_file(
|
|||
cx: &mut AsyncWindowContext,
|
||||
) -> Option<(Range<text::Anchor>, ResolvedPath)> {
|
||||
let project = project?;
|
||||
let snapshot = buffer.update(cx, |buffer, _| buffer.snapshot()).ok()?;
|
||||
let snapshot = buffer.read_with(cx, |buffer, _| buffer.snapshot()).ok()?;
|
||||
let scope = snapshot.language_scope_at(position);
|
||||
let (range, candidate_file_path) = surrounding_filename(snapshot, position)?;
|
||||
|
||||
|
|
|
@ -165,7 +165,7 @@ pub fn hover_at_inlay(
|
|||
this.hover_state.diagnostic_popover = None;
|
||||
})?;
|
||||
|
||||
let language_registry = project.update(cx, |p, _| p.languages().clone())?;
|
||||
let language_registry = project.read_with(cx, |p, _| p.languages().clone())?;
|
||||
let blocks = vec![inlay_hover.tooltip];
|
||||
let parsed_content = parse_blocks(&blocks, &language_registry, None, cx).await;
|
||||
|
||||
|
|
|
@ -639,7 +639,7 @@ impl InlayHintCache {
|
|||
if let Some(resolved_hint_task) = resolved_hint_task {
|
||||
let mut resolved_hint =
|
||||
resolved_hint_task.await.context("hint resolve task")?;
|
||||
editor.update(cx, |editor, _| {
|
||||
editor.read_with(cx, |editor, _| {
|
||||
if let Some(excerpt_hints) =
|
||||
editor.inlay_hint_cache.hints.get(&excerpt_id)
|
||||
{
|
||||
|
@ -933,7 +933,7 @@ fn fetch_and_update_hints(
|
|||
cx: &mut Context<Editor>,
|
||||
) -> Task<anyhow::Result<()>> {
|
||||
cx.spawn(async move |editor, cx|{
|
||||
let buffer_snapshot = excerpt_buffer.update(cx, |buffer, _| buffer.snapshot())?;
|
||||
let buffer_snapshot = excerpt_buffer.read_with(cx, |buffer, _| buffer.snapshot())?;
|
||||
let (lsp_request_limiter, multi_buffer_snapshot) =
|
||||
editor.update(cx, |editor, cx| {
|
||||
let multi_buffer_snapshot =
|
||||
|
@ -1009,7 +1009,7 @@ fn fetch_and_update_hints(
|
|||
.ok()
|
||||
.flatten();
|
||||
|
||||
let cached_excerpt_hints = editor.update(cx, |editor, _| {
|
||||
let cached_excerpt_hints = editor.read_with(cx, |editor, _| {
|
||||
editor
|
||||
.inlay_hint_cache
|
||||
.hints
|
||||
|
@ -2521,7 +2521,7 @@ pub mod tests {
|
|||
"Single buffer should produce a single excerpt with visible range"
|
||||
);
|
||||
let (_, (excerpt_buffer, _, excerpt_visible_range)) = ranges.into_iter().next().unwrap();
|
||||
excerpt_buffer.update(cx, |buffer, _| {
|
||||
excerpt_buffer.read_with(cx, |buffer, _| {
|
||||
let snapshot = buffer.snapshot();
|
||||
let start = buffer
|
||||
.anchor_before(excerpt_visible_range.start)
|
||||
|
|
|
@ -841,7 +841,7 @@ impl Item for Editor {
|
|||
// so that language servers or other downstream listeners of save events get notified.
|
||||
let (dirty_buffers, clean_buffers) = buffers.into_iter().partition(|buffer| {
|
||||
buffer
|
||||
.update(cx, |buffer, _| buffer.is_dirty() || buffer.has_conflict())
|
||||
.read_with(cx, |buffer, _| buffer.is_dirty() || buffer.has_conflict())
|
||||
.unwrap_or(false)
|
||||
});
|
||||
|
||||
|
@ -1089,7 +1089,7 @@ impl SerializableItem for Editor {
|
|||
let project = project.clone();
|
||||
async move |cx| {
|
||||
let language_registry =
|
||||
project.update(cx, |project, _| project.languages().clone())?;
|
||||
project.read_with(cx, |project, _| project.languages().clone())?;
|
||||
|
||||
let language = if let Some(language_name) = language {
|
||||
// We don't fail here, because we'd rather not set the language if the name changed
|
||||
|
@ -2032,7 +2032,7 @@ mod tests {
|
|||
{
|
||||
let project = Project::test(fs.clone(), [path!("/file.rs").as_ref()], cx).await;
|
||||
// Add Rust to the language, so that we can restore the language of the buffer
|
||||
project.update(cx, |project, _| project.languages().add(rust_language()));
|
||||
project.read_with(cx, |project, _| project.languages().add(rust_language()));
|
||||
|
||||
let (workspace, cx) =
|
||||
cx.add_window_view(|window, cx| Workspace::test_new(project.clone(), window, cx));
|
||||
|
|
|
@ -81,7 +81,7 @@ async fn lsp_task_context(
|
|||
cx: &mut AsyncApp,
|
||||
) -> Option<TaskContext> {
|
||||
let worktree_store = project
|
||||
.update(cx, |project, _| project.worktree_store())
|
||||
.read_with(cx, |project, _| project.worktree_store())
|
||||
.ok()?;
|
||||
|
||||
let worktree_abs_path = cx
|
||||
|
|
|
@ -73,7 +73,7 @@ pub fn go_to_parent_module(
|
|||
};
|
||||
|
||||
let location_links = if let Some((client, project_id)) = upstream_client {
|
||||
let buffer_id = buffer.update(cx, |buffer, _| buffer.remote_id())?;
|
||||
let buffer_id = buffer.read_with(cx, |buffer, _| buffer.remote_id())?;
|
||||
|
||||
let request = proto::LspExtGoToParentModule {
|
||||
project_id,
|
||||
|
@ -95,7 +95,7 @@ pub fn go_to_parent_module(
|
|||
.collect::<anyhow::Result<_>>()
|
||||
.context("go to parent module via collab")?
|
||||
} else {
|
||||
let buffer_snapshot = buffer.update(cx, |buffer, _| buffer.snapshot())?;
|
||||
let buffer_snapshot = buffer.read_with(cx, |buffer, _| buffer.snapshot())?;
|
||||
let position = trigger_anchor.text_anchor.to_point_utf16(&buffer_snapshot);
|
||||
project
|
||||
.update(cx, |project, cx| {
|
||||
|
@ -173,7 +173,7 @@ pub fn expand_macro_recursively(
|
|||
expansion: response.expansion,
|
||||
}
|
||||
} else {
|
||||
let buffer_snapshot = buffer.update(cx, |buffer, _| buffer.snapshot())?;
|
||||
let buffer_snapshot = buffer.read_with(cx, |buffer, _| buffer.snapshot())?;
|
||||
let position = trigger_anchor.text_anchor.to_point_utf16(&buffer_snapshot);
|
||||
project
|
||||
.update(cx, |project, cx| {
|
||||
|
@ -249,7 +249,7 @@ pub fn open_docs(editor: &mut Editor, _: &OpenDocs, window: &mut Window, cx: &mu
|
|||
};
|
||||
|
||||
let docs_urls = if let Some((client, project_id)) = upstream_client {
|
||||
let buffer_id = buffer.update(cx, |buffer, _| buffer.remote_id())?;
|
||||
let buffer_id = buffer.read_with(cx, |buffer, _| buffer.remote_id())?;
|
||||
let request = proto::LspExtOpenDocs {
|
||||
project_id,
|
||||
buffer_id: buffer_id.to_proto(),
|
||||
|
@ -264,7 +264,7 @@ pub fn open_docs(editor: &mut Editor, _: &OpenDocs, window: &mut Window, cx: &mu
|
|||
local: response.local,
|
||||
}
|
||||
} else {
|
||||
let buffer_snapshot = buffer.update(cx, |buffer, _| buffer.snapshot())?;
|
||||
let buffer_snapshot = buffer.read_with(cx, |buffer, _| buffer.snapshot())?;
|
||||
let position = trigger_anchor.text_anchor.to_point_utf16(&buffer_snapshot);
|
||||
project
|
||||
.update(cx, |project, cx| {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue