Lines Matching defs:source

72     fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
80 /// A minimal interface for accessing source files when rendering diagnostics.
87 /// for rendering `diagnostic::Label`s in the corresponding source files.
91 /// The source code of a file.
97 /// The source code of a file.
98 fn source(&'a self, id: Self::FileId) -> Result<Self::Source, Error>;
147 let source = self.source(id)?;
149 let column_index = column_index(source.as_ref(), line_range, byte_index);
165 /// The byte range of line in the source of the file.
169 /// A user-facing location in a source file.
182 /// The column index at the given byte index in the source file.
194 /// let source = "\n\n?∈?\n\n";
196 /// assert_eq!(files::column_index(source, 0..1, 0), 0);
197 /// assert_eq!(files::column_index(source, 2..13, 0), 0);
198 /// assert_eq!(files::column_index(source, 2..13, 2 + 0), 0);
199 /// assert_eq!(files::column_index(source, 2..13, 2 + 1), 0);
200 /// assert_eq!(files::column_index(source, 2..13, 2 + 4), 1);
201 /// assert_eq!(files::column_index(source, 2..13, 2 + 8), 2);
202 /// assert_eq!(files::column_index(source, 2..13, 2 + 10), 2);
203 /// assert_eq!(files::column_index(source, 2..13, 2 + 11), 3);
204 /// assert_eq!(files::column_index(source, 2..13, 2 + 12), 3);
206 pub fn column_index(source: &str, line_range: Range<usize>, byte_index: usize) -> usize {
207 let end_index = std::cmp::min(byte_index, std::cmp::min(line_range.end, source.len()));
210 .filter(|byte_index| source.is_char_boundary(byte_index + 1))
214 /// Return the starting byte index of each line in the source string.
228 /// let source = "foo\nbar\r\n\nbaz";
229 /// let line_starts: Vec<_> = files::line_starts(source).collect();
251 pub fn line_starts<'source>(source: &'source str) -> impl 'source + Iterator<Item = usize> {
252 std::iter::once(0).chain(source.match_indices('\n').map(|(i, _)| i + 1))
255 /// A file database that contains a single source file.
267 /// The source code of the file.
268 source: Source,
269 /// The starting byte indices in the source code.
278 /// Create a new source file.
279 pub fn new(name: Name, source: Source) -> SimpleFile<Name, Source> {
282 line_starts: line_starts(source.as_ref()).collect(),
283 source,
292 /// Return the source of the file.
293 pub fn source(&self) -> &Source {
294 &self.source
308 Ordering::Equal => Ok(self.source.as_ref().len()),
330 fn source(&self, (): ()) -> Result<&str, Error> {
331 Ok(self.source.as_ref())
349 /// A file database that can store multiple source files.
371 pub fn add(&mut self, name: Name, source: Source) -> usize {
373 self.files.push(SimpleFile::new(name, source));
396 fn source(&self, file_id: usize) -> Result<&str, Error> {
397 Ok(self.get(file_id)?.source().as_ref())
437 &file.source[line_range]