Merge remote-tracking branch 'origin/master' into run-session

This commit is contained in:
Nicolas Abril 2023-05-09 16:52:16 +02:00
commit e95be4715a
7 changed files with 34 additions and 18 deletions

View File

@ -62,6 +62,9 @@ pub struct Cli {
#[arg(long)]
pub hide_deps: bool,
#[arg(long)]
pub get_deps: bool,
/// Entrypoint of the file that makes the erasure checker
/// not remove the entry.
#[arg(short, long)]
@ -179,6 +182,7 @@ pub fn run_cli(config: Cli) -> anyhow::Result<()> {
config.hide_vals,
mode,
config.hide_deps,
config.get_deps
);
let root = config.root.unwrap_or_else(|| PathBuf::from("."));

View File

@ -174,7 +174,7 @@ pub fn run_in_session<T>(
) -> anyhow::Result<T> {
let (rx, tx) = std::sync::mpsc::channel();
let mut session = Session::new(root, rx);
let mut session = Session::new(root, rx, render_config.show_immediate_deps);
log(&session, &Log::Empty);
log(&session, &Log::Checking(format!("The file '{}'", file)));

View File

@ -182,7 +182,7 @@ fn parse_and_store_book_by_identifier(
}
match ident_to_path(&session.root, ident, true) {
Ok(Some(path)) => parse_and_store_book_by_path(session, &path, book),
Ok(Some(path)) => parse_and_store_book_by_path(session, &path, book, false),
Ok(None) => false,
Err(err) => {
session.diagnostic_sender.send(err).unwrap();
@ -191,7 +191,7 @@ fn parse_and_store_book_by_identifier(
}
}
fn parse_and_store_book_by_path(session: &mut Session, path: &PathBuf, book: &mut Book) -> bool {
fn parse_and_store_book_by_path(session: &mut Session, path: &PathBuf, book: &mut Book, immediate: bool) -> bool {
if !path.exists() {
let err = Box::new(DriverDiagnostic::CannotFindFile(
path.to_str().unwrap().to_string(),
@ -237,6 +237,11 @@ fn parse_and_store_book_by_path(session: &mut Session, path: &PathBuf, book: &mu
for idents in state.unbound_top_level.values() {
let fst = idents.iter().next().unwrap();
if immediate && session.show_immediate_deps {
println!("{}", fst);
}
if !book.names.contains_key(&fst.to_string()) {
failed |= parse_and_store_book_by_identifier(session, fst, book);
}
@ -265,7 +270,7 @@ fn unbound_variable(session: &mut Session, book: &Book, idents: &[Ident]) {
pub fn parse_and_store_book(session: &mut Session, path: &PathBuf) -> anyhow::Result<Book> {
let mut book = Book::default();
if parse_and_store_book_by_path(session, path, &mut book) {
if parse_and_store_book_by_path(session, path, &mut book, true) {
Err(ResolutionError.into())
} else {
Ok(book)

View File

@ -24,10 +24,12 @@ pub struct Session {
pub root: PathBuf,
pub book_counter: usize,
pub show_immediate_deps: bool,
}
impl Session {
pub fn new(root: PathBuf, sender: Sender<Box<dyn Diagnostic>>) -> Session {
pub fn new(root: PathBuf, sender: Sender<Box<dyn Diagnostic>>, show_immediate_deps: bool) -> Session {
Session {
loaded_paths: Vec::new(),
loaded_sources: Vec::new(),
@ -36,6 +38,7 @@ impl Session {
root,
book_counter: 0,
diagnostic_sender: sender,
show_immediate_deps
}
}
pub fn add_path(&mut self, path: Rc<PathBuf>, code: String) -> usize {

View File

@ -55,39 +55,43 @@ pub struct RenderConfig<'a> {
pub mode: Mode,
pub not_align: bool,
pub only_main: bool,
pub show_immediate_deps: bool,
}
impl<'a> RenderConfig<'a> {
pub fn unicode(indent: usize, hide_vals: bool, only_main: bool) -> RenderConfig<'a> {
pub fn unicode(indent: usize, hide_vals: bool, only_main: bool, show_immediate_deps: bool) -> RenderConfig<'a> {
RenderConfig {
chars: Chars::unicode(),
indent,
hide_vals,
mode: Mode::Classic,
not_align: false,
only_main
only_main,
show_immediate_deps
}
}
pub fn ascii(indent: usize, hide_vals: bool, only_main: bool) -> RenderConfig<'a> {
pub fn ascii(indent: usize, hide_vals: bool, only_main: bool, show_immediate_deps: bool) -> RenderConfig<'a> {
RenderConfig {
chars: Chars::ascii(),
indent,
hide_vals,
mode: Mode::Classic,
not_align: false,
only_main
only_main,
show_immediate_deps
}
}
pub fn compact(indent: usize, only_main: bool) -> RenderConfig<'a> {
pub fn compact(indent: usize, only_main: bool, show_immediate_deps: bool) -> RenderConfig<'a> {
RenderConfig {
chars: Chars::ascii(),
indent,
hide_vals: true,
mode: Mode::Compact,
not_align: true,
only_main
only_main,
show_immediate_deps
}
}
}
@ -98,15 +102,15 @@ pub fn check_if_colors_are_supported(disable: bool) {
}
}
pub fn check_if_utf8_is_supported<'a>(disable: bool, indent: usize, hide_vals: bool, mode: Mode, only_main: bool) -> RenderConfig<'a> {
pub fn check_if_utf8_is_supported<'a>(disable: bool, indent: usize, hide_vals: bool, mode: Mode, only_main: bool, show_immediate_deps: bool) -> RenderConfig<'a> {
match mode {
Mode::Classic => {
if disable || (cfg!(windows) && !Paint::enable_windows_ascii()) {
RenderConfig::ascii(indent, hide_vals, only_main)
RenderConfig::ascii(indent, hide_vals, only_main, show_immediate_deps)
} else {
RenderConfig::unicode(indent, hide_vals, only_main)
RenderConfig::unicode(indent, hide_vals, only_main, show_immediate_deps)
}
},
Mode::Compact => RenderConfig::compact(0, only_main),
Mode::Compact => RenderConfig::compact(0, only_main, show_immediate_deps),
}
}

View File

@ -15,7 +15,7 @@ fn new_session() -> Session {
let root = PathBuf::from("./suite/lib").canonicalize().unwrap();
Session::new(root, rx)
Session::new(root, rx, false)
}
fn exp_paths() -> Vec<&'static str> {

View File

@ -35,12 +35,12 @@ fn test_kind2(path: &Path, run: fn(&PathBuf, &mut Session) -> Option<String>) ->
golden_test(path, &|path| {
let (rx, tx) = std::sync::mpsc::channel();
let root = PathBuf::from("./suite/lib").canonicalize().unwrap();
let mut session = Session::new(root, rx);
let mut session = Session::new(root, rx, false);
let res = run(&PathBuf::from(path), &mut session);
let diagnostics = tx.try_iter().collect::<Vec<Box<dyn Diagnostic>>>();
let render = RenderConfig::ascii(2, false, false);
let render = RenderConfig::ascii(2, false, false, false);
kind_report::check_if_colors_are_supported(true);