diff --git a/codespan-lsp/src/lib.rs b/codespan-lsp/src/lib.rs index 2f3b279..61d19af 100644 --- a/codespan-lsp/src/lib.rs +++ b/codespan-lsp/src/lib.rs @@ -169,16 +169,16 @@ pub fn make_lsp_diagnostic( mut correlate_file_url: impl FnMut(FileId, &str) -> Result, ) -> Result { // We need a position for the primary error so take the span from the first primary label - let primary_file_id = diagnostic.primary_label.file_span.id; - let primary_span = diagnostic.primary_label.file_span.span; + let primary_file_id = diagnostic.primary_label.file_id; + let primary_span = diagnostic.primary_label.span; let primary_label_range = byte_span_to_range(files, primary_file_id, primary_span)?; let related_information = diagnostic .secondary_labels .into_iter() .map(|label| { - let file_id = label.file_span.id; - let range = byte_span_to_range(files, file_id, label.file_span.span)?; + let file_id = label.file_id; + let range = byte_span_to_range(files, file_id, label.span)?; let uri = correlate_file_url(file_id, files.name(file_id)) .map_err(|()| Error::UnableToCorrelateFilename(files.name(file_id).to_owned()))?; diff --git a/codespan-reporting/examples/emit.rs b/codespan-reporting/examples/emit.rs index c700424..e71c8ee 100644 --- a/codespan-reporting/examples/emit.rs +++ b/codespan-reporting/examples/emit.rs @@ -1,6 +1,6 @@ use structopt::StructOpt; -use codespan::{FileSpan, Files, Span}; +use codespan::{Files, Span}; use codespan_reporting::termcolor::StandardStream; use codespan_reporting::{emit, ColorArg, Diagnostic, Label}; @@ -34,19 +34,21 @@ fn main() { let error = Diagnostic::new_error( "Unexpected type in `+` application", Label::new( - FileSpan::new(file_id, Span::new(36, 38)), + file_id, + Span::new(36, 38), "Expected integer but got string", ), ) .with_code("E0001") .with_secondary_labels(vec![Label::new( - FileSpan::new(file_id, Span::new(36, 38)), + file_id, + Span::new(36, 38), "Expected integer but got string", )]); let warning = Diagnostic::new_warning( "`+` function has no effect unless its result is used", - Label::new(FileSpan::new(file_id, Span::new(22, 49)), "Value discarded"), + Label::new(file_id, Span::new(22, 49), "Value discarded"), ); let diagnostics = [error, warning]; diff --git a/codespan-reporting/src/diagnostic.rs b/codespan-reporting/src/diagnostic.rs index 5acd87b..558c53c 100644 --- a/codespan-reporting/src/diagnostic.rs +++ b/codespan-reporting/src/diagnostic.rs @@ -1,6 +1,6 @@ //! Diagnostic reporting support for the codespan crate -use codespan::FileSpan; +use codespan::{FileId, Span}; #[cfg(feature = "serialization")] use serde::{Deserialize, Serialize}; use std::cmp::Ordering; @@ -57,17 +57,20 @@ impl PartialOrd for Severity { #[cfg_attr(feature = "memory_usage", derive(heapsize_derive::HeapSizeOf))] #[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] pub struct Label { + /// The file that we are labelling. + pub file_id: FileId, /// The span we are going to include in the final snippet. - pub file_span: FileSpan, + pub span: Span, /// A message to provide some additional information for the underlined code. pub message: String, } impl Label { /// Create a new label. - pub fn new(file_span: FileSpan, message: impl Into) -> Label { + pub fn new(file_id: FileId, span: Span, message: impl Into) -> Label { Label { - file_span, + file_id, + span, message: message.into(), } } diff --git a/codespan-reporting/src/emitter.rs b/codespan-reporting/src/emitter.rs index aeca31c..280906a 100644 --- a/codespan-reporting/src/emitter.rs +++ b/codespan-reporting/src/emitter.rs @@ -188,7 +188,7 @@ impl<'a> MarkedSource<'a> { } fn span(&self) -> Span { - self.label.file_span.span + self.label.span } fn start(&self) -> ByteIndex { @@ -200,19 +200,19 @@ impl<'a> MarkedSource<'a> { } fn file_name(&self) -> &'a str { - self.files.name(self.label.file_span.id) + self.files.name(self.label.file_id) } fn location(&self, byte_index: ByteIndex) -> Result { - self.files.location(self.label.file_span.id, byte_index) + self.files.location(self.label.file_id, byte_index) } fn source_slice(&self, span: Span) -> Result<&'a str, impl std::error::Error> { - self.files.source_slice(self.label.file_span.id, span) + self.files.source_slice(self.label.file_id, span) } fn line_span(&self, line_index: LineIndex) -> Result { - self.files.line_span(self.label.file_span.id, line_index) + self.files.line_span(self.label.file_id, line_index) } fn label_color(&self, config: &Config) -> Color { diff --git a/codespan/src/file.rs b/codespan/src/file.rs index 447f169..454d43b 100644 --- a/codespan/src/file.rs +++ b/codespan/src/file.rs @@ -38,21 +38,6 @@ impl error::Error for SpanOutOfBoundsError {} #[cfg_attr(feature = "memory_usage", derive(heapsize_derive::HeapSizeOf))] pub struct FileId(u32); -/// A span that is situated in a source file. -#[derive(Copy, Clone, Debug, PartialEq, Eq)] -#[cfg_attr(feature = "serialization", derive(Deserialize, Serialize))] -#[cfg_attr(feature = "memory_usage", derive(heapsize_derive::HeapSizeOf))] -pub struct FileSpan { - pub id: FileId, - pub span: Span, -} - -impl FileSpan { - pub fn new(id: FileId, span: Span) -> FileSpan { - FileSpan { id, span } - } -} - /// A database of source files. #[derive(Debug, Clone)] pub struct Files { diff --git a/codespan/src/lib.rs b/codespan/src/lib.rs index eafb7ed..be42e71 100644 --- a/codespan/src/lib.rs +++ b/codespan/src/lib.rs @@ -16,7 +16,7 @@ mod index; mod location; mod span; -pub use crate::file::{FileId, FileSpan, Files}; +pub use crate::file::{FileId, Files}; pub use crate::file::{LineIndexOutOfBoundsError, LocationError, SpanOutOfBoundsError}; pub use crate::index::{ByteIndex, ByteOffset}; pub use crate::index::{ColumnIndex, ColumnNumber, ColumnOffset};