mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-29 20:34:44 +00:00
feat: display progress
This commit is contained in:
parent
60ea11aa3e
commit
948a14b1af
4 changed files with 41 additions and 2 deletions
|
@ -170,6 +170,7 @@ pub struct ErgConfig {
|
||||||
/// verbosity level for system messages.
|
/// verbosity level for system messages.
|
||||||
/// * 0: display errors, warns
|
/// * 0: display errors, warns
|
||||||
/// * 1 (default): display errors, warnings and hints
|
/// * 1 (default): display errors, warnings and hints
|
||||||
|
/// * 2: display errors, warnings, hints and progress
|
||||||
pub verbose: u8,
|
pub verbose: u8,
|
||||||
/// needed for `jupyter-erg`
|
/// needed for `jupyter-erg`
|
||||||
pub ps1: &'static str,
|
pub ps1: &'static str,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::fs::{metadata, remove_file, File};
|
use std::fs::{metadata, remove_file, File};
|
||||||
use std::io::{BufRead, BufReader};
|
use std::io::{stdout, BufRead, BufReader, Write};
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::option::Option;
|
use std::option::Option;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
@ -829,10 +829,33 @@ impl<ASTBuilder: ASTBuildable, HIRBuilder: Buildable>
|
||||||
|
|
||||||
fn build_deps_and_module(&mut self, path: &NormalizedPathBuf, graph: &mut ModuleGraph) {
|
fn build_deps_and_module(&mut self, path: &NormalizedPathBuf, graph: &mut ModuleGraph) {
|
||||||
let mut ancestors = graph.ancestors(path).into_vec();
|
let mut ancestors = graph.ancestors(path).into_vec();
|
||||||
|
let nmods = ancestors.len();
|
||||||
|
let pad = nmods.to_string().len();
|
||||||
|
let print_progress =
|
||||||
|
nmods > 0 && !self.cfg.mode.is_language_server() && self.cfg.verbose >= 2;
|
||||||
|
if print_progress && !self.inlines.contains_key(path) {
|
||||||
|
let mut out = stdout().lock();
|
||||||
|
write!(out, "Checking 0/{nmods}").unwrap();
|
||||||
|
out.flush().unwrap();
|
||||||
|
}
|
||||||
while let Some(ancestor) = ancestors.pop() {
|
while let Some(ancestor) = ancestors.pop() {
|
||||||
if graph.ancestors(&ancestor).is_empty() {
|
if graph.ancestors(&ancestor).is_empty() {
|
||||||
graph.remove(&ancestor);
|
graph.remove(&ancestor);
|
||||||
if let Some(entry) = self.asts.remove(&ancestor) {
|
if let Some(entry) = self.asts.remove(&ancestor) {
|
||||||
|
if print_progress {
|
||||||
|
let name = ancestor.file_name().unwrap_or_default().to_string_lossy();
|
||||||
|
let checked = nmods - ancestors.len();
|
||||||
|
let percentage = (checked as f64 / nmods as f64) * 100.0;
|
||||||
|
let spaces = " ".repeat(((100.0 - percentage) / 5.0) as usize);
|
||||||
|
let eqs = "=".repeat((percentage / 5.0) as usize);
|
||||||
|
let mut out = stdout().lock();
|
||||||
|
write!(
|
||||||
|
out,
|
||||||
|
"\rChecking [{eqs}{spaces}] {checked:>pad$}/{nmods}: {name:<30}"
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
out.flush().unwrap();
|
||||||
|
}
|
||||||
self.start_analysis_process(entry.ast, entry.name, ancestor);
|
self.start_analysis_process(entry.ast, entry.name, ancestor);
|
||||||
} else {
|
} else {
|
||||||
self.build_inlined_module(&ancestor, graph);
|
self.build_inlined_module(&ancestor, graph);
|
||||||
|
@ -841,6 +864,9 @@ impl<ASTBuilder: ASTBuildable, HIRBuilder: Buildable>
|
||||||
ancestors.insert(0, ancestor);
|
ancestors.insert(0, ancestor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if print_progress {
|
||||||
|
println!();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_inlined_module(&mut self, path: &NormalizedPathBuf, graph: &mut ModuleGraph) {
|
fn build_inlined_module(&mut self, path: &NormalizedPathBuf, graph: &mut ModuleGraph) {
|
||||||
|
|
|
@ -3,10 +3,20 @@
|
||||||
.NamedTuple = 'namedtuple': ClassType
|
.NamedTuple = 'namedtuple': ClassType
|
||||||
.NamedTuple.
|
.NamedTuple.
|
||||||
__call__: (typename: Str, field_names: Sequence(Str), rename := Bool) -> (*Obj, **Obj) -> NamedTuple
|
__call__: (typename: Str, field_names: Sequence(Str), rename := Bool) -> (*Obj, **Obj) -> NamedTuple
|
||||||
.Deque = 'deque': ClassType
|
.Deque! = 'deque': ClassType
|
||||||
|
.Deque!.
|
||||||
|
__call__: (iterable := Iterable(Obj)) -> Deque!
|
||||||
.ChainMap: ClassType
|
.ChainMap: ClassType
|
||||||
|
.ChainMap.
|
||||||
|
maps: [Mapping; _]
|
||||||
|
__call__: (*maps: Mapping(Obj, Obj)) -> ChainMap
|
||||||
|
new_child: (m := Mapping(Obj, Obj), **kwargs: Obj) -> ChainMap
|
||||||
.Counter: ClassType
|
.Counter: ClassType
|
||||||
|
.Counter.
|
||||||
|
__call__: (iterable_or_mapping := Iterable(Obj) or Mapping(Obj, Obj), **kwargs: Obj) -> Counter
|
||||||
.OrderedDict: ClassType
|
.OrderedDict: ClassType
|
||||||
|
.OrderedDict.
|
||||||
|
__call__: (mapping: Mapping(Obj, Obj)) -> OrderedDict
|
||||||
.Defaultdict = 'defaultDict': ClassType
|
.Defaultdict = 'defaultDict': ClassType
|
||||||
.UserDict: ClassType
|
.UserDict: ClassType
|
||||||
.UserList: ClassType
|
.UserList: ClassType
|
||||||
|
|
|
@ -138,6 +138,7 @@ impl SharedPromises {
|
||||||
self.promises.borrow().get(path).is_some()
|
self.promises.borrow().get(path).is_some()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// If the path is not registered, return `false`.
|
||||||
pub fn is_joined(&self, path: &NormalizedPathBuf) -> bool {
|
pub fn is_joined(&self, path: &NormalizedPathBuf) -> bool {
|
||||||
self.promises
|
self.promises
|
||||||
.borrow()
|
.borrow()
|
||||||
|
@ -145,6 +146,7 @@ impl SharedPromises {
|
||||||
.is_some_and(|promise| promise.is_joined())
|
.is_some_and(|promise| promise.is_joined())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// If the path is not registered, return `false`.
|
||||||
pub fn is_finished(&self, path: &NormalizedPathBuf) -> bool {
|
pub fn is_finished(&self, path: &NormalizedPathBuf) -> bool {
|
||||||
self.promises
|
self.promises
|
||||||
.borrow()
|
.borrow()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue