red-knot: source_text, line_index, and parsed_module queries (#11822)

This commit is contained in:
Micha Reiser 2024-06-13 08:37:02 +01:00 committed by GitHub
parent efbf7b14b5
commit d4dd96d1f4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 194 additions and 16 deletions

View file

@ -48,6 +48,31 @@ impl FileSystemPath {
unsafe { &*(path as *const Utf8Path as *const FileSystemPath) }
}
/// Extracts the file extension, if possible.
///
/// The extension is:
///
/// * [`None`], if there is no file name;
/// * [`None`], if there is no embedded `.`;
/// * [`None`], if the file name begins with `.` and has no other `.`s within;
/// * Otherwise, the portion of the file name after the final `.`
///
/// # Examples
///
/// ```
/// use ruff_db::file_system::FileSystemPath;
///
/// assert_eq!("rs", FileSystemPath::new("foo.rs").extension().unwrap());
/// assert_eq!("gz", FileSystemPath::new("foo.tar.gz").extension().unwrap());
/// ```
///
/// See [`Path::extension`] for more details.
#[inline]
#[must_use]
pub fn extension(&self) -> Option<&str> {
self.0.extension()
}
/// Converts the path to an owned [`FileSystemPathBuf`].
pub fn to_path_buf(&self) -> FileSystemPathBuf {
FileSystemPathBuf(self.0.to_path_buf())
@ -251,9 +276,10 @@ impl FileType {
#[cfg(test)]
mod tests {
use crate::file_system::FileRevision;
use filetime::FileTime;
use crate::file_system::FileRevision;
#[test]
fn revision_from_file_time() {
let file_time = FileTime::now();