Răsfoiți Sursa

Merge branch 'master' into master

YuKun Liu 2 ani în urmă
părinte
comite
0e8414b40a
3 a modificat fișierele cu 57 adăugiri și 43 ștergeri
  1. 1 1
      Cargo.toml
  2. 12 9
      src/builder.rs
  3. 44 33
      src/server/mod.rs

+ 1 - 1
Cargo.toml

@@ -25,7 +25,7 @@ toml = "0.5.8"
 fs_extra = "1.2.0"
 cargo_toml = "0.11.4"
 futures = "0.3.21"
-notify = { version = "5.0.0-pre.13", features = ["serde"] }
+notify = { version = "5.0.0-pre.16", features = ["serde"] }
 html_parser = "0.6.2"
 binary-install = "0.0.2"
 convert_case = "0.5.0"

+ 12 - 9
src/builder.rs

@@ -152,10 +152,7 @@ pub fn build(config: &CrateConfig, quiet: bool) -> Result<BuildResult> {
                         if config.release == true {
                             args.push("-Oz");
                         }
-                        binaryen.call(
-                            "wasm-opt",
-                            args,
-                        )?;
+                        binaryen.call("wasm-opt", args)?;
                     }
                 }
             }
@@ -177,11 +174,11 @@ pub fn build(config: &CrateConfig, quiet: bool) -> Result<BuildResult> {
 
                 let input_path = match sub.get("input") {
                     Some(val) => val.as_str().unwrap(),
-                    None => "./public"
+                    None => "./public",
                 };
                 let config_path = match sub.get("config") {
                     Some(val) => val.as_str().unwrap(),
-                    None => "./src/tailwind.config.js"
+                    None => "./src/tailwind.config.js",
                 };
                 let mut args = vec![
                     "-i",
@@ -189,13 +186,13 @@ pub fn build(config: &CrateConfig, quiet: bool) -> Result<BuildResult> {
                     "-o",
                     "dist/tailwind.css",
                     "-c",
-                    config_path
+                    config_path,
                 ];
 
                 if config.release == true {
                     args.push("--minify");
                 }
-                
+
                 tailwind.call("tailwindcss", args)?;
             }
         } else {
@@ -459,7 +456,13 @@ pub fn gen_page(config: &DioxusConfig, serve: bool) -> String {
             &style.to_str().unwrap(),
         ))
     }
-    if config.application.tools.clone().unwrap_or_default().contains_key("tailwindcss") {
+    if config
+        .application
+        .tools
+        .clone()
+        .unwrap_or_default()
+        .contains_key("tailwindcss")
+    {
         style_str.push_str("<link rel=\"stylesheet\" href=\"tailwind.css\">\n");
     }
     html = html.replace("{style_include}", &style_str);

+ 44 - 33
src/server/mod.rs

@@ -151,47 +151,58 @@ pub async fn startup_hot_reload(port: u16, config: CrateConfig) -> Result<()> {
                                                 } else {
                                                     *last = last.split_at(end.column).0;
                                                 }
+                                                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");
+                                                messages.push(SetRsxMessage {
+                                                    location: hr,
+                                                    new_text: rsx,
+                                                });
                                             }
-                                            let rsx = lines.join("\n");
-                                            messages.push(SetRsxMessage {
-                                                location: hr,
-                                                new_text: rsx,
-                                            });
                                         }
                                     }
                                 }
+                            } else {
+                                // if this is a new file, rebuild the project
+                                *last_file_rebuild = FileMap::new(crate_dir.clone());
                             }
-                        } else {
-                            // if this is a new file, rebuild the project
-                            *last_file_rebuild = FileMap::new(crate_dir.clone());
                         }
                     }
-                }
-                if needs_rebuild {
-                    match build_manager.rebuild() {
-                        Ok(res) => {
-                            print_console_info(
-                                port,
-                                &config,
-                                PrettierOptions {
-                                    changed: evt.paths,
-                                    warnings: res.warnings,
-                                    elapsed_time: res.elapsed_time,
-                                },
-                            );
-                        }
-                        Err(err) => {
-                            log::error!("{}", err);
+                    if needs_rebuild {
+                        match build_manager.rebuild() {
+                            Ok(res) => {
+                                print_console_info(
+                                    port,
+                                    &config,
+                                    PrettierOptions {
+                                        changed: evt.paths,
+                                        warnings: res.warnings,
+                                        elapsed_time: res.elapsed_time,
+                                    },
+                                );
+                            }
+                            Err(err) => {
+                                log::error!("{}", err);
+                            }
                         }
                     }
+                    if !messages.is_empty() {
+                        let _ = hot_reload_tx.send(SetManyRsxMessage(messages));
+                    }
                 }
-                if !messages.is_empty() {
-                    let _ = hot_reload_tx.send(SetManyRsxMessage(messages));
-                }
+                last_update_time = chrono::Local::now().timestamp();
             }
-            last_update_time = chrono::Local::now().timestamp();
-        }
-    })
+        },
+        notify::Config::default(),
+    )
     .unwrap();
 
     for sub_path in allow_watch_path {
@@ -321,11 +332,11 @@ pub async fn startup_default(port: u16, config: CrateConfig) -> Result<()> {
                             },
                         );
                     }
-                    Err(e) => log::error!("{}", e),
                 }
             }
-        }
-    })
+        },
+        notify::Config::default(),
+    )
     .unwrap();
 
     for sub_path in allow_watch_path {