Skip to content

Commit db5023e

Browse files
committed
Highlight code on diagnostics when underlined
1 parent abc4a55 commit db5023e

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/librustc_errors/emitter.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,13 @@ impl EmitterWriter {
619619
code_offset + annotation.start_col,
620620
style);
621621
}
622-
_ => (),
622+
_ => {
623+
buffer.set_style_range(line_offset,
624+
code_offset + annotation.start_col,
625+
code_offset + annotation.end_col,
626+
style,
627+
annotation.is_primary);
628+
}
623629
}
624630
}
625631

src/librustc_errors/styled_buffer.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,25 @@ impl StyledBuffer {
144144
pub fn num_lines(&self) -> usize {
145145
self.text.len()
146146
}
147+
148+
pub fn set_style_range(&mut self,
149+
line: usize,
150+
col_start: usize,
151+
col_end: usize,
152+
style: Style,
153+
overwrite: bool) {
154+
for col in col_start..col_end {
155+
self.set_style(line, col, style, overwrite);
156+
}
157+
}
158+
159+
pub fn set_style(&mut self, line: usize, col: usize, style: Style, overwrite: bool) {
160+
if let Some(ref mut line) = self.styles.get_mut(line) {
161+
if let Some(s) = line.get_mut(col) {
162+
if *s == Style::NoStyle || *s == Style::Quotation || overwrite {
163+
*s = style;
164+
}
165+
}
166+
}
167+
}
147168
}

0 commit comments

Comments
 (0)