(&self, source_path: PathBuf, cache: &mut FileTreeCache)
| 164 | |
| 165 | impl ErrorMessage { |
| 166 | fn compose_display(&self, source_path: PathBuf, cache: &mut FileTreeCache) -> Option<String> { |
| 167 | // We always pass color to ariadne as true, and then (currently) strip later. |
| 168 | let config = Config::default().with_color(true); |
| 169 | |
| 170 | // Create a span tuple with the source path and the error range |
| 171 | let span = Range::from(self.span?); |
| 172 | let error_span = (source_path.clone(), span.start..span.end); |
| 173 | |
| 174 | let mut report = Report::build(ReportKind::Error, error_span.clone()) |
| 175 | .with_config(config) |
| 176 | .with_label(Label::new(error_span).with_message(&self.reason)); |
| 177 | |
| 178 | if let Some(code) = &self.code { |
| 179 | report = report.with_code(code); |
| 180 | } |
| 181 | |
| 182 | // I don't know how to set multiple hints... |
| 183 | if !self.hints.is_empty() { |
| 184 | report.set_help(&self.hints[0]); |
| 185 | } |
| 186 | if self.hints.len() > 1 { |
| 187 | report.set_note(&self.hints[1]); |
| 188 | } |
| 189 | if self.hints.len() > 2 { |
| 190 | report.set_message(&self.hints[2]); |
| 191 | } |
| 192 | |
| 193 | let mut out = Vec::new(); |
| 194 | report.finish().write(cache, &mut out).ok()?; |
| 195 | String::from_utf8(out) |
| 196 | .ok() |
| 197 | .map(|x| crate::utils::maybe_strip_colors(x.as_str())) |
| 198 | } |
| 199 | |
| 200 | fn compose_location(&self, source: &Source) -> Option<SourceLocation> { |
| 201 | let span = self.span?; |
no test coverage detected