mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 06:11:43 +00:00
red-knot: Add directory support to MemoryFileSystem
(#11825)
This commit is contained in:
parent
d4dd96d1f4
commit
22b6488550
5 changed files with 463 additions and 93 deletions
|
@ -27,6 +27,18 @@ pub trait FileSystem {
|
|||
|
||||
/// Returns `true` if `path` exists.
|
||||
fn exists(&self, path: &FileSystemPath) -> bool;
|
||||
|
||||
/// Returns `true` if `path` exists and is a directory.
|
||||
fn is_directory(&self, path: &FileSystemPath) -> bool {
|
||||
self.metadata(path)
|
||||
.map_or(false, |metadata| metadata.file_type.is_directory())
|
||||
}
|
||||
|
||||
/// Returns `true` if `path` exists and is a file.
|
||||
fn is_file(&self, path: &FileSystemPath) -> bool {
|
||||
self.metadata(path)
|
||||
.map_or(false, |metadata| metadata.file_type.is_file())
|
||||
}
|
||||
}
|
||||
|
||||
// TODO support untitled files for the LSP use case. Wrap a `str` and `String`
|
||||
|
@ -37,7 +49,7 @@ pub trait FileSystem {
|
|||
///
|
||||
/// The path is guaranteed to be valid UTF-8.
|
||||
#[repr(transparent)]
|
||||
#[derive(Eq, PartialEq, Hash)]
|
||||
#[derive(Eq, PartialEq, Hash, PartialOrd, Ord)]
|
||||
pub struct FileSystemPath(Utf8Path);
|
||||
|
||||
impl FileSystemPath {
|
||||
|
@ -95,7 +107,7 @@ impl FileSystemPath {
|
|||
///
|
||||
/// The path is guaranteed to be valid UTF-8.
|
||||
#[repr(transparent)]
|
||||
#[derive(Eq, PartialEq, Clone, Hash)]
|
||||
#[derive(Eq, PartialEq, Clone, Hash, PartialOrd, Ord)]
|
||||
pub struct FileSystemPathBuf(Utf8PathBuf);
|
||||
|
||||
impl Default for FileSystemPathBuf {
|
||||
|
@ -109,6 +121,10 @@ impl FileSystemPathBuf {
|
|||
Self(Utf8PathBuf::new())
|
||||
}
|
||||
|
||||
pub fn from_utf8_path_buf(path: Utf8PathBuf) -> Self {
|
||||
Self(path)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn as_path(&self) -> &FileSystemPath {
|
||||
FileSystemPath::new(&self.0)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue