Formatting and check

This commit is contained in:
Pi Lanningham 2023-11-09 14:59:07 -05:00 committed by KtorZ
parent 689a41ded4
commit 771f6d1601
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
5 changed files with 43 additions and 32 deletions

View File

@ -47,7 +47,7 @@ pub fn exec(
match_tests,
exact_match,
no_traces,
watch,
..
}: Args,
) -> miette::Result<()> {
crate::with_project(directory, deny, |p| {

View File

@ -4,7 +4,6 @@ use clap::Parser;
pub mod blueprint;
pub mod build;
pub mod check;
pub mod watch;
pub mod completion;
pub mod docs;
pub mod fmt;
@ -13,6 +12,7 @@ pub mod new;
pub mod packages;
pub mod tx;
pub mod uplc;
pub mod watch;
/// Aiken: a smart-contract language and toolchain for Cardano
#[derive(Parser)]

View File

@ -1,5 +1,9 @@
use notify::{RecursiveMode, Watcher, Event, event::EventAttributes};
use std::{path::Path, error::Error, time::SystemTime, collections::VecDeque, sync::{Mutex, Arc}};
use notify::{event::EventAttributes, Event, RecursiveMode, Watcher};
use std::{
collections::VecDeque,
path::Path,
sync::{Arc, Mutex},
};
#[derive(clap::Args)]
/// Type-check an Aiken project
pub struct Args {
@ -9,40 +13,49 @@ pub struct Args {
}
pub fn exec(Args { clear }: Args) -> miette::Result<()> {
let project = Path::new("../sundae-contracts/aiken").to_path_buf().canonicalize().expect("");
let project = Path::new("../sundae-contracts/aiken")
.to_path_buf()
.canonicalize()
.expect("");
let build = project.join("build").canonicalize().expect("");
let lock = project.join("aiken.lock");
let queue = Arc::new(Mutex::new(VecDeque::new()));
queue.lock().unwrap().push_back(Event { kind: notify::EventKind::Any, paths: vec![], attrs: EventAttributes::new() });
queue.lock().unwrap().push_back(Event {
kind: notify::EventKind::Any,
paths: vec![],
attrs: EventAttributes::new(),
});
let queue_write = queue.clone();
let mut watcher = notify::recommended_watcher(move |res: notify::Result<Event>| {
match res {
Ok(event) => {
match event.kind {
notify::EventKind::Create(_) |
notify::EventKind::Modify(_) |
notify::EventKind::Remove(_) => {
Ok(event) => match event.kind {
notify::EventKind::Create(_)
| notify::EventKind::Modify(_)
| notify::EventKind::Remove(_) => {
let mut queue = queue_write.lock().expect("lock queue");
queue.push_back(event.clone());
drop(queue);
}
_ => {}
}
},
Err(e) => {
println!("watch error: {:?}", e)
},
}
};
}).expect("watcher");
let _ = watcher.watch(Path::new("../sundae-contracts/aiken"), RecursiveMode::Recursive);
})
.expect("watcher");
let _ = watcher.watch(
Path::new("../sundae-contracts/aiken"),
RecursiveMode::Recursive,
);
let queue_read = queue.clone();
let mut last_evt = SystemTime::UNIX_EPOCH;
loop {
std::thread::sleep(std::time::Duration::from_millis(300));
let mut queue = queue_read.lock().expect("lock queue");
let mut latest = None;
// debounce the events, and ignore build/lock changes, because they come in in large batches
while let Some(evt) = queue.pop_back() {
if evt.paths.iter().any(|p| {
let p = p.canonicalize().expect("");
@ -53,18 +66,12 @@ pub fn exec(Args { clear }: Args) -> miette::Result<()> {
latest = Some(evt);
}
drop(queue);
if let Some(evt) = latest {
if latest.is_some() {
if clear {
println!("{esc}c", esc = 27 as char);
}
let _ = crate::with_project_ok(Some(project.clone()), false, |p| {
p.check(
false,
None,
true,
false,
false.into(),
)
p.check(false, None, true, false, false.into())
});
}
}

View File

@ -96,7 +96,11 @@ where
// TODO: we probably want to rework with_project slightly to avoid duplication here,
// but this is a quick hack to get the aiken watch working
pub fn with_project_ok<A>(directory: Option<PathBuf>, deny: bool, mut action: A) -> miette::Result<()>
pub fn with_project_ok<A>(
directory: Option<PathBuf>,
deny: bool,
mut action: A,
) -> miette::Result<()>
where
A: FnMut(&mut Project<Terminal>) -> Result<(), Vec<aiken_project::error::Error>>,
{

View File

@ -1,8 +1,8 @@
use aiken::cmd::{
blueprint::{self, address},
build, check, watch, completion, docs, fmt, lsp, new,
build, check, completion, docs, fmt, lsp, new,
packages::{self, add},
tx, uplc, Cmd,
tx, uplc, watch, Cmd,
};
use aiken_project::{config, pretty};