diff --git a/codespan-reporting/src/term.rs b/codespan-reporting/src/term.rs index 3b90abb..122b038 100644 --- a/codespan-reporting/src/term.rs +++ b/codespan-reporting/src/term.rs @@ -126,7 +126,7 @@ pub fn emit<'files, F: Files<'files>>( let mut renderer = Renderer::new(writer, config); match config.display_style { - DisplayStyle::Rich => RichDiagnostic::new(diagnostic).render(files, &mut renderer), + DisplayStyle::Rich => RichDiagnostic::new(diagnostic, config).render(files, &mut renderer), DisplayStyle::Short => ShortDiagnostic::new(diagnostic).render(files, &mut renderer), } } diff --git a/codespan-reporting/src/term/renderer.rs b/codespan-reporting/src/term/renderer.rs index cb79443..a61f93c 100644 --- a/codespan-reporting/src/term/renderer.rs +++ b/codespan-reporting/src/term/renderer.rs @@ -127,16 +127,6 @@ impl<'writer, 'config> Renderer<'writer, 'config> { &self.config.styles } - // FIXME: Architectural smell - we'd prefer not to pass information from the renderer to the view. - pub fn start_context_lines(&self) -> usize { - self.config.start_context_lines - } - - // FIXME: Architectural smell - we'd prefer not to pass information from the renderer to the view. - pub fn end_context_lines(&self) -> usize { - self.config.end_context_lines - } - /// Diagnostic header, with severity, code, and message. /// /// ```text diff --git a/codespan-reporting/src/term/views.rs b/codespan-reporting/src/term/views.rs index 59cdcc5..b645421 100644 --- a/codespan-reporting/src/term/views.rs +++ b/codespan-reporting/src/term/views.rs @@ -3,7 +3,7 @@ use std::ops::Range; use crate::diagnostic::{Diagnostic, LabelStyle}; use crate::files::{Files, Location}; use crate::term::renderer::{Locus, MultiLabel, Renderer, SingleLabel}; -use crate::term::RenderError; +use crate::term::{Config, RenderError}; /// Count the number of decimal digits in `n`. fn count_digits(mut n: usize) -> usize { @@ -16,16 +16,20 @@ fn count_digits(mut n: usize) -> usize { } /// Output a richly formatted diagnostic, with source code previews. -pub struct RichDiagnostic<'diagnostic, FileId> { +pub struct RichDiagnostic<'diagnostic, 'config, FileId> { diagnostic: &'diagnostic Diagnostic, + config: &'config Config, } -impl<'diagnostic, FileId> RichDiagnostic<'diagnostic, FileId> +impl<'diagnostic, 'config, FileId> RichDiagnostic<'diagnostic, 'config, FileId> where FileId: Copy + PartialEq, { - pub fn new(diagnostic: &'diagnostic Diagnostic) -> RichDiagnostic<'diagnostic, FileId> { - RichDiagnostic { diagnostic } + pub fn new( + diagnostic: &'diagnostic Diagnostic, + config: &'config Config, + ) -> RichDiagnostic<'diagnostic, 'config, FileId> { + RichDiagnostic { diagnostic, config } } pub fn render<'files>( @@ -270,10 +274,10 @@ where // The line should be rendered to match the configuration of how much context to show. line.must_render |= // Is this line part of the context after the start of the label? - line_index - start_line_index <= renderer.start_context_lines() + line_index - start_line_index <= self.config.start_context_lines || // Is this line part of the context before the end of the label? - end_line_index - line_index <= renderer.end_context_lines(); + end_line_index - line_index <= self.config.end_context_lines; } // Last labeled line