[−][src]Trait rslint_errors::file::Files
Interface for interacting with source files that are identified by a unique identifier.
Required methods
fn name(&self, id: FileId) -> Option<&str>
Returns the name of the file identified by the id.
fn source(&self, id: FileId) -> Option<&str>
Returns the source of the file identified by the id.
fn line_index(&self, file_id: FileId, byte_index: usize) -> Option<usize>
The index of the line at the byte index.
Implementation
This can be implemented by caching the results of line_starts
and then use binary_search
to compute the line index.
ⓘThis example is not tested
match self.line_starts.binary_search(byte_index) { Ok(line) => line, Err(next_line) => next_line - 1, }
fn line_range(&self, id: FileId, line_index: usize) -> Option<Range<usize>>
The byte range of line in the source of the file.