editor: Fix diagnostic rendering when semantic tokens set to full#53008
editor: Fix diagnostic rendering when semantic tokens set to full#53008SomeoneToIgnore merged 4 commits intozed-industries:mainfrom
Conversation
SomeoneToIgnore
left a comment
There was a problem hiding this comment.
Oh, I see now, sorry: it's the rendering code that we're hitting here purely, so it's hard to test — would be amazing if we can get it tested somehow still, but not insisting now.
What's confusing though is this bit:
zed/crates/language/src/buffer.rs
Lines 3736 to 3746 in cb99ab4
it seems wasteful to get language highlights for the full case here — which we will do due to the new code, won't we?
Can we rework the code somehow to avoid getting the highlights but do get the diagnostics?
Would be good to get tests, if possible.
Very insightful point! Ideally, when using the "full" mode, Tree-sitter highlighting is unnecessary, and skipping it would indeed be a performance win and also make the architecture cleaner. However, achieving this would require decoupling diagnostics from syntax highlighting at a very low level. The Modifying the signature of I agree the current fix is a bit "dirty". While it correctly breaks the coupling between
I intended to add a GPUI test, but found that I would have to manually call |
Yes, that's a 7-level chain but overall it's triggered in a particular, highlighted above level only, to disable the highlights on one level, the rest is just passing the parameter through, so I find it hard to agree with this phrase. Do I miss something?
Is it a bad thing? If we can have a test with both diagnostics and tokens and the |
c2e08f4 to
b47c639
Compare
|
Truly thanks for the review! The fix now addresses the root cause directly, and I'm pretty satisfied with how it turned out. About the test I added: it's a bit tricky because it cannot be easily tested against the current main branch. It will fail to compile rather than failing at the assertion, simply because it passes the new |
SomeoneToIgnore
left a comment
There was a problem hiding this comment.
Thank you a lot for the fix and the test!
|
May I ask why you chose to pass the full struct in every location instead of using |
|
Yes, it's totally not clear to me by looking at To emphasize, the more important fix was to pass |
|
Understood. I'm transitioning from Python and still learning the 'Rust way.' Thanks for the explanation, it helps me keep my future contributions idiomatic. |
|
/cherry-pick preview |
|
🍒💥 Cherry-pick did not succeed |
|
🍒💥 Cherry-pick did not succeed |
…d-industries#53008) Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content is consistent with the [UI/UX checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) - [ ] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable Closes zed-industries#50212 There are two unreasonable coupling account for this issue, the coupling of `use_tree_sitter` with `languge_aware` in https://github.com/zed-industries/zed/blob/7892b932795911516f26f3c1c1c72249ed181ba8/crates/editor/src/element.rs#L3820-L3822 and the coupling of `language_aware` with `diagnostics` in https://github.com/zed-industries/zed/blob/7892b932795911516f26f3c1c1c72249ed181ba8/crates/language/src/buffer.rs#L3736-L3746 Because of these couplings, when the editor stops using Tree-sitter highlighting when `"semantic_tokens"` set to `"full"`, it also accidentally stops fetching diagnostic information. This is why error and warning underlines disappear. I’ve fixed this by adding a separate `use_tree_sitter` parameter to `highlighted_chunks`. This way, we can keep `language_aware` true to get the diagnostic data we need, but still decide whether or not to apply Tree-sitter highlights. I chose to fix this at the `highlighted_chunks` level because I’m worried that changing the logic in the deeper layers of the DisplayMap or Buffer might have too many side effects that are hard to predict. This approach feels like a safer way to solve the problem. Release Notes: - Fixed a bug where diagnostic underlines disappeared when "semantic_tokens" set to "full" --------- Co-authored-by: Kirill Bulatov <kirill@zed.dev>
…d-industries#53008) Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content is consistent with the [UI/UX checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) - [ ] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable Closes zed-industries#50212 There are two unreasonable coupling account for this issue, the coupling of `use_tree_sitter` with `languge_aware` in https://github.com/zed-industries/zed/blob/23eaa7d2b30731447088bc0b0318853049c3a6f0/crates/editor/src/element.rs#L3820-L3822 and the coupling of `language_aware` with `diagnostics` in https://github.com/zed-industries/zed/blob/23eaa7d2b30731447088bc0b0318853049c3a6f0/crates/language/src/buffer.rs#L3736-L3746 Because of these couplings, when the editor stops using Tree-sitter highlighting when `"semantic_tokens"` set to `"full"`, it also accidentally stops fetching diagnostic information. This is why error and warning underlines disappear. I’ve fixed this by adding a separate `use_tree_sitter` parameter to `highlighted_chunks`. This way, we can keep `language_aware` true to get the diagnostic data we need, but still decide whether or not to apply Tree-sitter highlights. I chose to fix this at the `highlighted_chunks` level because I’m worried that changing the logic in the deeper layers of the DisplayMap or Buffer might have too many side effects that are hard to predict. This approach feels like a safer way to solve the problem. Release Notes: - Fixed a bug where diagnostic underlines disappeared when "semantic_tokens" set to "full" --------- Co-authored-by: Kirill Bulatov <kirill@zed.dev>

Self-Review Checklist:
Closes #50212
There are two unreasonable coupling account for this issue, the coupling of
use_tree_sitterwithlanguge_awareinzed/crates/editor/src/element.rs
Lines 3820 to 3822 in 7892b93
and the coupling of
language_awarewithdiagnosticsinzed/crates/language/src/buffer.rs
Lines 3736 to 3746 in 7892b93
Because of these couplings, when the editor stops using Tree-sitter highlighting when
"semantic_tokens"set to"full", it also accidentally stops fetching diagnostic information. This is why error and warning underlines disappear.I’ve fixed this by adding a separate
use_tree_sitterparameter tohighlighted_chunks. This way, we can keeplanguage_awaretrue to get the diagnostic data we need, but still decide whether or not to apply Tree-sitter highlights. I chose to fix this at thehighlighted_chunkslevel because I’m worried that changing the logic in the deeper layers of the DisplayMap or Buffer might have too many side effects that are hard to predict. This approach feels like a safer way to solve the problem.Release Notes: