Skip to content

Commit ff49bc5

Browse files
committed
move full renderer to its own module
restore cut_indicator from #19420
1 parent fa711fa commit ff49bc5

File tree

2 files changed

+59
-33
lines changed

2 files changed

+59
-33
lines changed

crates/ruff_db/src/diagnostic/render.rs

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ use std::borrow::Cow;
22
use std::collections::BTreeMap;
33
use std::path::Path;
44

5+
use full::FullRenderer;
56
use ruff_annotate_snippets::{
67
Annotation as AnnotateAnnotation, Level as AnnotateLevel, Message as AnnotateMessage,
7-
Renderer as AnnotateRenderer, Snippet as AnnotateSnippet,
8+
Snippet as AnnotateSnippet,
89
};
910
use ruff_notebook::{Notebook, NotebookIndex};
1011
use ruff_source_file::{LineIndex, OneIndexed, SourceCode};
1112
use ruff_text_size::{TextLen, TextRange, TextSize};
1213

13-
use crate::diagnostic::stylesheet::DiagnosticStylesheet;
1414
use crate::{
1515
Db,
1616
files::File,
@@ -111,37 +111,7 @@ impl std::fmt::Display for DisplayDiagnostics<'_> {
111111
ConciseRenderer::new(self.resolver, self.config).render(f, self.diagnostics)?;
112112
}
113113
DiagnosticFormat::Full => {
114-
let stylesheet = if self.config.color {
115-
DiagnosticStylesheet::styled()
116-
} else {
117-
DiagnosticStylesheet::plain()
118-
};
119-
120-
let mut renderer = if self.config.color {
121-
AnnotateRenderer::styled()
122-
} else {
123-
AnnotateRenderer::plain()
124-
}
125-
.cut_indicator("…");
126-
127-
renderer = renderer
128-
.error(stylesheet.error)
129-
.warning(stylesheet.warning)
130-
.info(stylesheet.info)
131-
.note(stylesheet.note)
132-
.help(stylesheet.help)
133-
.line_no(stylesheet.line_no)
134-
.emphasis(stylesheet.emphasis)
135-
.none(stylesheet.none);
136-
137-
for diag in self.diagnostics {
138-
let resolved = Resolved::new(self.resolver, diag, self.config);
139-
let renderable = resolved.to_renderable(self.config.context);
140-
for diag in renderable.diagnostics.iter() {
141-
writeln!(f, "{}", renderer.render(diag.to_annotate()))?;
142-
}
143-
writeln!(f)?;
144-
}
114+
FullRenderer::new(self.resolver, self.config).render(f, self.diagnostics)?;
145115
}
146116
DiagnosticFormat::Azure => {
147117
AzureRenderer::new(self.resolver).render(f, self.diagnostics)?;

crates/ruff_db/src/diagnostic/render/full.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,59 @@
1+
use ruff_annotate_snippets::Renderer as AnnotateRenderer;
2+
3+
use crate::diagnostic::render::{FileResolver, Resolved};
4+
use crate::diagnostic::{Diagnostic, DisplayDiagnosticConfig, stylesheet::DiagnosticStylesheet};
5+
6+
pub(super) struct FullRenderer<'a> {
7+
resolver: &'a dyn FileResolver,
8+
config: &'a DisplayDiagnosticConfig,
9+
}
10+
11+
impl<'a> FullRenderer<'a> {
12+
pub(super) fn new(resolver: &'a dyn FileResolver, config: &'a DisplayDiagnosticConfig) -> Self {
13+
Self { resolver, config }
14+
}
15+
16+
pub(super) fn render(
17+
&self,
18+
f: &mut std::fmt::Formatter,
19+
diagnostics: &[Diagnostic],
20+
) -> std::fmt::Result {
21+
let stylesheet = if self.config.color {
22+
DiagnosticStylesheet::styled()
23+
} else {
24+
DiagnosticStylesheet::plain()
25+
};
26+
27+
let mut renderer = if self.config.color {
28+
AnnotateRenderer::styled()
29+
} else {
30+
AnnotateRenderer::plain()
31+
}
32+
.cut_indicator("…");
33+
34+
renderer = renderer
35+
.error(stylesheet.error)
36+
.warning(stylesheet.warning)
37+
.info(stylesheet.info)
38+
.note(stylesheet.note)
39+
.help(stylesheet.help)
40+
.line_no(stylesheet.line_no)
41+
.emphasis(stylesheet.emphasis)
42+
.none(stylesheet.none);
43+
44+
for diag in diagnostics {
45+
let resolved = Resolved::new(self.resolver, diag, self.config);
46+
let renderable = resolved.to_renderable(self.config.context);
47+
for diag in renderable.diagnostics.iter() {
48+
writeln!(f, "{}", renderer.render(diag.to_annotate()))?;
49+
}
50+
writeln!(f)?;
51+
}
52+
53+
Ok(())
54+
}
55+
}
56+
157
#[cfg(test)]
258
mod tests {
359
use ruff_diagnostics::Applicability;

0 commit comments

Comments
 (0)