dev: log vfs on didChanged (#1311) (#1332)

This commit is contained in:
Myriad-Dreamin 2025-02-20 00:47:16 +08:00 committed by GitHub
parent 803cc1ffaf
commit 497c82588d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 65 additions and 24 deletions

View file

@ -352,6 +352,10 @@ impl<M: PathAccessModel + Sized> Vfs<M> {
}
}
pub fn display(&self) -> DisplayVfs<M> {
DisplayVfs { inner: self }
}
/// Reads a file.
pub fn read(&self, fid: TypstFileId) -> FileResult<Bytes> {
let bytes = self.managed.lock().slot(fid, |entry| entry.bytes.clone());
@ -431,6 +435,20 @@ impl<M: PathAccessModel + Sized> Vfs<M> {
}
}
pub struct DisplayVfs<'a, M: PathAccessModel + Sized> {
inner: &'a Vfs<M>,
}
impl<M: PathAccessModel + Sized> fmt::Debug for DisplayVfs<'_, M> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Vfs")
.field("revision", &self.inner.revision)
.field("managed", &self.inner.managed.lock().display())
.field("paths", &self.inner.paths.lock().display())
.finish()
}
}
pub struct RevisingVfs<'a, M: PathAccessModel + Sized> {
inner: &'a mut Vfs<M>,
managed: EntryMap,
@ -581,6 +599,20 @@ impl EntryMap {
res
}
}
fn display(&self) -> DisplayEntryMap {
DisplayEntryMap { map: self }
}
}
pub struct DisplayEntryMap<'a> {
map: &'a EntryMap,
}
impl fmt::Debug for DisplayEntryMap<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_map().entries(self.map.entries.iter()).finish()
}
}
#[derive(Debug, Clone, Default)]
@ -600,6 +632,20 @@ impl PathMap {
fn remove(&mut self, path: &Path) -> Option<Vec<TypstFileId>> {
self.paths.remove(path)
}
fn display(&self) -> DisplayPathMap {
DisplayPathMap { map: self }
}
}
pub struct DisplayPathMap<'a> {
map: &'a PathMap,
}
impl fmt::Debug for DisplayPathMap<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_map().entries(self.map.paths.iter()).finish()
}
}
/// Convert a byte slice to a string, removing UTF-8 BOM if present.