diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eef3843..bff3b32 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,6 +35,11 @@ jobs: with: command: check args: --manifest-path "codespan/Cargo.toml" --features "serialization" + - name: Run cargo test for codespan without codespan-reporting + uses: actions-rs/cargo@v1 + with: + command: check + args: --manifest-path "codespan/Cargo.toml" --no-default-features - name: Run cargo test for codespan-lsp uses: actions-rs/cargo@v1 with: diff --git a/codespan-reporting/src/files.rs b/codespan-reporting/src/files.rs index a717555..41691b9 100644 --- a/codespan-reporting/src/files.rs +++ b/codespan-reporting/src/files.rs @@ -191,6 +191,7 @@ pub fn column_index(source: &str, line_range: Range, byte_index: usize) - /// /// assert_eq!(line_index(&line_starts, 5), Some(1)); /// ``` +// NOTE: this is copied in `codespan::file::line_starts` and should be kept in sync. pub fn line_starts<'source>(source: &'source str) -> impl 'source + Iterator { std::iter::once(0).chain(source.match_indices('\n').map(|(i, _)| i + 1)) } diff --git a/codespan/src/file.rs b/codespan/src/file.rs index 322a6d0..3150517 100644 --- a/codespan/src/file.rs +++ b/codespan/src/file.rs @@ -341,7 +341,7 @@ where Source: AsRef, { fn new(name: OsString, source: Source) -> Self { - let line_starts = codespan_reporting::files::line_starts(source.as_ref()) + let line_starts = line_starts(source.as_ref()) .map(|i| ByteIndex::from(i as u32)) .collect(); @@ -353,7 +353,7 @@ where } fn update(&mut self, source: Source) { - let line_starts = codespan_reporting::files::line_starts(source.as_ref()) + let line_starts = line_starts(source.as_ref()) .map(|i| ByteIndex::from(i as u32)) .collect(); self.source = source; @@ -443,6 +443,11 @@ where } } +// NOTE: this is copied from `codespan_reporting::files::line_starts` and should be kept in sync. +fn line_starts<'source>(source: &'source str) -> impl 'source + Iterator { + std::iter::once(0).chain(source.match_indices('\n').map(|(i, _)| i + 1)) +} + #[cfg(test)] mod test { use super::*;