Skip to content

Commit c5bc368

Browse files
authored
[red-knot] Improve Vfs and FileSystem documentation (#11856)
1 parent 73370fe commit c5bc368

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

crates/ruff_db/src/file_system.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@ mod os;
1313

1414
pub type Result<T> = std::io::Result<T>;
1515

16-
/// A file system that can be used to read and write files.
16+
/// An abstraction over `std::fs` with features tailored to Ruff's needs.
1717
///
18-
/// The file system is agnostic to the actual storage medium, it could be a real file system, a combination
19-
/// of a real file system and an in-memory file system in the case of an LSP where unsaved changes are stored in memory,
20-
/// or an all in-memory file system for testing.
18+
/// Provides a file system agnostic API to interact with files and directories.
19+
/// Abstracting the file system operations enables:
20+
///
21+
/// * Accessing unsaved or even untitled files in the LSP use case
22+
/// * Testing with an in-memory file system
23+
/// * Running Ruff in a WASM environment without needing to stub out the full `std::fs` API.
2124
pub trait FileSystem {
2225
/// Reads the metadata of the file or directory at `path`.
2326
fn metadata(&self, path: &FileSystemPath) -> Result<Metadata>;

crates/ruff_db/src/vfs.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub struct Vfs {
3838

3939
#[derive(Default)]
4040
struct VfsInner {
41-
/// Lookup table that maps the path to a salsa interned [`VfsFile`] instance.
41+
/// Lookup table that maps [`VfsPath`]s to salsa interned [`VfsFile`] instances.
4242
///
4343
/// The map also stores entries for files that don't exist on the file system. This is necessary
4444
/// so that queries that depend on the existence of a file are re-executed when the file is created.
@@ -93,7 +93,7 @@ impl Vfs {
9393
})
9494
}
9595

96-
/// Lookups a vendored file by its path. Returns `Some` if a vendored file for the given path
96+
/// Looks up a vendored file by its path. Returns `Some` if a vendored file for the given path
9797
/// exists and `None` otherwise.
9898
pub fn vendored(&self, db: &dyn Db, path: &VendoredPath) -> Option<VfsFile> {
9999
let file = match self
@@ -144,7 +144,7 @@ impl Vfs {
144144
}
145145

146146
/// Creates a salsa like snapshot of the files. The instances share
147-
/// the same path to file mapping.
147+
/// the same path-to-file mapping.
148148
pub fn snapshot(&self) -> Self {
149149
Self {
150150
inner: self.inner.clone(),

0 commit comments

Comments
 (0)