Skip to content

Commit 871856e

Browse files
committed
Highlight code on diagnostics when underlined
1 parent bacb5c5 commit 871856e

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/librustc_errors/emitter.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,13 @@ impl EmitterWriter {
551551
code_offset + annotation.start_col,
552552
style);
553553
}
554-
_ => (),
554+
_ => {
555+
buffer.set_style_range(line_offset,
556+
code_offset + annotation.start_col,
557+
code_offset + annotation.end_col,
558+
style,
559+
annotation.is_primary);
560+
}
555561
}
556562
}
557563

src/librustc_errors/styled_buffer.rs

+21
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)