diff --git a/src/wasm-lib/kcl/src/errors.rs b/src/wasm-lib/kcl/src/errors.rs index 99f110a917..3168f75ff4 100644 --- a/src/wasm-lib/kcl/src/errors.rs +++ b/src/wasm-lib/kcl/src/errors.rs @@ -150,7 +150,7 @@ impl KclErrorWithOutputs { source_files: Default::default(), } } - pub fn into_miette_report_with_outputs(self, code: &str) -> anyhow::Result { + pub fn into_miette_report_with_outputs(self) -> anyhow::Result { let mut source_ranges = self.error.source_ranges(); // Pop off the first source range to get the filename. @@ -162,33 +162,23 @@ impl KclErrorWithOutputs { .source_files .get(&first_source_range.module_id()) .cloned() - .unwrap_or(ModuleSource { - source: code.to_string(), - path: self - .filenames - .get(&first_source_range.module_id()) - .ok_or_else(|| { - anyhow::anyhow!( - "Could not find filename for module id: {:?}", - first_source_range.module_id() - ) - })? - .clone(), - }); + .ok_or_else(|| { + anyhow::anyhow!( + "Could not find source file for module id: {:?}", + first_source_range.module_id() + ) + })?; let filename = source.path.to_string(); let kcl_source = source.source.to_string(); let mut related = Vec::new(); for source_range in source_ranges { let module_id = source_range.module_id(); - let source = self.source_files.get(&module_id).cloned().unwrap_or(ModuleSource { - source: code.to_string(), - path: self - .filenames - .get(&module_id) - .ok_or_else(|| anyhow::anyhow!("Could not find filename for module id: {:?}", module_id))? - .clone(), - }); + let source = self + .source_files + .get(&module_id) + .cloned() + .ok_or_else(|| anyhow::anyhow!("Could not find source file for module id: {:?}", module_id))?; let error = self.error.override_source_ranges(vec![source_range]); let report = Report { error, diff --git a/src/wasm-lib/kcl/src/execution/mod.rs b/src/wasm-lib/kcl/src/execution/mod.rs index 8d77e1682f..2769562ce3 100644 --- a/src/wasm-lib/kcl/src/execution/mod.rs +++ b/src/wasm-lib/kcl/src/execution/mod.rs @@ -532,6 +532,7 @@ impl ExecutorContext { } } + exec_state.add_root_module_contents(&program); let result = self.inner_run(&program.ast, &mut exec_state, true).await?; // Restore any temporary variables, then save any newly created variables back to @@ -585,9 +586,15 @@ impl ExecutorContext { .await .is_err() { - (true, program.ast) + (true, program) } else { - (clear_scene, changed_program) + ( + clear_scene, + crate::Program { + ast: changed_program, + original_file_contents: program.original_file_contents, + }, + ) } } CacheResult::NoAction(true) => { @@ -608,7 +615,7 @@ impl ExecutorContext { return Ok(old_state.to_wasm_outcome(result_env)); } - (true, program.ast) + (true, program) } CacheResult::NoAction(false) => return Ok(old_state.to_wasm_outcome(result_env)), }; @@ -636,10 +643,11 @@ impl ExecutorContext { self.send_clear_scene(&mut exec_state, Default::default()) .await .map_err(KclErrorWithOutputs::no_outputs)?; - (program.ast, exec_state, false) + (program, exec_state, false) }; - let result = self.inner_run(&program, &mut exec_state, preserve_mem).await; + exec_state.add_root_module_contents(&program); + let result = self.inner_run(&program.ast, &mut exec_state, preserve_mem).await; if result.is_err() { cache::bust_cache().await; @@ -650,7 +658,7 @@ impl ExecutorContext { // Save this as the last successful execution to the cache. cache::write_old_ast(OldAstState { - ast: program, + ast: program.ast, exec_state: exec_state.clone(), settings: self.settings.clone(), result_env: result.0, @@ -691,6 +699,7 @@ impl ExecutorContext { self.send_clear_scene(exec_state, Default::default()) .await .map_err(KclErrorWithOutputs::no_outputs)?; + exec_state.add_root_module_contents(program); self.inner_run(&program.ast, exec_state, false).await } diff --git a/src/wasm-lib/kcl/src/execution/state.rs b/src/wasm-lib/kcl/src/execution/state.rs index 4c1b581a6b..dade43cf57 100644 --- a/src/wasm-lib/kcl/src/execution/state.rs +++ b/src/wasm-lib/kcl/src/execution/state.rs @@ -182,8 +182,27 @@ impl ExecState { self.global.path_to_source_id.insert(path.clone(), id); } + pub(crate) fn add_root_module_contents(&mut self, program: &crate::Program) { + let root_id = ModuleId::default(); + // Get the path for the root module. + let path = self + .global + .path_to_source_id + .iter() + .find(|(_, v)| **v == root_id) + .unwrap() + .0 + .clone(); + self.add_id_to_source( + root_id, + ModuleSource { + path, + source: program.original_file_contents.to_string(), + }, + ); + } + pub(super) fn add_id_to_source(&mut self, id: ModuleId, source: ModuleSource) { - debug_assert!(!self.global.id_to_source.contains_key(&id)); self.global.id_to_source.insert(id, source.clone()); } @@ -251,8 +270,6 @@ impl GlobalState { global .path_to_source_id .insert(ModulePath::Local { value: root_path }, root_id); - // Ideally we'd have a way to set the root module's source here, but - // we don't have a way to get the source from the executor settings. global } } diff --git a/src/wasm-lib/kcl/src/lib.rs b/src/wasm-lib/kcl/src/lib.rs index da824cf573..596c6aa8a2 100644 --- a/src/wasm-lib/kcl/src/lib.rs +++ b/src/wasm-lib/kcl/src/lib.rs @@ -134,6 +134,11 @@ use crate::log::{log, logln}; pub struct Program { #[serde(flatten)] pub ast: parsing::ast::types::Node, + // The ui doesn't need to know about this. + // It's purely used for saving the contents of the original file, so we can use it for errors. + // Because in the case of the root file, we don't want to read the file from disk again. + #[serde(skip)] + pub original_file_contents: String, } #[cfg(any(test, feature = "lsp-test-util"))] @@ -147,7 +152,13 @@ impl Program { let tokens = parsing::token::lex(input, module_id)?; let (ast, errs) = parsing::parse_tokens(tokens).0?; - Ok((ast.map(|ast| Program { ast }), errs)) + Ok(( + ast.map(|ast| Program { + ast, + original_file_contents: input.to_string(), + }), + errs, + )) } pub fn parse_no_errs(input: &str) -> Result { @@ -155,7 +166,10 @@ impl Program { let tokens = parsing::token::lex(input, module_id)?; let ast = parsing::parse_tokens(tokens).parse_errs_as_err()?; - Ok(Program { ast }) + Ok(Program { + ast, + original_file_contents: input.to_string(), + }) } pub fn compute_digest(&mut self) -> parsing::ast::digest::Digest { @@ -168,9 +182,10 @@ impl Program { } /// Change the meta settings for the kcl file. - pub fn change_meta_settings(&mut self, settings: crate::MetaSettings) -> Result { + pub fn change_meta_settings(&self, settings: crate::MetaSettings) -> Result { Ok(Self { ast: self.ast.change_meta_settings(settings)?, + original_file_contents: self.original_file_contents.clone(), }) } @@ -192,12 +207,6 @@ impl Program { } } -impl From> for Program { - fn from(ast: parsing::ast::types::Node) -> Program { - Self { ast } - } -} - #[inline] fn try_f64_to_usize(f: f64) -> Option { let i = f as usize; diff --git a/src/wasm-lib/kcl/src/lsp/kcl/mod.rs b/src/wasm-lib/kcl/src/lsp/kcl/mod.rs index adafacc882..be0dfc3864 100644 --- a/src/wasm-lib/kcl/src/lsp/kcl/mod.rs +++ b/src/wasm-lib/kcl/src/lsp/kcl/mod.rs @@ -46,7 +46,7 @@ use crate::{ errors::Suggestion, lsp::{backend::Backend as _, util::IntoDiagnostic}, parsing::{ - ast::types::{Expr, Node, VariableKind}, + ast::types::{Expr, VariableKind}, token::TokenStream, PIPE_OPERATOR, }, @@ -102,7 +102,7 @@ pub struct Backend { /// Token maps. pub(super) token_map: DashMap, /// AST maps. - pub ast_map: DashMap>, + pub ast_map: DashMap, /// Current code. pub code_map: DashMap>, /// Diagnostics. @@ -327,11 +327,17 @@ impl crate::lsp::backend::Backend for Backend { // this if it backfires and only hork the LSP. ast.compute_digest(); + // Save it as a program. + let ast = crate::Program { + ast, + original_file_contents: params.text.clone(), + }; + // Check if the ast changed. let ast_changed = match self.ast_map.get(&filename) { Some(old_ast) => { // Check if the ast changed. - *old_ast != ast + *old_ast.ast != *ast.ast } None => true, }; @@ -346,7 +352,7 @@ impl crate::lsp::backend::Backend for Backend { // Update the symbols map. self.symbols_map.insert( params.uri.to_string(), - ast.get_lsp_symbols(¶ms.text).unwrap_or_default(), + ast.ast.get_lsp_symbols(¶ms.text).unwrap_or_default(), ); // Update our semantic tokens. @@ -361,14 +367,14 @@ impl crate::lsp::backend::Backend for Backend { // Only send the notification if we can execute. // Otherwise it confuses the client. self.client - .send_notification::(ast.clone()) + .send_notification::(ast.ast.clone()) .await; } // Execute the code if we have an executor context. // This function automatically executes if we should & updates the diagnostics if we got // errors. - if self.execute(¶ms, &ast.into()).await.is_err() { + if self.execute(¶ms, &ast).await.is_err() { return; } @@ -421,7 +427,7 @@ impl Backend { let token_modifiers_bitset = if let Some(ast) = self.ast_map.get(params.uri.as_str()) { let token_index = Arc::new(Mutex::new(token_type_index)); let modifier_index: Arc> = Arc::new(Mutex::new(0)); - crate::walk::walk(&ast, |node: crate::walk::Node| { + crate::walk::walk(&ast.ast, |node: crate::walk::Node| { let Ok(node_range): Result = (&node).try_into() else { return Ok(true); }; @@ -1021,7 +1027,7 @@ impl LanguageServer for Backend { return Ok(None); }; - let Some(hover) = ast.get_hover_value_for_position(pos, current_code) else { + let Some(hover) = ast.ast.get_hover_value_for_position(pos, current_code) else { return Ok(None); }; @@ -1150,13 +1156,13 @@ impl LanguageServer for Backend { }; let position = position_to_char_index(params.text_document_position.position, current_code); - if ast.get_non_code_meta_for_position(position).is_some() { + if ast.ast.get_non_code_meta_for_position(position).is_some() { // If we are in a code comment we don't want to show completions. return Ok(None); } // Get the completion items for the ast. - let Ok(variables) = ast.completion_items() else { + let Ok(variables) = ast.ast.completion_items() else { return Ok(Some(CompletionResponse::Array(completions))); }; @@ -1211,7 +1217,7 @@ impl LanguageServer for Backend { return Ok(None); }; - let Some(value) = ast.get_expr_for_position(pos) else { + let Some(value) = ast.ast.get_expr_for_position(pos) else { return Ok(None); }; @@ -1360,7 +1366,7 @@ impl LanguageServer for Backend { }; // Get the folding ranges. - let folding_ranges = ast.get_lsp_folding_ranges(); + let folding_ranges = ast.ast.get_lsp_folding_ranges(); if folding_ranges.is_empty() { return Ok(None); diff --git a/src/wasm-lib/kcl/src/lsp/tests.rs b/src/wasm-lib/kcl/src/lsp/tests.rs index ebf86ead87..6596a3abc9 100644 --- a/src/wasm-lib/kcl/src/lsp/tests.rs +++ b/src/wasm-lib/kcl/src/lsp/tests.rs @@ -1138,7 +1138,7 @@ fn myFn = (param1) => { // Get the ast. let ast = server.ast_map.get("file:///test.kcl").unwrap().clone(); - assert!(ast != Node::::default()); + assert!(ast.ast != Node::::default()); // Send semantic tokens request. let semantic_tokens = server @@ -2251,7 +2251,7 @@ part001 = cube([0,0], 20) // Get the ast. let ast = server.ast_map.get("file:///test.kcl").unwrap().clone(); - assert_eq!(ast.body.len(), 2); + assert_eq!(ast.ast.body.len(), 2); // Send change file. server @@ -2428,7 +2428,7 @@ async fn kcl_test_kcl_lsp_full_to_empty_file_updates_ast_and_memory() { // Get the ast. let ast = server.ast_map.get("file:///test.kcl").unwrap().clone(); - assert!(ast != Node::::default()); + assert!(ast.ast != Node::::default()); // Send change file. server @@ -2450,7 +2450,7 @@ async fn kcl_test_kcl_lsp_full_to_empty_file_updates_ast_and_memory() { // Get the ast. let ast = server.ast_map.get("file:///test.kcl").unwrap().clone(); - assert_eq!(ast, default_hashed); + assert_eq!(ast.ast, default_hashed); } #[tokio::test(flavor = "multi_thread")] @@ -2479,7 +2479,7 @@ async fn kcl_test_kcl_lsp_code_unchanged_but_has_diagnostics_reexecute() { // Get the ast. let ast = server.ast_map.get("file:///test.kcl").unwrap().clone(); - assert!(ast != Node::::default()); + assert!(ast.ast != Node::::default()); // Assure we have no diagnostics. assert_diagnostic_count(server.diagnostics_map.get("file:///test.kcl").as_deref(), 0); @@ -2506,11 +2506,15 @@ async fn kcl_test_kcl_lsp_code_unchanged_but_has_diagnostics_reexecute() { assert_diagnostic_count(server.diagnostics_map.get("file:///test.kcl").as_deref(), 1); // Clear the ast and memory. - server - .ast_map - .insert("file:///test.kcl".to_string(), Node::::default()); + server.ast_map.insert( + "file:///test.kcl".to_string(), + crate::Program { + ast: Default::default(), + original_file_contents: Default::default(), + }, + ); let ast = server.ast_map.get("file:///test.kcl").unwrap().clone(); - assert_eq!(ast, Node::::default()); + assert_eq!(ast.ast, Node::::default()); // Send change file, but the code is the same. server @@ -2529,7 +2533,7 @@ async fn kcl_test_kcl_lsp_code_unchanged_but_has_diagnostics_reexecute() { // Get the ast. let ast = server.ast_map.get("file:///test.kcl").unwrap().clone(); - assert!(ast != Node::::default()); + assert!(ast.ast != Node::::default()); // Assure we have no diagnostics. assert_diagnostic_count(server.diagnostics_map.get("file:///test.kcl").as_deref(), 0); @@ -2561,7 +2565,7 @@ async fn kcl_test_kcl_lsp_code_and_ast_unchanged_but_has_diagnostics_reexecute() // Get the ast. let ast = server.ast_map.get("file:///test.kcl").unwrap().clone(); - assert!(ast != Node::::default()); + assert!(ast.ast != Node::::default()); // Assure we have no diagnostics. assert_diagnostic_count(server.diagnostics_map.get("file:///test.kcl").as_deref(), 0); @@ -2604,7 +2608,7 @@ async fn kcl_test_kcl_lsp_code_and_ast_unchanged_but_has_diagnostics_reexecute() // Get the ast. let ast = server.ast_map.get("file:///test.kcl").unwrap().clone(); - assert!(ast != Node::::default()); + assert!(ast.ast != Node::::default()); // Assure we have no diagnostics. assert_diagnostic_count(server.diagnostics_map.get("file:///test.kcl").as_deref(), 0); @@ -2636,7 +2640,7 @@ async fn kcl_test_kcl_lsp_code_and_ast_units_unchanged_but_has_diagnostics_reexe // Get the ast. let ast = server.ast_map.get("file:///test.kcl").unwrap().clone(); - assert!(ast != Node::::default()); + assert!(ast.ast != Node::::default()); // Assure we have no diagnostics. assert_diagnostic_count(server.diagnostics_map.get("file:///test.kcl").as_deref(), 0); @@ -2682,7 +2686,7 @@ async fn kcl_test_kcl_lsp_code_and_ast_units_unchanged_but_has_diagnostics_reexe // Get the ast. let ast = server.ast_map.get("file:///test.kcl").unwrap().clone(); - assert!(ast != Node::::default()); + assert!(ast.ast != Node::::default()); // Assure we have no diagnostics. assert_diagnostic_count(server.diagnostics_map.get("file:///test.kcl").as_deref(), 0); @@ -2714,7 +2718,7 @@ async fn kcl_test_kcl_lsp_code_and_ast_units_unchanged_but_has_memory_reexecute_ // Get the ast. let ast = server.ast_map.get("file:///test.kcl").unwrap().clone(); - assert!(ast != Node::::default()); + assert!(ast.ast != Node::::default()); // Assure we have no diagnostics. assert_diagnostic_count(server.diagnostics_map.get("file:///test.kcl").as_deref(), 0); @@ -2739,7 +2743,7 @@ async fn kcl_test_kcl_lsp_code_and_ast_units_unchanged_but_has_memory_reexecute_ // Get the ast. let ast = server.ast_map.get("file:///test.kcl").unwrap().clone(); - assert!(ast != Node::::default()); + assert!(ast.ast != Node::::default()); // Assure we have no diagnostics. assert_diagnostic_count(server.diagnostics_map.get("file:///test.kcl").as_deref(), 0); @@ -2771,7 +2775,7 @@ async fn kcl_test_kcl_lsp_cant_execute_set() { // Get the ast. let ast = server.ast_map.get("file:///test.kcl").unwrap().clone(); - assert!(ast != Node::::default()); + assert!(ast.ast != Node::::default()); // Assure we have no diagnostics. assert_diagnostic_count(server.diagnostics_map.get("file:///test.kcl").as_deref(), 0); @@ -2795,7 +2799,7 @@ async fn kcl_test_kcl_lsp_cant_execute_set() { // Get the ast. let ast = server.ast_map.get("file:///test.kcl").unwrap().clone(); - assert!(ast != Node::::default()); + assert!(ast.ast != Node::::default()); // Assure we have no diagnostics. assert_diagnostic_count(server.diagnostics_map.get("file:///test.kcl").as_deref(), 0); @@ -2831,7 +2835,7 @@ async fn kcl_test_kcl_lsp_cant_execute_set() { // Get the ast. let ast = server.ast_map.get("file:///test.kcl").unwrap().clone(); - assert!(ast != default_hashed); + assert!(ast.ast != default_hashed); // Assure we have no diagnostics. assert_diagnostic_count(server.diagnostics_map.get("file:///test.kcl").as_deref(), 0); @@ -2862,7 +2866,7 @@ async fn kcl_test_kcl_lsp_cant_execute_set() { // Get the ast. let ast = server.ast_map.get("file:///test.kcl").unwrap().clone(); - assert!(ast != Node::::default()); + assert!(ast.ast != Node::::default()); // Assure we have no diagnostics. assert_diagnostic_count(server.diagnostics_map.get("file:///test.kcl").as_deref(), 0); @@ -2995,7 +2999,7 @@ part001 = startSketchOn('XY') // Get the ast. let ast = server.ast_map.get("file:///test.kcl").unwrap().clone(); - assert!(ast != Node::::default()); + assert!(ast.ast != Node::::default()); // Assure we have one diagnostics. assert_diagnostic_count(server.diagnostics_map.get("file:///test.kcl").as_deref(), 1); @@ -3016,7 +3020,7 @@ part001 = startSketchOn('XY') // Get the ast. let ast = server.ast_map.get("file:///test.kcl").unwrap().clone(); - assert!(ast != Node::::default()); + assert!(ast.ast != Node::::default()); // Assure we have one diagnostics. assert_diagnostic_count(server.diagnostics_map.get("file:///test.kcl").as_deref(), 1); @@ -3109,7 +3113,7 @@ part001 = startSketchOn('XY') // Get the ast. let ast = server.ast_map.get("file:///test.kcl").unwrap().clone(); - assert!(ast != Node::::default()); + assert!(ast.ast != Node::::default()); // Send change file, but the code is the same. server @@ -3128,7 +3132,7 @@ part001 = startSketchOn('XY') // Get the ast. let ast = server.ast_map.get("file:///test.kcl").unwrap().clone(); - assert!(ast != Node::::default()); + assert!(ast.ast != Node::::default()); // Assure we have diagnostics. @@ -3168,7 +3172,7 @@ part001 = startSketchOn('XY') // Get the ast. let ast = server.ast_map.get("file:///test.kcl").unwrap().clone(); - assert!(ast != Node::::default()); + assert!(ast.ast != Node::::default()); // Send change file, but the code is the same. server @@ -3195,7 +3199,7 @@ NEW_LINT = 1"# // Get the ast. let ast = server.ast_map.get("file:///test.kcl").unwrap().clone(); - assert!(ast != Node::::default()); + assert!(ast.ast != Node::::default()); // Assure we have diagnostics. @@ -3302,7 +3306,7 @@ part001 = startSketchOn('XY') // Get the ast. let ast = server.ast_map.get("file:///test.kcl").unwrap().clone(); - assert!(ast != Node::::default()); + assert!(ast.ast != Node::::default()); // Get the symbols map. let symbols_map = server.symbols_map.get("file:///test.kcl").unwrap().clone(); @@ -3389,7 +3393,7 @@ part001 = startSketchOn('XY') // Get the ast. let ast = server.ast_map.get("file:///test.kcl").unwrap().clone(); - assert!(ast != Node::::default()); + assert!(ast.ast != Node::::default()); // Get the symbols map. let symbols_map = server.symbols_map.get("file:///test.kcl").unwrap().clone(); @@ -3428,7 +3432,7 @@ part001 = startSketchOn('XY') // Get the ast. let ast = server.ast_map.get("file:///test.kcl").unwrap().clone(); - assert!(ast != Node::::default()); + assert!(ast.ast != Node::::default()); // Get the symbols map. let symbols_map = server.symbols_map.get("file:///test.kcl").unwrap().clone(); diff --git a/src/wasm-lib/kcl/src/parsing/ast/modify.rs b/src/wasm-lib/kcl/src/parsing/ast/modify.rs index d176d1eea8..b5feb5dd65 100644 --- a/src/wasm-lib/kcl/src/parsing/ast/modify.rs +++ b/src/wasm-lib/kcl/src/parsing/ast/modify.rs @@ -182,9 +182,7 @@ pub async fn modify_ast_for_sketch( let recasted = program.ast.recast(&FormatOptions::default(), 0); // Re-parse the ast so we get the correct source ranges. - *program = crate::parsing::parse_str(&recasted, module_id) - .parse_errs_as_err()? - .into(); + program.ast = crate::parsing::parse_str(&recasted, module_id).parse_errs_as_err()?; Ok(recasted) } diff --git a/src/wasm-lib/kcl/src/parsing/ast/types/mod.rs b/src/wasm-lib/kcl/src/parsing/ast/types/mod.rs index 0217b96f77..cc07ada482 100644 --- a/src/wasm-lib/kcl/src/parsing/ast/types/mod.rs +++ b/src/wasm-lib/kcl/src/parsing/ast/types/mod.rs @@ -275,7 +275,7 @@ impl Node { Ok(None) } - pub fn change_meta_settings(&mut self, settings: crate::execution::MetaSettings) -> Result { + pub fn change_meta_settings(&self, settings: crate::execution::MetaSettings) -> Result { let mut new_program = self.clone(); let mut found = false; for node in &mut new_program.inner_attrs { @@ -4035,7 +4035,7 @@ startSketchOn('XY')"#; let some_program_string = r#"@settings(defaultLengthUnit = inch) startSketchOn('XY')"#; - let mut program = crate::parsing::top_level_parse(some_program_string).unwrap(); + let program = crate::parsing::top_level_parse(some_program_string).unwrap(); let result = program.meta_settings().unwrap(); assert!(result.is_some()); let meta_settings = result.unwrap(); @@ -4077,7 +4077,7 @@ startSketchOn('XY') #[tokio::test(flavor = "multi_thread")] async fn test_parse_get_meta_settings_nothing_to_mm() { let some_program_string = r#"startSketchOn('XY')"#; - let mut program = crate::parsing::top_level_parse(some_program_string).unwrap(); + let program = crate::parsing::top_level_parse(some_program_string).unwrap(); let result = program.meta_settings().unwrap(); assert!(result.is_none()); diff --git a/src/wasm-lib/kcl/src/simulation_tests.rs b/src/wasm-lib/kcl/src/simulation_tests.rs index 1af448257f..e2ea794c81 100644 --- a/src/wasm-lib/kcl/src/simulation_tests.rs +++ b/src/wasm-lib/kcl/src/simulation_tests.rs @@ -84,10 +84,14 @@ async fn execute(test_name: &str, render_to_png: bool) { let Ok(ast) = ast_res else { return; }; + let ast = crate::Program { + ast, + original_file_contents: read("input.kcl", test_name), + }; // Run the program. let exec_res = crate::test_server::execute_and_snapshot_ast( - ast.into(), + ast, crate::settings::types::UnitLength::Mm, Some(Path::new("tests").join(test_name).join("input.kcl").to_owned()), ) @@ -132,10 +136,7 @@ async fn execute(test_name: &str, render_to_png: bool) { Box::new(miette::MietteHandlerOpts::new().show_related_errors_as_nested().build()) })) .unwrap(); - let report = error - .clone() - .into_miette_report_with_outputs(&read("input.kcl", test_name)) - .unwrap(); + let report = error.clone().into_miette_report_with_outputs().unwrap(); let report = miette::Report::new(report); if previously_passed { eprintln!("This test case failed, but it previously passed. If this is intended, and the test should actually be failing now, please delete kcl/{ok_path_str} and other associated passing artifacts"); diff --git a/src/wasm-lib/src/wasm.rs b/src/wasm-lib/src/wasm.rs index a3855d3f48..5f8bcd4103 100644 --- a/src/wasm-lib/src/wasm.rs +++ b/src/wasm-lib/src/wasm.rs @@ -561,7 +561,7 @@ pub fn change_kcl_settings(code: &str, settings_str: &str) -> Result