mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 22:01:47 +00:00
[red-knot] Rename FileSystem
to System
(#12214)
This commit is contained in:
parent
16a63c88cf
commit
ac04380f36
38 changed files with 1432 additions and 1291 deletions
|
@ -3,28 +3,29 @@ use std::hash::BuildHasherDefault;
|
|||
use rustc_hash::FxHasher;
|
||||
use salsa::DbWithJar;
|
||||
|
||||
use crate::file_system::FileSystem;
|
||||
use crate::files::{File, Files};
|
||||
use crate::parsed::parsed_module;
|
||||
use crate::source::{line_index, source_text};
|
||||
use crate::vfs::{Vfs, VfsFile};
|
||||
use crate::system::System;
|
||||
use crate::vendored::VendoredFileSystem;
|
||||
|
||||
pub mod file_revision;
|
||||
pub mod file_system;
|
||||
pub mod files;
|
||||
pub mod parsed;
|
||||
pub mod source;
|
||||
pub mod system;
|
||||
pub mod vendored;
|
||||
pub mod vfs;
|
||||
|
||||
pub(crate) type FxDashMap<K, V> = dashmap::DashMap<K, V, BuildHasherDefault<FxHasher>>;
|
||||
|
||||
#[salsa::jar(db=Db)]
|
||||
pub struct Jar(VfsFile, source_text, line_index, parsed_module);
|
||||
pub struct Jar(File, source_text, line_index, parsed_module);
|
||||
|
||||
/// Database that gives access to the virtual filesystem, source code, and parsed AST.
|
||||
/// Most basic database that gives access to files, the host system, source code, and parsed AST.
|
||||
pub trait Db: DbWithJar<Jar> {
|
||||
fn file_system(&self) -> &dyn FileSystem;
|
||||
|
||||
fn vfs(&self) -> &Vfs;
|
||||
fn vendored(&self) -> &VendoredFileSystem;
|
||||
fn system(&self) -> &dyn System;
|
||||
fn files(&self) -> &Files;
|
||||
}
|
||||
|
||||
/// Trait for upcasting a reference to a base trait object.
|
||||
|
@ -38,39 +39,36 @@ mod tests {
|
|||
|
||||
use salsa::DebugWithDb;
|
||||
|
||||
use crate::file_system::{FileSystem, MemoryFileSystem};
|
||||
use crate::vfs::{VendoredPathBuf, Vfs};
|
||||
use crate::files::Files;
|
||||
use crate::system::TestSystem;
|
||||
use crate::system::{DbWithTestSystem, System};
|
||||
use crate::vendored::VendoredFileSystem;
|
||||
use crate::{Db, Jar};
|
||||
|
||||
/// Database that can be used for testing.
|
||||
///
|
||||
/// Uses an in memory filesystem and it stubs out the vendored files by default.
|
||||
#[derive(Default)]
|
||||
#[salsa::db(Jar)]
|
||||
pub(crate) struct TestDb {
|
||||
storage: salsa::Storage<Self>,
|
||||
vfs: Vfs,
|
||||
file_system: MemoryFileSystem,
|
||||
files: Files,
|
||||
system: TestSystem,
|
||||
vendored: VendoredFileSystem,
|
||||
events: std::sync::Arc<std::sync::Mutex<Vec<salsa::Event>>>,
|
||||
}
|
||||
|
||||
impl TestDb {
|
||||
pub(crate) fn new() -> Self {
|
||||
let mut vfs = Vfs::default();
|
||||
vfs.stub_vendored::<VendoredPathBuf, String>([]);
|
||||
|
||||
Self {
|
||||
storage: salsa::Storage::default(),
|
||||
file_system: MemoryFileSystem::default(),
|
||||
system: TestSystem::default(),
|
||||
vendored: VendoredFileSystem::default(),
|
||||
events: std::sync::Arc::default(),
|
||||
vfs,
|
||||
files: Files::default(),
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
pub(crate) fn file_system(&self) -> &MemoryFileSystem {
|
||||
&self.file_system
|
||||
}
|
||||
|
||||
/// Empties the internal store of salsa events that have been emitted,
|
||||
/// and returns them as a `Vec` (equivalent to [`std::mem::take`]).
|
||||
///
|
||||
|
@ -93,22 +91,32 @@ mod tests {
|
|||
self.take_salsa_events();
|
||||
}
|
||||
|
||||
pub(crate) fn file_system_mut(&mut self) -> &mut MemoryFileSystem {
|
||||
&mut self.file_system
|
||||
}
|
||||
|
||||
pub(crate) fn vfs_mut(&mut self) -> &mut Vfs {
|
||||
&mut self.vfs
|
||||
pub(crate) fn with_vendored(&mut self, vendored_file_system: VendoredFileSystem) {
|
||||
self.vendored = vendored_file_system;
|
||||
}
|
||||
}
|
||||
|
||||
impl Db for TestDb {
|
||||
fn file_system(&self) -> &dyn FileSystem {
|
||||
&self.file_system
|
||||
fn vendored(&self) -> &VendoredFileSystem {
|
||||
&self.vendored
|
||||
}
|
||||
|
||||
fn vfs(&self) -> &Vfs {
|
||||
&self.vfs
|
||||
fn system(&self) -> &dyn System {
|
||||
&self.system
|
||||
}
|
||||
|
||||
fn files(&self) -> &Files {
|
||||
&self.files
|
||||
}
|
||||
}
|
||||
|
||||
impl DbWithTestSystem for TestDb {
|
||||
fn test_system(&self) -> &TestSystem {
|
||||
&self.system
|
||||
}
|
||||
|
||||
fn test_system_mut(&mut self) -> &mut TestSystem {
|
||||
&mut self.system
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -124,9 +132,10 @@ mod tests {
|
|||
fn snapshot(&self) -> salsa::Snapshot<Self> {
|
||||
salsa::Snapshot::new(Self {
|
||||
storage: self.storage.snapshot(),
|
||||
file_system: self.file_system.snapshot(),
|
||||
vfs: self.vfs.snapshot(),
|
||||
system: self.system.snapshot(),
|
||||
files: self.files.snapshot(),
|
||||
events: self.events.clone(),
|
||||
vendored: self.vendored.snapshot(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue