Skip to content

editor: Fix semantic tokens missing when opening buffer from multibuffer#53712

Draft
Dnreikronos wants to merge 1 commit intozed-industries:mainfrom
Dnreikronos:fix/semantic-tokens-from-multibuffer
Draft

editor: Fix semantic tokens missing when opening buffer from multibuffer#53712
Dnreikronos wants to merge 1 commit intozed-industries:mainfrom
Dnreikronos:fix/semantic-tokens-from-multibuffer

Conversation

@Dnreikronos
Copy link
Copy Markdown
Contributor

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:

  1. set_visible_line_count (scroll.rs:682) fires on first render and spawns a task that calls register_visible_buffers + update_lsp_data (requests semantic tokens).

  2. open_buffers_in_workspace (editor.rs:25049) calls change_selections with autoscroll right after creating the editor. This emits ScrollPositionChanged, whose handler (editor.rs:2655) replaces post_scroll_update with a task calling update_data_on_scroll.

  3. update_data_on_scroll (editor.rs:26099) has a singleton guard: if !self.buffer().read(cx).is_singleton() that skips update_lsp_data for single-file buffers. This is a scroll optimization, singleton buffers don't change their visible buffer set on scroll.

  4. The initial task gets dropped, the replacement skips update_lsp_data, semantic tokens are never requested.

Fix

Added a needs_initial_lsp_data flag to the Editor struct, set to true on creation. update_data_on_scroll checks this flag alongside the singleton guard, so update_lsp_data runs at least once even for singletons. The flag flips to false right after, so subsequent scrolls behave exactly as before. No perf impact after the first render.

Self-review checklist

  • I've reviewed my own diff for quality, security, and reliability
  • Unsafe blocks (if any) have justifying comments
  • The content is consistent with the UI/UX checklist
  • Tests cover the new/changed behavior
  • Performance impact has been considered and is acceptable

Closes #53051

Demo

Before:
https://github.com/user-attachments/assets/77d07d95-cb4a-44ff-842d-1f7a46653ca9
After:

semantic.mp4

Release notes

  • Fixed semantic token highlighting missing when opening a buffer from multibuffer search results

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
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Apr 11, 2026
@Dnreikronos Dnreikronos marked this pull request as draft April 11, 2026 21:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Semantic tokens are not highlighted when a buffer is opened from a multibuffer

1 participant