mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-11-25 21:37:32 +00:00
parent
803cc1ffaf
commit
497c82588d
5 changed files with 65 additions and 24 deletions
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue