# editor: Fix semantic tokens missing when opening buffer from multibuffer \(\#53712\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/a86de48c70e4bcc8c8da53eb5317726c74be7005)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: a86de48c70e4bcc8c8da53eb5317726c74be7005

Requested commit: a86de48c70e4bcc8c8da53eb5317726c74be7005

Commit: a86de48c70e4bcc8c8da53eb5317726c74be7005

Tree: 9d8ea56eaee09a2d46d6ff132b6a67932d528a0d

Author: João Soares

Committer: GitHub

## Message

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

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

- [x] 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](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Closes #53051

## Demo

Before:

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


https://github.com/user-attachments/assets/2c942f52-4ec3-459f-a97b-93919e4bfb3d



## Release notes

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

## Parents

- [5a47e9825babb293a4e4aea3359fb860085ab63f](https://git.cafe/gitcafe/zed/commit/5a47e9825babb293a4e4aea3359fb860085ab63f?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/a86de48c70e4bcc8c8da53eb5317726c74be7005?format=markdown)
