Browse Source

Merge pull request #48 from Demonthos/fix_path_seperator

fix path separator for hot reloading
YuKun Liu 3 years ago
parent
commit
a0a8b8b2d3
2 changed files with 7 additions and 3 deletions
  1. 6 3
      src/server/hot_reload.rs
  2. 1 0
      src/server/mod.rs

+ 6 - 3
src/server/hot_reload.rs

@@ -97,6 +97,7 @@ pub async fn hot_reload_handler(
                             if let DiffResult::RsxChanged(changed) = find_rsx(&new_file, &old_file) {
                                 for (old, new) in changed.into_iter() {
                                     let hr = get_location(
+                                        &state.watcher_config.crate_dir,
                                         k,
                                         old.to_token_stream(),
                                     );
@@ -150,7 +151,7 @@ pub async fn hot_reload_handler(
                                 let error: Error = serde_json::from_str(&err).unwrap();
                                 match error{
                                     Error::ParseError(parse_error) => {
-                                        log::error!("parse error:\n--> at {}:{}:{}\n\t{:?}", parse_error.location.file, parse_error.location.line, parse_error.location.column, parse_error.message);
+                                        log::error!("parse error:\n--> at {}:{}:{}\n\t{:?}", parse_error.location.file_path, parse_error.location.line, parse_error.location.column, parse_error.message);
                                     },
                                     Error::RecompileRequiredError(_) => {
                                         if let Err(err) = state.build_manager.build(){
@@ -182,10 +183,12 @@ pub async fn hot_reload_handler(
     })
 }
 
-pub fn get_location(path: &Path, ts: TokenStream) -> CodeLocation {
+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 {
-        file: path.display().to_string(),
+        file_path: relative.display().to_string(),
+        crate_path: crate_path.display().to_string(),
         line: span.line as u32,
         column: span.column as u32 + 1,
     }

+ 1 - 0
src/server/mod.rs

@@ -121,6 +121,7 @@ pub async fn startup_hot_reload(port: u16, config: CrateConfig) -> Result<()> {
                                         log::info!("reloading rsx");
                                         for (old, new) in changed.into_iter() {
                                             let hr = get_location(
+                                                &crate_dir,
                                                 &path.to_path_buf(),
                                                 old.to_token_stream(),
                                             );