WIP update templates

This commit is contained in:
= 2022-12-18 21:00:31 -06:00
parent 15ec138320
commit 6da1b531bb
4 changed files with 212 additions and 65 deletions

166
Cargo.lock generated
View file

@ -29,6 +29,17 @@ dependencies = [
"opaque-debug", "opaque-debug",
] ]
[[package]]
name = "ahash"
version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47"
dependencies = [
"getrandom 0.2.8",
"once_cell",
"version_check",
]
[[package]] [[package]]
name = "aho-corasick" name = "aho-corasick"
version = "0.7.20" version = "0.7.20"
@ -598,6 +609,40 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "darling"
version = "0.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0dd3cd20dc6b5a876612a6e5accfe7f3dd883db6d07acfbf14c128f61550dfa"
dependencies = [
"darling_core",
"darling_macro",
]
[[package]]
name = "darling_core"
version = "0.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a784d2ccaf7c98501746bf0be29b2022ba41fd62a2e622af997a03e9f972859f"
dependencies = [
"fnv",
"ident_case",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "darling_macro"
version = "0.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7618812407e9402654622dd402b0a89dff9ba93badd6540781526117b92aab7e"
dependencies = [
"darling_core",
"quote",
"syn",
]
[[package]] [[package]]
name = "data-encoding" name = "data-encoding"
version = "2.3.3" version = "2.3.3"
@ -630,6 +675,8 @@ dependencies = [
"colored 2.0.0", "colored 2.0.0",
"convert_case", "convert_case",
"ctrlc", "ctrlc",
"dioxus-core",
"dioxus-html",
"dioxus-rsx", "dioxus-rsx",
"dirs 4.0.0", "dirs 4.0.0",
"fern", "fern",
@ -661,12 +708,43 @@ dependencies = [
"zip 0.6.3", "zip 0.6.3",
] ]
[[package]]
name = "dioxus-core"
version = "0.2.1"
dependencies = [
"anyhow",
"bumpalo",
"futures-channel",
"futures-util",
"indexmap",
"log",
"longest-increasing-subsequence",
"rustc-hash",
"serde",
"slab",
"smallbox",
]
[[package]]
name = "dioxus-html"
version = "0.2.1"
dependencies = [
"async-trait",
"dioxus-core",
"dioxus-rsx",
"enumset",
"euclid",
"keyboard-types",
"serde",
"serde_repr",
]
[[package]] [[package]]
name = "dioxus-rsx" name = "dioxus-rsx"
version = "0.0.1" version = "0.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dbbc06efd42a94671472910bd5aeb55b28d0d2683d30dfc6af0508917478beb5"
dependencies = [ dependencies = [
"dioxus-core",
"internment",
"proc-macro2", "proc-macro2",
"quote", "quote",
"serde", "serde",
@ -737,6 +815,37 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "enumset"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "19be8061a06ab6f3a6cf21106c873578bf01bd42ad15e0311a9c76161cb1c753"
dependencies = [
"enumset_derive",
]
[[package]]
name = "enumset_derive"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03e7b551eba279bf0fa88b83a46330168c1560a52a94f5126f892f0b364ab3e0"
dependencies = [
"darling",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "euclid"
version = "0.22.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b52c2ef4a78da0ba68fbe1fd920627411096d2ac478f7f4c9f3a54ba6705bade"
dependencies = [
"num-traits",
"serde",
]
[[package]] [[package]]
name = "failure" name = "failure"
version = "0.1.8" version = "0.1.8"
@ -996,6 +1105,9 @@ name = "hashbrown"
version = "0.12.3" version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
dependencies = [
"ahash",
]
[[package]] [[package]]
name = "headers" name = "headers"
@ -1206,6 +1318,12 @@ version = "2.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005"
[[package]]
name = "ident_case"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
[[package]] [[package]]
name = "idna" name = "idna"
version = "0.2.3" version = "0.2.3"
@ -1278,6 +1396,16 @@ dependencies = [
"cfg-if", "cfg-if",
] ]
[[package]]
name = "internment"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a798d7677f07d6f1e77be484ea8626ddb1566194de399f1206306820c406371"
dependencies = [
"hashbrown",
"parking_lot",
]
[[package]] [[package]]
name = "ipconfig" name = "ipconfig"
version = "0.3.1" version = "0.3.1"
@ -1338,6 +1466,17 @@ dependencies = [
"wasm-bindgen", "wasm-bindgen",
] ]
[[package]]
name = "keyboard-types"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b7668b7cff6a51fe61cdde64cd27c8a220786f399501b57ebe36f7d8112fd68"
dependencies = [
"bitflags",
"serde",
"unicode-segmentation",
]
[[package]] [[package]]
name = "kqueue" name = "kqueue"
version = "1.0.7" version = "1.0.7"
@ -1422,6 +1561,12 @@ dependencies = [
"cfg-if", "cfg-if",
] ]
[[package]]
name = "longest-increasing-subsequence"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3bd0dd2cd90571056fdb71f6275fada10131182f84899f4b2a916e565d81d86"
[[package]] [[package]]
name = "lru-cache" name = "lru-cache"
version = "0.1.2" version = "0.1.2"
@ -2227,6 +2372,17 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "serde_repr"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fe39d9fbb0ebf5eb2c7cb7e2a47e4f462fad1379f1166b8ae49ad9eae89a7ca"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "serde_urlencoded" name = "serde_urlencoded"
version = "0.7.1" version = "0.7.1"
@ -2296,6 +2452,12 @@ dependencies = [
"autocfg", "autocfg",
] ]
[[package]]
name = "smallbox"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4679d6eef28b85020158619fc09769de89e90886c5de7157587d87cb72648faa"
[[package]] [[package]]
name = "smallvec" name = "smallvec"
version = "1.10.0" version = "1.10.0"

