mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 06:11:43 +00:00
[red-knot] Simplify virtual file support (#13043)
## Summary This PR simplifies the virtual file support in the red knot core, specifically: * Update `File::add_virtual_file` method to `File::virtual_file` which will always create a new virtual file and override the existing entry in the lookup table * Add `VirtualFile` which is a wrapper around `File` and provides methods to increment the file revision / close the virtual file * Add a new `File::try_virtual_file` to lookup the `VirtualFile` from `Files` * Add `File::sync_virtual_path` which takes in the `SystemVirtualPath`, looks up the `VirtualFile` for it and calls the `sync` method to increment the file revision * Removes the `virtual_path_metadata` method on `System` trait ## Test Plan - [x] Make sure the existing red knot tests pass - [x] Updated code works well with the LSP
This commit is contained in:
parent
21c5606793
commit
551ed2706b
8 changed files with 71 additions and 94 deletions
|
@ -136,22 +136,6 @@ impl MemoryFileSystem {
|
|||
ruff_notebook::Notebook::from_source_code(&content)
|
||||
}
|
||||
|
||||
pub(crate) fn virtual_path_metadata(
|
||||
&self,
|
||||
path: impl AsRef<SystemVirtualPath>,
|
||||
) -> Result<Metadata> {
|
||||
let virtual_files = self.inner.virtual_files.read().unwrap();
|
||||
let file = virtual_files
|
||||
.get(&path.as_ref().to_path_buf())
|
||||
.ok_or_else(not_found)?;
|
||||
|
||||
Ok(Metadata {
|
||||
revision: file.last_modified.into(),
|
||||
permissions: Some(MemoryFileSystem::PERMISSION),
|
||||
file_type: FileType::File,
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn read_virtual_path_to_string(
|
||||
&self,
|
||||
path: impl AsRef<SystemVirtualPath>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue