diff --git a/CHANGELOG.md b/CHANGELOG.md index c9f14d7b..2e646ab5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,6 +64,7 @@ Enhancements * `Scope::remove` is added to remove a variable from a `Scope`, returning its value. * The code base is cleaner by running it through Clippy. * `ParseError::err_type` and `ParseError::position` are added for convenience. +* The source of an `AST` compiled from a script file is set to the file's path. Version 1.8.0 diff --git a/src/api/files.rs b/src/api/files.rs index 17bd324c..ad2bbeae 100644 --- a/src/api/files.rs +++ b/src/api/files.rs @@ -106,7 +106,11 @@ impl Engine { /// ``` #[inline] pub fn compile_file_with_scope(&self, scope: &Scope, path: PathBuf) -> RhaiResultOf { - Self::read_file(path).and_then(|contents| Ok(self.compile_with_scope(scope, &contents)?)) + Self::read_file(&path).and_then(|contents| { + let mut ast = self.compile_with_scope(scope, &contents)?; + ast.set_source(path.to_string_lossy()); + Ok(ast) + }) } /// Evaluate a script file, returning the result value or an error. ///