Reduce display_map snapshot creation (#39354)

Re-applies https://github.com/zed-industries/zed/pull/30840

This PR re-applies the initial
[PR](https://github.com/zed-industries/zed/pull/30840). As it was closed
because it was hard to land, because of the many conflicts. This PR
re-applies the changes for it.

In several cases we were creating multiple display_map
snapshots within the same root-level function call.
Creating a display_map snapshot is quite slow, and in some
cases we were creating the snapshot multiple times.

Release Notes:

- N/A
This commit is contained in:
Remco Smits
2025-10-17 21:56:57 +02:00
committed by GitHub
parent ef5b8c6fed
commit 7e97fcaacb
60 changed files with 853 additions and 426 deletions
+12 -5
View File
@@ -1359,7 +1359,10 @@ impl Vim {
return;
};
let newest_selection_empty = editor.update(cx, |editor, cx| {
editor.selections.newest::<usize>(cx).is_empty()
editor
.selections
.newest::<usize>(&editor.display_snapshot(cx))
.is_empty()
});
let editor = editor.read(cx);
let editor_mode = editor.mode();
@@ -1455,9 +1458,11 @@ impl Vim {
cx: &mut Context<Self>,
) -> Option<String> {
self.update_editor(cx, |_, editor, cx| {
let selection = editor.selections.newest::<usize>(cx);
let snapshot = &editor.snapshot(window, cx);
let selection = editor
.selections
.newest::<usize>(&snapshot.display_snapshot);
let snapshot = editor.snapshot(window, cx);
let snapshot = snapshot.buffer_snapshot();
let (range, kind) =
snapshot.surrounding_word(selection.start, Some(CharScopeContext::Completion));
@@ -1484,9 +1489,11 @@ impl Vim {
let selections = self.editor().map(|editor| {
editor.update(cx, |editor, cx| {
let snapshot = editor.display_snapshot(cx);
(
editor.selections.oldest::<Point>(cx),
editor.selections.newest::<Point>(cx),
editor.selections.oldest::<Point>(&snapshot),
editor.selections.newest::<Point>(&snapshot),
)
})
});