fix: disable hotreloaidng stuff

This commit is contained in:
Jonathan Kelley 2022-12-11 12:54:17 -08:00
parent aa05dc3054
commit 7d49f71cd5
4 changed files with 87 additions and 92 deletions

3
Cargo.lock generated
View file

@ -561,7 +561,7 @@ dependencies = [
[[package]] [[package]]
name = "dioxus-cli" name = "dioxus-cli"
version = "0.2.0" version = "0.2.1"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"atty", "atty",
@ -574,7 +574,6 @@ dependencies = [
"colored 2.0.0", "colored 2.0.0",
"convert_case", "convert_case",
"ctrlc", "ctrlc",
"dioxus-core",
"dioxus-rsx", "dioxus-rsx",
"dirs 4.0.0", "dirs 4.0.0",
"fern", "fern",

View file

@ -1,6 +1,6 @@
[package] [package]
name = "dioxus-cli" name = "dioxus-cli"
version = "0.2.0" version = "0.2.1"
authors = ["Jonathan Kelley"] authors = ["Jonathan Kelley"]
edition = "2021" edition = "2021"
description = "CLI tool for developing, testing, and publishing Dioxus apps" description = "CLI tool for developing, testing, and publishing Dioxus apps"
@ -58,8 +58,6 @@ zip = "0.6.2"
tower = "0.4.12" tower = "0.4.12"
syn = { version = "1.0", features = ["full", "extra-traits"] } syn = { version = "1.0", features = ["full", "extra-traits"] }
dioxus-core = { git = "https://github.com/dioxuslabs/dioxus/" }
dioxus-rsx = { git = "https://github.com/dioxuslabs/dioxus/" } dioxus-rsx = { git = "https://github.com/dioxuslabs/dioxus/" }
proc-macro2 = { version = "1.0", features = ["span-locations"] } proc-macro2 = { version = "1.0", features = ["span-locations"] }

View file

@ -2,7 +2,6 @@ use axum::{
extract::{ws::Message, Extension, TypedHeader, WebSocketUpgrade}, extract::{ws::Message, Extension, TypedHeader, WebSocketUpgrade},
response::IntoResponse, response::IntoResponse,
}; };
use dioxus_core::{prelude::TemplateId, CodeLocation, OwnedCodeLocation, SetTemplateMsg};
use dioxus_rsx::try_parse_template; use dioxus_rsx::try_parse_template;
use std::{path::PathBuf, sync::Arc}; use std::{path::PathBuf, sync::Arc};
@ -21,7 +20,7 @@ use syn::spanned::Spanned;
use tokio::sync::broadcast; use tokio::sync::broadcast;
pub struct HotReloadState { pub struct HotReloadState {
pub messages: broadcast::Sender<SetTemplateMsg>, pub messages: broadcast::Sender<String>,
pub build_manager: Arc<BuildManager>, pub build_manager: Arc<BuildManager>,
pub last_file_rebuild: Arc<Mutex<FileMap>>, pub last_file_rebuild: Arc<Mutex<FileMap>>,
pub watcher_config: CrateConfig, pub watcher_config: CrateConfig,
@ -75,7 +74,7 @@ pub async fn hot_reload_handler(
log::info!("🔥 Hot Reload WebSocket connected"); log::info!("🔥 Hot Reload WebSocket connected");
{ {
// update any rsx calls that changed before the websocket connected. // update any rsx calls that changed before the websocket connected.
let mut messages = Vec::new(); // let mut messages = Vec::new();
{ {
log::info!("🔮 Finding updates since last compile..."); log::info!("🔮 Finding updates since last compile...");
@ -98,11 +97,11 @@ pub async fn hot_reload_handler(
if let DiffResult::RsxChanged(changed) = find_rsx(&new_file, &old_file) if let DiffResult::RsxChanged(changed) = find_rsx(&new_file, &old_file)
{ {
for (old, new) in changed.into_iter() { for (old, new) in changed.into_iter() {
let hr = get_location( // let hr = get_location(
&state.watcher_config.crate_dir, // &state.watcher_config.crate_dir,
k, // k,
old.to_token_stream(), // old.to_token_stream(),
); // );
// get the original source code to preserve whitespace // get the original source code to preserve whitespace
let span = new.span(); let span = new.span();
let start = span.start(); let start = span.start();
@ -125,32 +124,32 @@ pub async fn hot_reload_handler(
} }
let rsx = lines.join("\n"); let rsx = lines.join("\n");
let old_dyn_ctx = try_parse_template( // let old_dyn_ctx = try_parse_template(
&format!("{}", old.tokens), // &format!("{}", old.tokens),
hr.to_owned(), // hr.to_owned(),
None, // None,
) // )
.map(|(_, old_dyn_ctx)| old_dyn_ctx); // .map(|(_, old_dyn_ctx)| old_dyn_ctx);
if let Ok((template, _)) = // if let Ok((template, _)) =
try_parse_template(&rsx, hr.to_owned(), old_dyn_ctx.ok()) // try_parse_template(&rsx, hr.to_owned(), old_dyn_ctx.ok())
{ // {
messages.push(SetTemplateMsg(TemplateId(hr), template)); // // messages.push(SetTemplateMsg(TemplateId(hr), template));
} // }
} }
} }
} }
} }
} }
} }
for msg in messages { // for msg in messages {
if socket // if socket
.send(Message::Text(serde_json::to_string(&msg).unwrap())) // .send(Message::Text(serde_json::to_string(&msg).unwrap()))
.await // .await
.is_err() // .is_err()
{ // {
return; // return;
} // }
} // }
log::info!("finished"); log::info!("finished");
} }
@ -173,13 +172,13 @@ pub async fn hot_reload_handler(
}) })
} }
pub fn get_location(crate_path: &Path, path: &Path, ts: TokenStream) -> CodeLocation { // pub fn get_location(crate_path: &Path, path: &Path, ts: TokenStream) -> CodeLocation {
let span = ts.span().start(); // let span = ts.span().start();
let relative = path.strip_prefix(crate_path).unwrap(); // let relative = path.strip_prefix(crate_path).unwrap();
CodeLocation::Dynamic(Box::new(OwnedCodeLocation { // CodeLocation::Dynamic(Box::new(OwnedCodeLocation {
file_path: relative.display().to_string(), // file_path: relative.display().to_string(),
crate_path: crate_path.display().to_string(), // crate_path: crate_path.display().to_string(),
line: span.line as u32, // line: span.line as u32,
column: span.column as u32 + 1, // column: span.column as u32 + 1,
})) // }))
} // }

