Highlight code on diagnostics when underlined

This commit is contained in:
Esteban Küber 2017-10-02 15:28:52 -07:00
parent bacb5c58df
commit 871856e831
2 changed files with 28 additions and 1 deletions

View File

@ -551,7 +551,13 @@ impl EmitterWriter {
code_offset + annotation.start_col,
style);
}
_ => (),
_ => {
buffer.set_style_range(line_offset,
code_offset + annotation.start_col,
code_offset + annotation.end_col,
style,
annotation.is_primary);
}
}
}

View File

@ -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;
}
}
}
}
}