perf: use a single iteration over the views of a document

This commit is contained in:
Nikita Revenco 2024-12-25 18:08:58 +00:00
parent 7c40fbf555
commit 74b5705f65
2 changed files with 19 additions and 24 deletions

View file

@ -1238,18 +1238,29 @@ pub fn select_references_to_symbol_under_cursor(cx: &mut Context) {
);
}
pub fn compute_inlay_hints_for_all_views(editor: &mut Editor, jobs: &mut crate::job::Jobs) {
if !editor.config().lsp.display_inlay_hints {
pub fn compute_lsp_annotations_for_all_views(editor: &mut Editor, jobs: &mut crate::job::Jobs) {
let display_inlay_hints = editor.config().lsp.display_inlay_hints;
let display_color_swatches = editor.config().lsp.display_color_swatches;
if !display_inlay_hints && !display_color_swatches {
return;
}
for (view, _) in editor.tree.views() {
let doc = match editor.documents.get(&view.doc) {
Some(doc) => doc,
None => continue,
let Some(doc) = editor.documents.get(&view.doc) else {
continue;
};
if let Some(callback) = compute_inlay_hints_for_view(view, doc) {
jobs.callback(callback);
if display_inlay_hints {
if let Some(callback) = compute_inlay_hints_for_view(view, doc) {
jobs.callback(callback);
}
}
if display_color_swatches {
if let Some(callback) = compute_color_swatches_for_view(view, doc) {
jobs.callback(callback);
}
}
}
}
@ -1404,21 +1415,6 @@ fn compute_inlay_hints_for_view(
Some(callback)
}
pub fn compute_color_swatches_for_all_views(editor: &mut Editor, jobs: &mut crate::job::Jobs) {
if !editor.config().lsp.display_color_swatches {
return;
}
for (view, _) in editor.tree.views() {
let Some(doc) = editor.documents.get(&view.doc) else {
continue;
};
if let Some(callback) = compute_color_swatches_for_view(view, doc) {
jobs.callback(callback);
}
}
}
fn compute_color_swatches_for_view(
view: &View,
doc: &Document,

View file

@ -1118,8 +1118,7 @@ impl EditorView {
}
pub fn handle_idle_timeout(&mut self, cx: &mut commands::Context) -> EventResult {
commands::compute_inlay_hints_for_all_views(cx.editor, cx.jobs);
commands::compute_color_swatches_for_all_views(cx.editor, cx.jobs);
commands::compute_lsp_annotations_for_all_views(cx.editor, cx.jobs);
EventResult::Ignored(None)
}