From 8e9e8a753c5e6c08d979d2ef4e801ac26d821d72 Mon Sep 17 00:00:00 2001 From: Tobias Schmitz Date: Tue, 20 May 2025 15:23:21 +0200 Subject: [PATCH] docs: update some comments --- crates/typst-library/src/diag.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/crates/typst-library/src/diag.rs b/crates/typst-library/src/diag.rs index aa2783af7..124d717c2 100644 --- a/crates/typst-library/src/diag.rs +++ b/crates/typst-library/src/diag.rs @@ -573,7 +573,7 @@ impl From for EcoString { pub type LoadResult = Result; -/// A callsite independent error that occurred during data loading. +/// A call site independent error that occurred during data loading. /// This avoids polluting the memoization with [`Span`]s and [`FileId`]s from source files. /// Can be turned into a [`SourceDiagnostic`] using the [`LoadedAt::in_text`] /// or [`LoadedAt::in_invalid_text`] methods available on [`LoadResult`]. @@ -622,6 +622,7 @@ impl LoadedAt for Result { } impl Loaded { + /// Report an error, possibly in an external file. pub fn err_in_text( &self, pos: impl Into, @@ -629,10 +630,11 @@ impl Loaded { error: impl std::fmt::Display, ) -> EcoVec { let pos = pos.into(); + // This also does utf-8 validation. Only report an error in an external + // file if it is human readable (valid utf-8), otherwise fall back to + // `err_in_invalid_text`. let lines = Lines::from_bytes(&self.bytes); match (self.source.v, lines) { - // Only report an error in an external file, - // if it is human readable (valid utf-8). (LoadSource::Path(file_id), Ok(lines)) => { if let Some(range) = pos.range(&lines) { let span = Span::from_range(file_id, range); @@ -664,7 +666,7 @@ impl Loaded { } } - /// Report an error, possibly in an external file. + /// Report an error (possibly from an external file) that isn't valid utf-8. pub fn err_in_invalid_text( &self, pos: impl Into,