mirror of
https://github.com/erg-lang/erg.git
synced 2025-08-04 10:49:54 +00:00
fix(els): file data inconsistencies
This commit is contained in:
parent
ca83d090a3
commit
b0959b13e7
4 changed files with 66 additions and 28 deletions
|
@ -1,3 +1,4 @@
|
|||
use std::fmt;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use erg_common::shared::Shared;
|
||||
|
@ -7,6 +8,19 @@ use erg_common::{normalize_path, set};
|
|||
#[derive(Debug, Clone, Default)]
|
||||
pub struct ModuleGraph(Graph<PathBuf, ()>);
|
||||
|
||||
impl fmt::Display for ModuleGraph {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
for node in self.0.iter() {
|
||||
writeln!(f, "{} depends on {{", node.id.display())?;
|
||||
for dep in node.depends_on.iter() {
|
||||
writeln!(f, "{}, ", dep.display())?;
|
||||
}
|
||||
writeln!(f, "}}, ")?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoIterator for ModuleGraph {
|
||||
type Item = Node<PathBuf, ()>;
|
||||
type IntoIter = std::vec::IntoIter<Self::Item>;
|
||||
|
@ -62,6 +76,11 @@ impl ModuleGraph {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn remove(&mut self, path: &Path) {
|
||||
let path = normalize_path(path.to_path_buf());
|
||||
self.0.retain(|n| n.id != path);
|
||||
}
|
||||
|
||||
pub fn initialize(&mut self) {
|
||||
self.0.clear();
|
||||
}
|
||||
|
@ -70,6 +89,12 @@ impl ModuleGraph {
|
|||
#[derive(Debug, Clone, Default)]
|
||||
pub struct SharedModuleGraph(Shared<ModuleGraph>);
|
||||
|
||||
impl fmt::Display for SharedModuleGraph {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{}", self.0.borrow())
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoIterator for SharedModuleGraph {
|
||||
type Item = Node<PathBuf, ()>;
|
||||
type IntoIter = std::vec::IntoIter<Self::Item>;
|
||||
|
@ -104,6 +129,10 @@ impl SharedModuleGraph {
|
|||
ref_graph.iter()
|
||||
}
|
||||
|
||||
pub fn remove(&self, path: &Path) {
|
||||
self.0.borrow_mut().remove(path);
|
||||
}
|
||||
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn sort(&self) -> Result<(), TopoSortError> {
|
||||
self.0.borrow_mut().sort()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue