Merge pull request #251 from jyn514/no-reporting

Allow using codespan without codespan-reporting
This commit is contained in:
Brendan Zabarauskas
2020-06-22 13:09:12 +10:00
committed by GitHub
3 changed files with 13 additions and 2 deletions
+5
View File
@@ -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:
+1
View File
@@ -191,6 +191,7 @@ pub fn column_index(source: &str, line_range: Range<usize>, 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<Item = usize> {
std::iter::once(0).chain(source.match_indices('\n').map(|(i, _)| i + 1))
}
+7 -2
View File
@@ -341,7 +341,7 @@ where
Source: AsRef<str>,
{
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<Item = usize> {
std::iter::once(0).chain(source.match_indices('\n').map(|(i, _)| i + 1))
}
#[cfg(test)]
mod test {
use super::*;