editor: Fix semantic tokens missing when opening buffer from multibuffer#53712
Draft
Dnreikronos wants to merge 1 commit intozed-industries:mainfrom
Draft
editor: Fix semantic tokens missing when opening buffer from multibuffer#53712Dnreikronos wants to merge 1 commit intozed-industries:mainfrom
Dnreikronos wants to merge 1 commit intozed-industries:mainfrom
Conversation
A race condition between set_visible_line_count and ScrollPositionChanged caused the initial update_lsp_data call to be dropped for singleton buffers opened from multibuffer search results. The first-render task (scroll.rs:682) spawns update_lsp_data, but the autoscroll from open_buffers_in_workspace replaces post_scroll_update with update_data_on_scroll, which skips update_lsp_data for singletons. Add a needs_initial_lsp_data flag so update_data_on_scroll runs update_lsp_data at least once even for singleton buffers. Fixes zed-industries#53051
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Semantic token highlighting was missing when opening a file from multibuffer search results (Ctrl+Shift+F). Which file got hit depended on window size and scroll offset.
Root cause
Two async tasks race to write
post_scroll_update:set_visible_line_count(scroll.rs:682) fires on first render and spawns a task that callsregister_visible_buffers+update_lsp_data(requests semantic tokens).open_buffers_in_workspace(editor.rs:25049) callschange_selectionswith autoscroll right after creating the editor. This emitsScrollPositionChanged, whose handler (editor.rs:2655) replacespost_scroll_updatewith a task callingupdate_data_on_scroll.update_data_on_scroll(editor.rs:26099) has a singleton guard:if !self.buffer().read(cx).is_singleton()that skipsupdate_lsp_datafor single-file buffers. This is a scroll optimization, singleton buffers don't change their visible buffer set on scroll.The initial task gets dropped, the replacement skips
update_lsp_data, semantic tokens are never requested.Fix
Added a
needs_initial_lsp_dataflag to the Editor struct, set totrueon creation.update_data_on_scrollchecks this flag alongside the singleton guard, soupdate_lsp_dataruns at least once even for singletons. The flag flips tofalseright after, so subsequent scrolls behave exactly as before. No perf impact after the first render.Self-review checklist
Closes #53051
Demo
Before:
https://github.com/user-attachments/assets/77d07d95-cb4a-44ff-842d-1f7a46653ca9
After:
semantic.mp4
Release notes