View file

@ -8,7 +8,6 @@ use axum::{
}; };
use cargo_metadata::diagnostic::Diagnostic; use cargo_metadata::diagnostic::Diagnostic;
use colored::Colorize; use colored::Colorize;
use dioxus_core::{prelude::TemplateId, SetTemplateMsg};
use dioxus_rsx::try_parse_template; use dioxus_rsx::try_parse_template;
use notify::{RecommendedWatcher, Watcher}; use notify::{RecommendedWatcher, Watcher};
use syn::spanned::Spanned; use syn::spanned::Spanned;
@ -139,55 +138,55 @@ pub async fn startup_hot_reload(port: u16, config: CrateConfig) -> Result<()> {
} }
DiffResult::RsxChanged(changed) => { DiffResult::RsxChanged(changed) => {
log::info!("🪁 reloading rsx"); log::info!("🪁 reloading rsx");
for (old, new) in changed.into_iter() { // for (old, new) in changed.into_iter() {
let hr = get_location( // let hr = get_location(
&crate_dir, // &crate_dir,
&path.to_path_buf(), // &path.to_path_buf(),
old.to_token_stream(), // old.to_token_stream(),
); // );
// get the original source code to preserve whitespace // // get the original source code to preserve whitespace
let span = new.span(); // let span = new.span();
let start = span.start(); // let start = span.start();
let end = span.end(); // let end = span.end();
let mut lines: Vec<_> = src // let mut lines: Vec<_> = src
.lines() // .lines()
.skip(start.line - 1) // .skip(start.line - 1)
.take(end.line - start.line + 1) // .take(end.line - start.line + 1)
.collect(); // .collect();
if let Some(first) = lines.first_mut() { // if let Some(first) = lines.first_mut() {
*first = first.split_at(start.column).1; // *first = first.split_at(start.column).1;
} // }
if let Some(last) = lines.last_mut() { // if let Some(last) = lines.last_mut() {
// if there is only one line the start index of last line will be the start of the rsx!, not the start of the line // // if there is only one line the start index of last line will be the start of the rsx!, not the start of the line
if start.line == end.line { // if start.line == end.line {
*last = last // *last = last
.split_at(end.column - start.column) // .split_at(end.column - start.column)
.0; // .0;
} else { // } else {
*last = last.split_at(end.column).0; // *last = last.split_at(end.column).0;
} // }
} // }
let rsx = lines.join("\n"); // let rsx = lines.join("\n");
let old_dyn_ctx = try_parse_template( // let old_dyn_ctx = try_parse_template(
&format!("{}", old.tokens), // &format!("{}", old.tokens),
hr.to_owned(), // hr.to_owned(),
None, // None,
) // )
.map(|(_, old_dyn_ctx)| old_dyn_ctx); // .map(|(_, old_dyn_ctx)| old_dyn_ctx);
if let Ok((template, _)) = try_parse_template( // // if let Ok((template, _)) = try_parse_template(
&rsx, // // &rsx,
hr.to_owned(), // // hr.to_owned(),
old_dyn_ctx.ok(), // // old_dyn_ctx.ok(),
) { // // ) {
messages.push(SetTemplateMsg( // // messages.push(SetTemplateMsg(
TemplateId(hr), // // TemplateId(hr),
template, // // template,
)); // // ));
} else { // // } else {
needs_rebuild = true; // // needs_rebuild = true;
} // // }
} // }
} }
} }
} }