Get new theme structure working
* Fix precedence of extends directives * Always group color with font properties for text theming Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
co-authored by
Nathan Sobo
parent
5761756fb4
commit
802f1f4e78
@@ -16,7 +16,7 @@ use zrpc::proto;
|
||||
use crate::{
|
||||
language::{Language, Tree},
|
||||
operation_queue::{self, OperationQueue},
|
||||
settings::{StyleId, ThemeMap},
|
||||
settings::{HighlightId, HighlightMap},
|
||||
sum_tree::{self, FilterCursor, SumTree},
|
||||
time::{self, ReplicaId},
|
||||
util::Bias,
|
||||
@@ -1985,7 +1985,7 @@ impl Snapshot {
|
||||
captures,
|
||||
next_capture: None,
|
||||
stack: Default::default(),
|
||||
theme_mapping: language.theme_mapping(),
|
||||
highlight_map: language.highlight_map(),
|
||||
}),
|
||||
}
|
||||
} else {
|
||||
@@ -2316,8 +2316,8 @@ impl<'a> tree_sitter::TextProvider<'a> for TextProvider<'a> {
|
||||
struct Highlights<'a> {
|
||||
captures: tree_sitter::QueryCaptures<'a, 'a, TextProvider<'a>>,
|
||||
next_capture: Option<(tree_sitter::QueryMatch<'a, 'a>, usize)>,
|
||||
stack: Vec<(usize, StyleId)>,
|
||||
theme_mapping: ThemeMap,
|
||||
stack: Vec<(usize, HighlightId)>,
|
||||
highlight_map: HighlightMap,
|
||||
}
|
||||
|
||||
pub struct HighlightedChunks<'a> {
|
||||
@@ -2341,7 +2341,7 @@ impl<'a> HighlightedChunks<'a> {
|
||||
if offset < next_capture_end {
|
||||
highlights.stack.push((
|
||||
next_capture_end,
|
||||
highlights.theme_mapping.get(capture.index),
|
||||
highlights.highlight_map.get(capture.index),
|
||||
));
|
||||
}
|
||||
highlights.next_capture.take();
|
||||
@@ -2357,7 +2357,7 @@ impl<'a> HighlightedChunks<'a> {
|
||||
}
|
||||
|
||||
impl<'a> Iterator for HighlightedChunks<'a> {
|
||||
type Item = (&'a str, StyleId);
|
||||
type Item = (&'a str, HighlightId);
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
let mut next_capture_start = usize::MAX;
|
||||
@@ -2381,7 +2381,7 @@ impl<'a> Iterator for HighlightedChunks<'a> {
|
||||
next_capture_start = capture.node.start_byte();
|
||||
break;
|
||||
} else {
|
||||
let style_id = highlights.theme_mapping.get(capture.index);
|
||||
let style_id = highlights.highlight_map.get(capture.index);
|
||||
highlights.stack.push((capture.node.end_byte(), style_id));
|
||||
highlights.next_capture = highlights.captures.next();
|
||||
}
|
||||
@@ -2391,7 +2391,7 @@ impl<'a> Iterator for HighlightedChunks<'a> {
|
||||
if let Some(chunk) = self.chunks.peek() {
|
||||
let chunk_start = self.range.start;
|
||||
let mut chunk_end = (self.chunks.offset() + chunk.len()).min(next_capture_start);
|
||||
let mut style_id = StyleId::default();
|
||||
let mut style_id = HighlightId::default();
|
||||
if let Some((parent_capture_end, parent_style_id)) =
|
||||
self.highlights.as_ref().and_then(|h| h.stack.last())
|
||||
{
|
||||
|
||||
@@ -654,16 +654,8 @@ mod tests {
|
||||
.unwrap();
|
||||
let theme = Theme {
|
||||
syntax: vec![
|
||||
(
|
||||
"mod.body".to_string(),
|
||||
Color::from_u32(0xff0000ff),
|
||||
Default::default(),
|
||||
),
|
||||
(
|
||||
"fn.name".to_string(),
|
||||
Color::from_u32(0x00ff00ff),
|
||||
Default::default(),
|
||||
),
|
||||
("mod.body".to_string(), Color::from_u32(0xff0000ff).into()),
|
||||
("fn.name".to_string(), Color::from_u32(0x00ff00ff).into()),
|
||||
],
|
||||
..Default::default()
|
||||
};
|
||||
@@ -676,7 +668,7 @@ mod tests {
|
||||
grammar: grammar.clone(),
|
||||
highlight_query,
|
||||
brackets_query: tree_sitter::Query::new(grammar, "").unwrap(),
|
||||
theme_mapping: Default::default(),
|
||||
highlight_map: Default::default(),
|
||||
});
|
||||
lang.set_theme(&theme);
|
||||
|
||||
@@ -752,16 +744,8 @@ mod tests {
|
||||
.unwrap();
|
||||
let theme = Theme {
|
||||
syntax: vec![
|
||||
(
|
||||
"mod.body".to_string(),
|
||||
Color::from_u32(0xff0000ff),
|
||||
Default::default(),
|
||||
),
|
||||
(
|
||||
"fn.name".to_string(),
|
||||
Color::from_u32(0x00ff00ff),
|
||||
Default::default(),
|
||||
),
|
||||
("mod.body".to_string(), Color::from_u32(0xff0000ff).into()),
|
||||
("fn.name".to_string(), Color::from_u32(0x00ff00ff).into()),
|
||||
],
|
||||
..Default::default()
|
||||
};
|
||||
@@ -774,7 +758,7 @@ mod tests {
|
||||
grammar: grammar.clone(),
|
||||
highlight_query,
|
||||
brackets_query: tree_sitter::Query::new(grammar, "").unwrap(),
|
||||
theme_mapping: Default::default(),
|
||||
highlight_map: Default::default(),
|
||||
});
|
||||
lang.set_theme(&theme);
|
||||
|
||||
@@ -953,7 +937,7 @@ mod tests {
|
||||
let mut snapshot = map.update(cx, |map, cx| map.snapshot(cx));
|
||||
let mut chunks: Vec<(String, Option<&str>)> = Vec::new();
|
||||
for (chunk, style_id) in snapshot.highlighted_chunks_for_rows(rows) {
|
||||
let style_name = theme.syntax_style_name(style_id);
|
||||
let style_name = theme.highlight_name(style_id);
|
||||
if let Some((last_chunk, last_style_name)) = chunks.last_mut() {
|
||||
if style_name == *last_style_name {
|
||||
last_chunk.push_str(chunk);
|
||||
|
||||
@@ -4,7 +4,7 @@ use super::{
|
||||
};
|
||||
use crate::{
|
||||
editor::buffer,
|
||||
settings::StyleId,
|
||||
settings::HighlightId,
|
||||
sum_tree::{self, Cursor, FilterCursor, SumTree},
|
||||
time,
|
||||
util::Bias,
|
||||
@@ -1004,12 +1004,12 @@ impl<'a> Iterator for Chunks<'a> {
|
||||
pub struct HighlightedChunks<'a> {
|
||||
transform_cursor: Cursor<'a, Transform, FoldOffset, usize>,
|
||||
buffer_chunks: buffer::HighlightedChunks<'a>,
|
||||
buffer_chunk: Option<(usize, &'a str, StyleId)>,
|
||||
buffer_chunk: Option<(usize, &'a str, HighlightId)>,
|
||||
buffer_offset: usize,
|
||||
}
|
||||
|
||||
impl<'a> Iterator for HighlightedChunks<'a> {
|
||||
type Item = (&'a str, StyleId);
|
||||
type Item = (&'a str, HighlightId);
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
let transform = if let Some(item) = self.transform_cursor.item() {
|
||||
@@ -1031,7 +1031,7 @@ impl<'a> Iterator for HighlightedChunks<'a> {
|
||||
self.transform_cursor.next(&());
|
||||
}
|
||||
|
||||
return Some((output_text, StyleId::default()));
|
||||
return Some((output_text, HighlightId::default()));
|
||||
}
|
||||
|
||||
// Retrieve a chunk from the current location in the buffer.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use parking_lot::Mutex;
|
||||
|
||||
use super::fold_map::{self, FoldEdit, FoldPoint, Snapshot as FoldSnapshot};
|
||||
use crate::{editor::rope, settings::StyleId, util::Bias};
|
||||
use crate::{editor::rope, settings::HighlightId, util::Bias};
|
||||
use std::{mem, ops::Range};
|
||||
|
||||
pub struct TabMap(Mutex<Snapshot>);
|
||||
@@ -416,14 +416,14 @@ impl<'a> Iterator for Chunks<'a> {
|
||||
pub struct HighlightedChunks<'a> {
|
||||
fold_chunks: fold_map::HighlightedChunks<'a>,
|
||||
chunk: &'a str,
|
||||
style_id: StyleId,
|
||||
style_id: HighlightId,
|
||||
column: usize,
|
||||
tab_size: usize,
|
||||
skip_leading_tab: bool,
|
||||
}
|
||||
|
||||
impl<'a> Iterator for HighlightedChunks<'a> {
|
||||
type Item = (&'a str, StyleId);
|
||||
type Item = (&'a str, HighlightId);
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
if self.chunk.is_empty() {
|
||||
|
||||
@@ -5,7 +5,7 @@ use super::{
|
||||
};
|
||||
use crate::{
|
||||
editor::Point,
|
||||
settings::StyleId,
|
||||
settings::HighlightId,
|
||||
sum_tree::{self, Cursor, SumTree},
|
||||
util::Bias,
|
||||
Settings,
|
||||
@@ -59,7 +59,7 @@ pub struct Chunks<'a> {
|
||||
pub struct HighlightedChunks<'a> {
|
||||
input_chunks: tab_map::HighlightedChunks<'a>,
|
||||
input_chunk: &'a str,
|
||||
style_id: StyleId,
|
||||
style_id: HighlightId,
|
||||
output_position: WrapPoint,
|
||||
max_output_row: u32,
|
||||
transforms: Cursor<'a, Transform, WrapPoint, TabPoint>,
|
||||
@@ -487,7 +487,7 @@ impl Snapshot {
|
||||
HighlightedChunks {
|
||||
input_chunks: self.tab_snapshot.highlighted_chunks(input_start..input_end),
|
||||
input_chunk: "",
|
||||
style_id: StyleId::default(),
|
||||
style_id: HighlightId::default(),
|
||||
output_position: output_start,
|
||||
max_output_row: rows.end,
|
||||
transforms,
|
||||
@@ -670,7 +670,7 @@ impl<'a> Iterator for Chunks<'a> {
|
||||
}
|
||||
|
||||
impl<'a> Iterator for HighlightedChunks<'a> {
|
||||
type Item = (&'a str, StyleId);
|
||||
type Item = (&'a str, HighlightId);
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
if self.output_position.row() >= self.max_output_row {
|
||||
|
||||
Reference in New Issue
Block a user