From cc71969884aad9f42e86659d5e808d039cd8e9ac Mon Sep 17 00:00:00 2001 From: Gabriel Dinner-David Date: Thu, 19 Dec 2024 23:39:43 -0500 Subject: [PATCH] propogate the colours --- helix-term/src/commands/lsp.rs | 9 ++++++++- helix-term/src/ui/editor.rs | 14 ++++++++++---- helix-view/src/document.rs | 4 ++++ helix-view/src/view.rs | 1 + 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/helix-term/src/commands/lsp.rs b/helix-term/src/commands/lsp.rs index 3d75c7e8..aea5e5b9 100644 --- a/helix-term/src/commands/lsp.rs +++ b/helix-term/src/commands/lsp.rs @@ -21,7 +21,7 @@ use helix_view::{ document::{ColorSwatchesId, DocumentColorSwatches, DocumentInlayHints, DocumentInlayHintsId}, editor::Action, handlers::lsp::SignatureHelpInvoked, - theme::Style, + theme::{Color, Style}, Document, View, }; @@ -1346,6 +1346,7 @@ fn compute_color_swatches_for_view( // let mut padding_before_color_swatches = Vec::new(); let mut color_swatches = Vec::new(); + let mut colors = Vec::new(); // let mut padding_after_color_swatches = Vec::new(); let doc_text = doc.text(); @@ -1364,12 +1365,18 @@ fn compute_color_swatches_for_view( let label = String::from("■ "); color_swatches.push(InlineAnnotation::new(char_idx, label)); + colors.push(Color::Rgb( + (swatch.color.red * 255.) as u8, + (swatch.color.green * 255.) as u8, + (swatch.color.blue * 255.) as u8, + )); } doc.set_color_swatches( view_id, DocumentColorSwatches { id: new_doc_color_swatches_id, + colors, color_swatches, }, ); diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 7a1345e9..6ad5f70c 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -207,9 +207,10 @@ impl EditorView { config.end_of_line_diagnostics, )); if let Some(swatches) = doc.color_swatches(view.id) { - for swatch in swatches.color_swatches.clone() { + for (swatch, color) in swatches.color_swatches.iter().zip(swatches.colors.iter()) { struct SwatchAnnotate { swatch_idx: usize, + color: Color, } impl Decoration for SwatchAnnotate { fn decorate_grapheme( @@ -218,14 +219,19 @@ impl EditorView { _grapheme: &FormattedGrapheme, style: &mut Style, ) -> usize { - style.fg = Some(Color::Rgb(4, 12, 28)); + style.fg = Some(self.color); usize::MAX } - fn reset_pos(&mut self, _pos: usize) -> usize { - self.swatch_idx + fn reset_pos(&mut self, pos: usize) -> usize { + if self.swatch_idx >= pos { + self.swatch_idx + } else { + usize::MAX + } } } decorations.add_decoration(SwatchAnnotate { + color: *color, swatch_idx: swatch.char_idx, }); } diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index 22a39c2c..eee5407e 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -38,6 +38,7 @@ use helix_core::{ ChangeSet, Diagnostic, LineEnding, Range, Rope, RopeBuilder, Selection, Syntax, Transaction, }; +use crate::theme::Color; use crate::{ editor::Config, events::{DocumentDidChange, SelectionDidChange}, @@ -275,6 +276,7 @@ pub struct DocumentColorSwatches { pub id: ColorSwatchesId, pub color_swatches: Vec, + pub colors: Vec, } impl DocumentColorSwatches { @@ -283,6 +285,7 @@ impl DocumentColorSwatches { Self { id, color_swatches: Vec::new(), + colors: Vec::new(), } } } @@ -1472,6 +1475,7 @@ impl Document { for text_annotation in self.color_swatches.values_mut() { let DocumentColorSwatches { id: _, + colors: _, color_swatches, } = text_annotation; diff --git a/helix-view/src/view.rs b/helix-view/src/view.rs index e34b5a38..3b26d299 100644 --- a/helix-view/src/view.rs +++ b/helix-view/src/view.rs @@ -484,6 +484,7 @@ impl View { }; if let Some(DocumentColorSwatches { id: _, + colors: _, color_swatches, }) = doc.color_swatches.get(&self.id) {