mirror of
https://github.com/openharmony/third_party_rust_codespan.git
synced 2026-07-19 16:43:33 -04:00
Merge pull request #251 from jyn514/no-reporting
Allow using codespan without codespan-reporting
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
@@ -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::*;
|
||||
|
||||
Reference in New Issue
Block a user