use super::VfsPath;
use crop::Rope;
use solar_interface::data_structures::map::rustc_hash::FxHashMap;
#[derive(Default)]
pub(crate) struct Vfs {
data: FxHashMap<VfsPath, Rope>,
dirty: bool,
}
impl Vfs {
pub(crate) fn set_file_contents(&mut self, path: VfsPath, contents: Option<Rope>) {
if let Some(contents) = contents {
self.data.insert(path, contents);
} else {
self.data.remove(&path);
}
self.dirty = true;
}
pub(crate) fn get_file_contents(&self, path: &VfsPath) -> Option<&Rope> {
self.data.get(path)
}
pub(crate) fn exists(&self, path: &VfsPath) -> bool {
self.data.contains_key(path)
}
#[expect(dead_code, reason = "VFS dirty state is scaffolded for future incremental analysis")]
pub(crate) fn is_dirty(&self) -> bool {
self.dirty
}
pub(crate) fn mark_clean(&mut self) -> bool {
let was_dirty = self.dirty;
self.dirty = false;
was_dirty
}
pub(crate) fn iter(&self) -> impl Iterator<Item = (&VfsPath, &Rope)> {
self.data.iter()
}
}