editor: Fix diagnostic rendering when semantic tokens set to full (#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 #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>
This commit is contained in:
Xin ZhaoandKirill Bulatov authored and GitHub committed 2026-04-07 14:15:33 +00:00
1 parent 8292ab440d
commit 3ed1c32bf9
18 files changed
+468 -97

No files matched your search

+23 -10
View File
@@ -21,9 +21,9 @@ use itertools::Itertools;
use language::{
AutoindentMode, Buffer, BufferChunks, BufferRow, BufferSnapshot, Capability, CharClassifier,
CharKind, CharScopeContext, Chunk, CursorShape, DiagnosticEntryRef, File, IndentGuideSettings,
IndentSize, Language, LanguageScope, OffsetRangeExt, OffsetUtf16, Outline, OutlineItem, Point,
PointUtf16, Selection, TextDimension, TextObject, ToOffset as _, ToPoint as _, TransactionId,
TreeSitterOptions, Unclipped,
IndentSize, Language, LanguageAwareStyling, LanguageScope, OffsetRangeExt, OffsetUtf16,
Outline, OutlineItem, Point, PointUtf16, Selection, TextDimension, TextObject, ToOffset as _,
ToPoint as _, TransactionId, TreeSitterOptions, Unclipped,
language_settings::{AllLanguageSettings, LanguageSettings},
};
@@ -1072,7 +1072,7 @@ pub struct MultiBufferChunks<'a> {
range: Range<MultiBufferOffset>,
excerpt_offset_range: Range<ExcerptOffset>,
excerpt_chunks: Option<ExcerptChunks<'a>>,
language_aware: bool,
language_aware: LanguageAwareStyling,
snapshot: &'a MultiBufferSnapshot,
}
@@ -3340,9 +3340,15 @@ impl EventEmitter<Event> for MultiBuffer {}
impl MultiBufferSnapshot {
pub fn text(&self) -> String {
self.chunks(MultiBufferOffset::ZERO..self.len(), false)
.map(|chunk| chunk.text)
.collect()
self.chunks(
MultiBufferOffset::ZERO..self.len(),
LanguageAwareStyling {
tree_sitter: false,
diagnostics: false,
},
)
.map(|chunk| chunk.text)
.collect()
}
pub fn reversed_chars_at<T: ToOffset>(&self, position: T) -> impl Iterator<Item = char> + '_ {
@@ -3378,7 +3384,14 @@ impl MultiBufferSnapshot {
}
pub fn text_for_range<T: ToOffset>(&self, range: Range<T>) -> impl Iterator<Item = &str> + '_ {
self.chunks(range, false).map(|chunk| chunk.text)
self.chunks(
range,
LanguageAwareStyling {
tree_sitter: false,
diagnostics: false,
},
)
.map(|chunk| chunk.text)
}
pub fn is_line_blank(&self, row: MultiBufferRow) -> bool {
@@ -4178,7 +4191,7 @@ impl MultiBufferSnapshot {
pub fn chunks<T: ToOffset>(
&self,
range: Range<T>,
language_aware: bool,
language_aware: LanguageAwareStyling,
) -> MultiBufferChunks<'_> {
let mut chunks = MultiBufferChunks {
excerpt_offset_range: ExcerptDimension(MultiBufferOffset::ZERO)
@@ -7227,7 +7240,7 @@ impl Excerpt {
fn chunks_in_range<'a>(
&'a self,
range: Range<usize>,
language_aware: bool,
language_aware: LanguageAwareStyling,
snapshot: &'a MultiBufferSnapshot,
) -> ExcerptChunks<'a> {
let buffer = self.buffer_snapshot(snapshot);