|
@@ -104,14 +104,15 @@ pub async fn startup_hot_reload(port: u16, config: CrateConfig) -> Result<()> {
|
|
if chrono::Local::now().timestamp() > last_update_time {
|
|
if chrono::Local::now().timestamp() > last_update_time {
|
|
// Give time for the change to take effect before reading the file
|
|
// Give time for the change to take effect before reading the file
|
|
std::thread::sleep(std::time::Duration::from_millis(100));
|
|
std::thread::sleep(std::time::Duration::from_millis(100));
|
|
|
|
+ let mut updated = false;
|
|
if let Ok(evt) = evt {
|
|
if let Ok(evt) = evt {
|
|
let mut messages = Vec::new();
|
|
let mut messages = Vec::new();
|
|
let mut needs_rebuild = false;
|
|
let mut needs_rebuild = false;
|
|
for path in evt.paths.clone() {
|
|
for path in evt.paths.clone() {
|
|
- let mut file = File::open(path.clone()).unwrap();
|
|
|
|
if path.extension().map(|p| p.to_str()).flatten() != Some("rs") {
|
|
if path.extension().map(|p| p.to_str()).flatten() != Some("rs") {
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
+ let mut file = File::open(path.clone()).unwrap();
|
|
let mut src = String::new();
|
|
let mut src = String::new();
|
|
file.read_to_string(&mut src).expect("Unable to read file");
|
|
file.read_to_string(&mut src).expect("Unable to read file");
|
|
// find changes to the rsx in the file
|
|
// find changes to the rsx in the file
|
|
@@ -119,6 +120,7 @@ pub async fn startup_hot_reload(port: u16, config: CrateConfig) -> Result<()> {
|
|
let mut last_file_rebuild = last_file_rebuild.lock().unwrap();
|
|
let mut last_file_rebuild = last_file_rebuild.lock().unwrap();
|
|
if let Some(old_str) = last_file_rebuild.map.get(&path) {
|
|
if let Some(old_str) = last_file_rebuild.map.get(&path) {
|
|
if let Ok(old) = syn::parse_file(&old_str) {
|
|
if let Ok(old) = syn::parse_file(&old_str) {
|
|
|
|
+ updated = true;
|
|
match find_rsx(&syntax, &old) {
|
|
match find_rsx(&syntax, &old) {
|
|
DiffResult::CodeChanged => {
|
|
DiffResult::CodeChanged => {
|
|
needs_rebuild = true;
|
|
needs_rebuild = true;
|
|
@@ -191,7 +193,9 @@ pub async fn startup_hot_reload(port: u16, config: CrateConfig) -> Result<()> {
|
|
let _ = hot_reload_tx.send(SetManyRsxMessage(messages));
|
|
let _ = hot_reload_tx.send(SetManyRsxMessage(messages));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- last_update_time = chrono::Local::now().timestamp();
|
|
|
|
|
|
+ if updated {
|
|
|
|
+ last_update_time = chrono::Local::now().timestamp();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
},
|
|
},
|
|
notify::Config::default(),
|
|
notify::Config::default(),
|
|
@@ -419,19 +423,17 @@ pub struct PrettierOptions {
|
|
}
|
|
}
|
|
|
|
|
|
fn print_console_info(port: u16, config: &CrateConfig, options: PrettierOptions) {
|
|
fn print_console_info(port: u16, config: &CrateConfig, options: PrettierOptions) {
|
|
- print!(
|
|
|
|
- "{}",
|
|
|
|
- String::from_utf8_lossy(
|
|
|
|
- &Command::new(if cfg!(target_os = "windows") {
|
|
|
|
- "cls"
|
|
|
|
- } else {
|
|
|
|
- "clear"
|
|
|
|
- })
|
|
|
|
- .output()
|
|
|
|
- .unwrap()
|
|
|
|
- .stdout
|
|
|
|
- )
|
|
|
|
- );
|
|
|
|
|
|
+ if let Ok(native_clearseq) = Command::new(if cfg!(target_os = "windows") {
|
|
|
|
+ "cls"
|
|
|
|
+ } else {
|
|
|
|
+ "clear"
|
|
|
|
+ })
|
|
|
|
+ .output() {
|
|
|
|
+ print!("{}", String::from_utf8_lossy(&native_clearseq.stdout));
|
|
|
|
+ } else {
|
|
|
|
+ // Try ANSI-Escape characters
|
|
|
|
+ print!("\x1b[2J\x1b[H");
|
|
|
|
+ }
|
|
|
|
|
|
// for path in &changed {
|
|
// for path in &changed {
|
|
// let path = path
|
|
// let path = path
|