From 871856e8312e7248d12f06f0faa1555f38e50a93 Mon Sep 17 00:00:00 2001 From: Esteban Küber Date: Mon, 2 Oct 2017 15:28:52 -0700 Subject: Highlight code on diagnostics when underlined --- src/librustc_errors/styled_buffer.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/librustc_errors/styled_buffer.rs') diff --git a/src/librustc_errors/styled_buffer.rs b/src/librustc_errors/styled_buffer.rs index 2c33f805203..2c736ec22c3 100644 --- a/src/librustc_errors/styled_buffer.rs +++ b/src/librustc_errors/styled_buffer.rs @@ -144,4 +144,25 @@ impl StyledBuffer { pub fn num_lines(&self) -> usize { self.text.len() } + + pub fn set_style_range(&mut self, + line: usize, + col_start: usize, + col_end: usize, + style: Style, + overwrite: bool) { + for col in col_start..col_end { + self.set_style(line, col, style, overwrite); + } + } + + pub fn set_style(&mut self, line: usize, col: usize, style: Style, overwrite: bool) { + if let Some(ref mut line) = self.styles.get_mut(line) { + if let Some(s) = line.get_mut(col) { + if *s == Style::NoStyle || *s == Style::Quotation || overwrite { + *s = style; + } + } + } + } } -- cgit 1.4.1-3-g733a5