View file

@ -72,7 +72,10 @@ mlua = { version = "0.8.1", features = [
"macros", "macros",
] } ] }
ctrlc = "3.2.3" ctrlc = "3.2.3"
dioxus-rsx = "0.0.1" # dioxus-rsx = "0.0.1"
dioxus-rsx = { path = "/home/evan/Desktop/github/dioxus/packages/rsx" }
dioxus-html = { path = "/home/evan/Desktop/github/dioxus/packages/html" }
dioxus-core = { path = "/home/evan/Desktop/github/dioxus/packages/core" }
[[bin]] [[bin]]
path = "src/main.rs" path = "src/main.rs"

View file

@ -9,6 +9,7 @@ use std::{path::PathBuf, sync::Arc};
use super::BuildManager; use super::BuildManager;
pub use crate::hot_reload::{find_rsx, DiffResult}; pub use crate::hot_reload::{find_rsx, DiffResult};
use crate::CrateConfig; use crate::CrateConfig;
use dioxus_core::Template;
pub use proc_macro2::TokenStream; pub use proc_macro2::TokenStream;
pub use std::collections::HashMap; pub use std::collections::HashMap;
pub use std::sync::Mutex; pub use std::sync::Mutex;
@ -20,7 +21,7 @@ use syn::spanned::Spanned;
use tokio::sync::broadcast; use tokio::sync::broadcast;
pub struct HotReloadState { pub struct HotReloadState {
pub messages: broadcast::Sender<String>, pub messages: broadcast::Sender<Template<'static>>,
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,
@ -171,14 +172,3 @@ pub async fn hot_reload_handler(
hot_reload_handle.await.unwrap(); hot_reload_handle.await.unwrap();
}) })
} }
// pub fn get_location(crate_path: &Path, path: &Path, ts: TokenStream) -> CodeLocation {
// let span = ts.span().start();
// let relative = path.strip_prefix(crate_path).unwrap();
// CodeLocation::Dynamic(Box::new(OwnedCodeLocation {
// file_path: relative.display().to_string(),
// crate_path: crate_path.display().to_string(),
// line: span.line as u32,
// column: span.column as u32 + 1,
// }))
// }

View file

@ -8,7 +8,8 @@ use axum::{
}; };
use cargo_metadata::diagnostic::Diagnostic; use cargo_metadata::diagnostic::Diagnostic;
use colored::Colorize; use colored::Colorize;
// use dioxus_rsx::try_parse_template; use dioxus_core::Template;
use dioxus_rsx::CallBody;
use notify::{RecommendedWatcher, Watcher}; use notify::{RecommendedWatcher, Watcher};
use syn::spanned::Spanned; use syn::spanned::Spanned;
@ -116,7 +117,7 @@ pub async fn startup_hot_reload(port: u16, config: CrateConfig) -> Result<()> {
std::thread::sleep(std::time::Duration::from_millis(100)); std::thread::sleep(std::time::Duration::from_millis(100));
let mut updated = false; let mut updated = false;
if let Ok(evt) = evt { if let Ok(evt) = evt {
let mut messages = Vec::new(); let mut messages: Vec<Template<'static>> = Vec::new();
let mut needs_rebuild = false; let mut needs_rebuild = false;
for path in evt.paths.clone() { for path in evt.paths.clone() {
if path.extension().map(|p| p.to_str()).flatten() != Some("rs") { if path.extension().map(|p| p.to_str()).flatten() != Some("rs") {
@ -138,55 +139,46 @@ 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 old_start = old.span().start();
// &crate_dir,
// &path.to_path_buf(),
// old.to_token_stream(),
// );
// // get the original source code to preserve whitespace
// let span = new.span();
// let start = span.start();
// let end = span.end();
// let mut lines: Vec<_> = src
// .lines()
// .skip(start.line - 1)
// .take(end.line - start.line + 1)
// .collect();
// if let Some(first) = lines.first_mut() {
// *first = first.split_at(start.column).1;
// }
// 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 start.line == end.line {
// *last = last
// .split_at(end.column - start.column)
// .0;
// } else {
// *last = last.split_at(end.column).0;
// }
// }
// let rsx = lines.join("\n");
// let old_dyn_ctx = try_parse_template( if let (Ok(old_call_body), Ok(new_call_body)) = (
// &format!("{}", old.tokens), syn::parse2::<CallBody>(old.tokens),
// hr.to_owned(), syn::parse2::<CallBody>(new),
// None, ) {
// ) let spndbg = format!(
// .map(|(_, old_dyn_ctx)| old_dyn_ctx); "{:?}",
// // if let Ok((template, _)) = try_parse_template( old_call_body.roots[0].span()
// // &rsx, );
// // hr.to_owned(), let root_col =
// // old_dyn_ctx.ok(), spndbg[9..].split("..").next().unwrap();
// // ) { if let Ok(file) = path.strip_prefix(&crate_dir)
// // messages.push(SetTemplateMsg( {
// // TemplateId(hr), let line = old_start.line;
// // template, let column = old_start.column;
// // )); let location = file.display().to_string()
// // } else { + ":"
// // needs_rebuild = true; + &line.to_string()
// // } + ":"
// } + &column.to_string()
+ ":"
+ root_col;
if let Some(template) = new_call_body
.update_template(
Some(old_call_body),
Box::leak(
location.into_boxed_str(),
),
)
{
messages.push(template);
} else {
needs_rebuild = true;
}
}
}
}
} }
} }
} }