diff --git a/e2e/playwright/snapshot-tests.spec.ts-snapshots/Client-side-scene-scale-should-match-engine-scale-Inch-scale-2-Google-Chrome-linux.png b/e2e/playwright/snapshot-tests.spec.ts-snapshots/Client-side-scene-scale-should-match-engine-scale-Inch-scale-2-Google-Chrome-linux.png index d44a1e1f2..bc89343e8 100644 Binary files a/e2e/playwright/snapshot-tests.spec.ts-snapshots/Client-side-scene-scale-should-match-engine-scale-Inch-scale-2-Google-Chrome-linux.png and b/e2e/playwright/snapshot-tests.spec.ts-snapshots/Client-side-scene-scale-should-match-engine-scale-Inch-scale-2-Google-Chrome-linux.png differ diff --git a/e2e/playwright/snapshot-tests.spec.ts-snapshots/Client-side-scene-scale-should-match-engine-scale-Millimeter-scale-2-Google-Chrome-linux.png b/e2e/playwright/snapshot-tests.spec.ts-snapshots/Client-side-scene-scale-should-match-engine-scale-Millimeter-scale-2-Google-Chrome-linux.png index 8645d7d49..13650e5de 100644 Binary files a/e2e/playwright/snapshot-tests.spec.ts-snapshots/Client-side-scene-scale-should-match-engine-scale-Millimeter-scale-2-Google-Chrome-linux.png and b/e2e/playwright/snapshot-tests.spec.ts-snapshots/Client-side-scene-scale-should-match-engine-scale-Millimeter-scale-2-Google-Chrome-linux.png differ diff --git a/e2e/playwright/snapshot-tests.spec.ts-snapshots/Zoom-to-fit-on-load---solid-2d-1-Google-Chrome-linux.png b/e2e/playwright/snapshot-tests.spec.ts-snapshots/Zoom-to-fit-on-load---solid-2d-1-Google-Chrome-linux.png index 3bb852179..01b92cd8e 100644 Binary files a/e2e/playwright/snapshot-tests.spec.ts-snapshots/Zoom-to-fit-on-load---solid-2d-1-Google-Chrome-linux.png and b/e2e/playwright/snapshot-tests.spec.ts-snapshots/Zoom-to-fit-on-load---solid-2d-1-Google-Chrome-linux.png differ diff --git a/e2e/playwright/snapshot-tests.spec.ts-snapshots/Zoom-to-fit-on-load---solid-3d-1-Google-Chrome-linux.png b/e2e/playwright/snapshot-tests.spec.ts-snapshots/Zoom-to-fit-on-load---solid-3d-1-Google-Chrome-linux.png index a6f65f72b..b8011d5bc 100644 Binary files a/e2e/playwright/snapshot-tests.spec.ts-snapshots/Zoom-to-fit-on-load---solid-3d-1-Google-Chrome-linux.png and b/e2e/playwright/snapshot-tests.spec.ts-snapshots/Zoom-to-fit-on-load---solid-3d-1-Google-Chrome-linux.png differ diff --git a/e2e/playwright/snapshot-tests.spec.ts-snapshots/code-color-goober-code-color-goober-1-Google-Chrome-linux.png b/e2e/playwright/snapshot-tests.spec.ts-snapshots/code-color-goober-code-color-goober-1-Google-Chrome-linux.png index a6a0fd1f2..15105d98a 100644 Binary files a/e2e/playwright/snapshot-tests.spec.ts-snapshots/code-color-goober-code-color-goober-1-Google-Chrome-linux.png and b/e2e/playwright/snapshot-tests.spec.ts-snapshots/code-color-goober-code-color-goober-1-Google-Chrome-linux.png differ diff --git a/src/lang/errors.test.ts b/src/lang/errors.test.ts index 9ae26011c..be0a9a31d 100644 --- a/src/lang/errors.test.ts +++ b/src/lang/errors.test.ts @@ -13,6 +13,7 @@ describe('test kclErrToDiagnostic', () => { operations: [], artifactCommands: [], artifactGraph: defaultArtifactGraph(), + filenames: {}, }, { name: '', @@ -23,6 +24,7 @@ describe('test kclErrToDiagnostic', () => { operations: [], artifactCommands: [], artifactGraph: defaultArtifactGraph(), + filenames: {}, }, ] const diagnostics = kclErrorsToDiagnostics(errors) diff --git a/src/lang/errors.ts b/src/lang/errors.ts index 238b6680d..64ec02d61 100644 --- a/src/lang/errors.ts +++ b/src/lang/errors.ts @@ -13,6 +13,7 @@ import { SourceRange, } from 'lang/wasm' import { Operation } from 'wasm-lib/kcl/bindings/Operation' +import { ModulePath } from 'wasm-lib/kcl/bindings/ModulePath' type ExtractKind = T extends { kind: infer K } ? K : never export class KCLError extends Error { @@ -22,6 +23,7 @@ export class KCLError extends Error { operations: Operation[] artifactCommands: ArtifactCommand[] artifactGraph: ArtifactGraph + filenames: { [x: number]: ModulePath | undefined } constructor( kind: ExtractKind | 'name', @@ -29,7 +31,8 @@ export class KCLError extends Error { sourceRange: SourceRange, operations: Operation[], artifactCommands: ArtifactCommand[], - artifactGraph: ArtifactGraph + artifactGraph: ArtifactGraph, + filenames: { [x: number]: ModulePath | undefined } ) { super() this.kind = kind @@ -38,6 +41,7 @@ export class KCLError extends Error { this.operations = operations this.artifactCommands = artifactCommands this.artifactGraph = artifactGraph + this.filenames = filenames Object.setPrototypeOf(this, KCLError.prototype) } } @@ -48,7 +52,8 @@ export class KCLLexicalError extends KCLError { sourceRange: SourceRange, operations: Operation[], artifactCommands: ArtifactCommand[], - artifactGraph: ArtifactGraph + artifactGraph: ArtifactGraph, + filenames: { [x: number]: ModulePath | undefined } ) { super( 'lexical', @@ -56,7 +61,8 @@ export class KCLLexicalError extends KCLError { sourceRange, operations, artifactCommands, - artifactGraph + artifactGraph, + filenames ) Object.setPrototypeOf(this, KCLSyntaxError.prototype) } @@ -68,7 +74,8 @@ export class KCLInternalError extends KCLError { sourceRange: SourceRange, operations: Operation[], artifactCommands: ArtifactCommand[], - artifactGraph: ArtifactGraph + artifactGraph: ArtifactGraph, + filenames: { [x: number]: ModulePath | undefined } ) { super( 'internal', @@ -76,7 +83,8 @@ export class KCLInternalError extends KCLError { sourceRange, operations, artifactCommands, - artifactGraph + artifactGraph, + filenames ) Object.setPrototypeOf(this, KCLSyntaxError.prototype) } @@ -88,7 +96,8 @@ export class KCLSyntaxError extends KCLError { sourceRange: SourceRange, operations: Operation[], artifactCommands: ArtifactCommand[], - artifactGraph: ArtifactGraph + artifactGraph: ArtifactGraph, + filenames: { [x: number]: ModulePath | undefined } ) { super( 'syntax', @@ -96,7 +105,8 @@ export class KCLSyntaxError extends KCLError { sourceRange, operations, artifactCommands, - artifactGraph + artifactGraph, + filenames ) Object.setPrototypeOf(this, KCLSyntaxError.prototype) } @@ -108,7 +118,8 @@ export class KCLSemanticError extends KCLError { sourceRange: SourceRange, operations: Operation[], artifactCommands: ArtifactCommand[], - artifactGraph: ArtifactGraph + artifactGraph: ArtifactGraph, + filenames: { [x: number]: ModulePath | undefined } ) { super( 'semantic', @@ -116,7 +127,8 @@ export class KCLSemanticError extends KCLError { sourceRange, operations, artifactCommands, - artifactGraph + artifactGraph, + filenames ) Object.setPrototypeOf(this, KCLSemanticError.prototype) } @@ -128,9 +140,18 @@ export class KCLTypeError extends KCLError { sourceRange: SourceRange, operations: Operation[], artifactCommands: ArtifactCommand[], - artifactGraph: ArtifactGraph + artifactGraph: ArtifactGraph, + filenames: { [x: number]: ModulePath | undefined } ) { - super('type', msg, sourceRange, operations, artifactCommands, artifactGraph) + super( + 'type', + msg, + sourceRange, + operations, + artifactCommands, + artifactGraph, + filenames + ) Object.setPrototypeOf(this, KCLTypeError.prototype) } } @@ -141,7 +162,8 @@ export class KCLUnimplementedError extends KCLError { sourceRange: SourceRange, operations: Operation[], artifactCommands: ArtifactCommand[], - artifactGraph: ArtifactGraph + artifactGraph: ArtifactGraph, + filenames: { [x: number]: ModulePath | undefined } ) { super( 'unimplemented', @@ -149,7 +171,8 @@ export class KCLUnimplementedError extends KCLError { sourceRange, operations, artifactCommands, - artifactGraph + artifactGraph, + filenames ) Object.setPrototypeOf(this, KCLUnimplementedError.prototype) } @@ -161,7 +184,8 @@ export class KCLUnexpectedError extends KCLError { sourceRange: SourceRange, operations: Operation[], artifactCommands: ArtifactCommand[], - artifactGraph: ArtifactGraph + artifactGraph: ArtifactGraph, + filenames: { [x: number]: ModulePath | undefined } ) { super( 'unexpected', @@ -169,7 +193,8 @@ export class KCLUnexpectedError extends KCLError { sourceRange, operations, artifactCommands, - artifactGraph + artifactGraph, + filenames ) Object.setPrototypeOf(this, KCLUnexpectedError.prototype) } @@ -181,7 +206,8 @@ export class KCLValueAlreadyDefined extends KCLError { sourceRange: SourceRange, operations: Operation[], artifactCommands: ArtifactCommand[], - artifactGraph: ArtifactGraph + artifactGraph: ArtifactGraph, + filenames: { [x: number]: ModulePath | undefined } ) { super( 'name', @@ -189,7 +215,8 @@ export class KCLValueAlreadyDefined extends KCLError { sourceRange, operations, artifactCommands, - artifactGraph + artifactGraph, + filenames ) Object.setPrototypeOf(this, KCLValueAlreadyDefined.prototype) } @@ -201,7 +228,8 @@ export class KCLUndefinedValueError extends KCLError { sourceRange: SourceRange, operations: Operation[], artifactCommands: ArtifactCommand[], - artifactGraph: ArtifactGraph + artifactGraph: ArtifactGraph, + filenames: { [x: number]: ModulePath | undefined } ) { super( 'name', @@ -209,7 +237,8 @@ export class KCLUndefinedValueError extends KCLError { sourceRange, operations, artifactCommands, - artifactGraph + artifactGraph, + filenames ) Object.setPrototypeOf(this, KCLUndefinedValueError.prototype) } @@ -232,7 +261,8 @@ export function lspDiagnosticsToKclErrors( [posToOffset(doc, range.start)!, posToOffset(doc, range.end)!, 0], [], [], - defaultArtifactGraph() + defaultArtifactGraph(), + {} ) ) .sort((a, b) => { diff --git a/src/lang/executor.test.ts b/src/lang/executor.test.ts index d3ad62f9b..7bd5b8934 100644 --- a/src/lang/executor.test.ts +++ b/src/lang/executor.test.ts @@ -511,7 +511,8 @@ const theExtrude = startSketchOn('XY') topLevelRange(129, 135), [], [], - defaultArtifactGraph() + defaultArtifactGraph(), + {} ) ) }) diff --git a/src/lang/wasm.ts b/src/lang/wasm.ts index 4e40569e2..457bb5e91 100644 --- a/src/lang/wasm.ts +++ b/src/lang/wasm.ts @@ -60,6 +60,7 @@ import { MetaSettings } from 'wasm-lib/kcl/bindings/MetaSettings' import { UnitAngle, UnitLength } from 'wasm-lib/kcl/bindings/ModelingCmd' import { UnitLen } from 'wasm-lib/kcl/bindings/UnitLen' import { UnitAngle as UnitAng } from 'wasm-lib/kcl/bindings/UnitAngle' +import { ModulePath } from 'wasm-lib/kcl/bindings/ModulePath' export type { Artifact } from 'wasm-lib/kcl/bindings/Artifact' export type { ArtifactCommand } from 'wasm-lib/kcl/bindings/Artifact' @@ -266,7 +267,8 @@ export const parse = (code: string | Error): ParseResult | Error => { firstSourceRange(parsed), [], [], - defaultArtifactGraph() + defaultArtifactGraph(), + {} ) } } @@ -296,6 +298,7 @@ export interface ExecState { artifactCommands: ArtifactCommand[] artifactGraph: ArtifactGraph errors: CompilationError[] + filenames: { [x: number]: ModulePath | undefined } } /** @@ -310,6 +313,7 @@ export function emptyExecState(): ExecState { artifactCommands: [], artifactGraph: defaultArtifactGraph(), errors: [], + filenames: [], } } @@ -336,6 +340,7 @@ function execStateFromRust( artifactCommands: execOutcome.artifactCommands, artifactGraph, errors: execOutcome.errors, + filenames: execOutcome.filenames, } } @@ -347,6 +352,7 @@ function mockExecStateFromRust(execOutcome: RustExecOutcome): ExecState { artifactCommands: execOutcome.artifactCommands, artifactGraph: new Map(), errors: execOutcome.errors, + filenames: execOutcome.filenames, } } @@ -474,7 +480,7 @@ const jsAppSettings = async () => { } const errFromErrWithOutputs = (e: any): KCLError => { - console.log('execute error', e) + console.log(e) const parsed: KclErrorWithOutputs = JSON.parse(e.toString()) return new KCLError( parsed.error.kind, @@ -482,7 +488,8 @@ const errFromErrWithOutputs = (e: any): KCLError => { firstSourceRange(parsed.error), parsed.operations, parsed.artifactCommands, - rustArtifactGraphToMap(parsed.artifactGraph) + rustArtifactGraphToMap(parsed.artifactGraph), + parsed.filenames ) } @@ -548,7 +555,8 @@ export const modifyAstForSketch = async ( firstSourceRange(parsed), [], [], - defaultArtifactGraph() + defaultArtifactGraph(), + {} ) return Promise.reject(kclError) diff --git a/src/wasm-lib/Cargo.toml b/src/wasm-lib/Cargo.toml index 93ea303b8..2a3d11cb6 100644 --- a/src/wasm-lib/Cargo.toml +++ b/src/wasm-lib/Cargo.toml @@ -103,3 +103,7 @@ path = "tests/modify/main.rs" #[patch.crates-io] #kittycad-modeling-cmds = { path = "../../../modeling-api/modeling-cmds" } #kittycad-modeling-session = { path = "../../../modeling-api/modeling-session" } + +# Local development only. Placeholder to speed up development cycle +#[package.metadata.wasm-pack.profile.release] +#wasm-opt = false \ No newline at end of file diff --git a/src/wasm-lib/kcl/src/errors.rs b/src/wasm-lib/kcl/src/errors.rs index bba31ccc6..a26bfc22d 100644 --- a/src/wasm-lib/kcl/src/errors.rs +++ b/src/wasm-lib/kcl/src/errors.rs @@ -2,9 +2,12 @@ use serde::{Deserialize, Serialize}; use thiserror::Error; use tower_lsp::lsp_types::{Diagnostic, DiagnosticSeverity}; +use indexmap::IndexMap; + use crate::{ execution::{ArtifactCommand, ArtifactGraph, Operation}, lsp::IntoDiagnostic, + modules::ModulePath, source_range::SourceRange, ModuleId, }; @@ -116,6 +119,7 @@ pub struct KclErrorWithOutputs { pub operations: Vec, pub artifact_commands: Vec, pub artifact_graph: ArtifactGraph, + pub filenames: IndexMap, } impl KclErrorWithOutputs { @@ -124,12 +128,14 @@ impl KclErrorWithOutputs { operations: Vec, artifact_commands: Vec, artifact_graph: ArtifactGraph, + filenames: IndexMap, ) -> Self { Self { error, operations, artifact_commands, artifact_graph, + filenames, } } pub fn no_outputs(error: KclError) -> Self { @@ -138,6 +144,7 @@ impl KclErrorWithOutputs { operations: Default::default(), artifact_commands: Default::default(), artifact_graph: Default::default(), + filenames: Default::default(), } } } diff --git a/src/wasm-lib/kcl/src/execution/exec_ast.rs b/src/wasm-lib/kcl/src/execution/exec_ast.rs index cfd158a34..0c9b13ffd 100644 --- a/src/wasm-lib/kcl/src/execution/exec_ast.rs +++ b/src/wasm-lib/kcl/src/execution/exec_ast.rs @@ -329,6 +329,8 @@ impl ExecutorContext { } let id = exec_state.next_module_id(); + // Add file path string to global state even if it fails to import + exec_state.add_path_to_source_id(resolved_path.clone(), id); let source = resolved_path.source(&self.fs, source_range).await?; // TODO handle parsing errors properly let parsed = crate::parsing::parse_str(&source, id).parse_errs_as_err()?; @@ -343,6 +345,8 @@ impl ExecutorContext { let id = exec_state.next_module_id(); let path = resolved_path.expect_path(); + // Add file path string to global state even if it fails to import + exec_state.add_path_to_source_id(resolved_path.clone(), id); let format = super::import::format_from_annotations(attrs, path, source_range)?; let geom = super::import::import_foreign(path, format, exec_state, self, source_range).await?; exec_state.add_module(id, resolved_path, ModuleRepr::Foreign(geom)); @@ -354,6 +358,8 @@ impl ExecutorContext { } let id = exec_state.next_module_id(); + // Add file path string to global state even if it fails to import + exec_state.add_path_to_source_id(resolved_path.clone(), id); let source = resolved_path.source(&self.fs, source_range).await?; let parsed = crate::parsing::parse_str(&source, id).parse_errs_as_err().unwrap(); exec_state.add_module(id, resolved_path, ModuleRepr::Kcl(parsed, None)); diff --git a/src/wasm-lib/kcl/src/execution/mod.rs b/src/wasm-lib/kcl/src/execution/mod.rs index 1b29c063a..9a63628e6 100644 --- a/src/wasm-lib/kcl/src/execution/mod.rs +++ b/src/wasm-lib/kcl/src/execution/mod.rs @@ -23,6 +23,7 @@ use crate::{ cache::{CacheInformation, CacheResult}, }, fs::FileManager, + modules::{ModuleId, ModulePath}, parsing::ast::types::{Expr, ImportPath, Node, NodeRef, Program}, settings::types::UnitLength, source_range::SourceRange, @@ -70,6 +71,8 @@ pub struct ExecOutcome { pub artifact_graph: ArtifactGraph, /// Non-fatal errors and warnings. pub errors: Vec, + /// File Names in module Id array index order + pub filenames: IndexMap, } #[derive(Debug, Default, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)] @@ -712,11 +715,19 @@ impl ExecutorContext { .execute_and_build_graph(program, exec_state, preserve_mem) .await .map_err(|e| { + let module_id_to_module_path: IndexMap = exec_state + .global + .path_to_source_id + .iter() + .map(|(k, v)| ((*v), k.clone())) + .collect(); + KclErrorWithOutputs::new( e, exec_state.mod_local.operations.clone(), exec_state.global.artifact_commands.clone(), exec_state.global.artifact_graph.clone(), + module_id_to_module_path, ) })?; diff --git a/src/wasm-lib/kcl/src/execution/state.rs b/src/wasm-lib/kcl/src/execution/state.rs index c95c56291..895dc9b1c 100644 --- a/src/wasm-lib/kcl/src/execution/state.rs +++ b/src/wasm-lib/kcl/src/execution/state.rs @@ -124,6 +124,12 @@ impl ExecState { artifact_commands: self.global.artifact_commands, artifact_graph: self.global.artifact_graph, errors: self.global.errors, + filenames: self + .global + .path_to_source_id + .iter() + .map(|(k, v)| ((*v), k.clone())) + .collect(), } } @@ -141,6 +147,7 @@ impl ExecState { artifact_commands: Default::default(), artifact_graph: Default::default(), errors: self.global.errors, + filenames: Default::default(), } } @@ -169,11 +176,13 @@ impl ExecState { self.global.path_to_source_id.get(path).cloned() } - pub(super) fn add_module(&mut self, id: ModuleId, path: ModulePath, repr: ModuleRepr) { + pub(super) fn add_path_to_source_id(&mut self, path: ModulePath, id: ModuleId) { debug_assert!(!self.global.path_to_source_id.contains_key(&path)); - self.global.path_to_source_id.insert(path.clone(), id); + } + pub(super) fn add_module(&mut self, id: ModuleId, path: ModulePath, repr: ModuleRepr) { + debug_assert!(self.global.path_to_source_id.contains_key(&path)); let module_info = ModuleInfo { id, repr, path }; self.global.module_infos.insert(id, module_info); } @@ -225,11 +234,15 @@ impl GlobalState { root_id, ModuleInfo { id: root_id, - path: ModulePath::Local(root_path.clone()), + path: ModulePath::Local { + value: root_path.clone(), + }, repr: ModuleRepr::Root, }, ); - global.path_to_source_id.insert(ModulePath::Local(root_path), root_id); + global + .path_to_source_id + .insert(ModulePath::Local { value: root_path }, root_id); global } } diff --git a/src/wasm-lib/kcl/src/modules.rs b/src/wasm-lib/kcl/src/modules.rs index b6e8e3fb5..82ee35576 100644 --- a/src/wasm-lib/kcl/src/modules.rs +++ b/src/wasm-lib/kcl/src/modules.rs @@ -64,13 +64,13 @@ impl ModuleLoader { } pub(crate) fn enter_module(&mut self, path: &ModulePath) { - if let ModulePath::Local(ref path) = path { + if let ModulePath::Local { value: ref path } = path { self.import_stack.push(path.clone()); } } pub(crate) fn leave_module(&mut self, path: &ModulePath) { - if let ModulePath::Local(ref path) = path { + if let ModulePath::Local { value: ref path } = path { let popped = self.import_stack.pop().unwrap(); assert_eq!(path, &popped); } @@ -119,31 +119,32 @@ pub enum ModuleRepr { } #[allow(clippy::large_enum_variant)] -#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize, Hash)] +#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize, Hash, ts_rs::TS)] +#[serde(tag = "type")] pub enum ModulePath { - Local(PathBuf), - Std(String), + Local { value: PathBuf }, + Std { value: String }, } impl ModulePath { pub(crate) fn expect_path(&self) -> &PathBuf { match self { - ModulePath::Local(p) => p, + ModulePath::Local { value: p } => p, _ => unreachable!(), } } pub(crate) fn std_path(&self) -> Option { match self { - ModulePath::Local(_) => None, - ModulePath::Std(p) => Some(p.clone()), + ModulePath::Local { value: _ } => None, + ModulePath::Std { value: p } => Some(p.clone()), } } pub(crate) async fn source(&self, fs: &FileManager, source_range: SourceRange) -> Result { match self { - ModulePath::Local(p) => fs.read_to_string(p, source_range).await, - ModulePath::Std(name) => read_std(name) + ModulePath::Local { value: p } => fs.read_to_string(p, source_range).await, + ModulePath::Std { value: name } => read_std(name) .ok_or_else(|| { KclError::Semantic(KclErrorDetails { message: format!("Cannot find standard library module to import: std::{name}."), @@ -162,14 +163,14 @@ impl ModulePath { } else { std::path::PathBuf::from(path) }; - ModulePath::Local(resolved_path) + ModulePath::Local { value: resolved_path } } ImportPath::Std { path } => { // For now we only support importing from singly-nested modules inside std. assert_eq!(path.len(), 2); assert_eq!(&path[0], "std"); - ModulePath::Std(path[1].clone()) + ModulePath::Std { value: path[1].clone() } } } } @@ -178,8 +179,8 @@ impl ModulePath { impl fmt::Display for ModulePath { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - ModulePath::Local(path) => path.display().fmt(f), - ModulePath::Std(s) => write!(f, "std::{s}"), + ModulePath::Local { value: path } => path.display().fmt(f), + ModulePath::Std { value: s } => write!(f, "std::{s}"), } } } diff --git a/src/wasm-lib/kcl/src/simulation_tests.rs b/src/wasm-lib/kcl/src/simulation_tests.rs index defc5c0a2..4619e5e03 100644 --- a/src/wasm-lib/kcl/src/simulation_tests.rs +++ b/src/wasm-lib/kcl/src/simulation_tests.rs @@ -1990,7 +1990,29 @@ mod helix_simple { /// Test parsing KCL. #[test] fn parse() { - super::parse(TEST_NAME) + super::parse(TEST_NAME); + } + + /// Test that parsing and unparsing KCL produces the original KCL input. + #[test] + fn unparse() { + super::unparse(TEST_NAME) + } + + /// Test that KCL is executed correctly. + #[tokio::test(flavor = "multi_thread")] + async fn kcl_test_execute() { + super::execute(TEST_NAME, true).await + } +} + +mod import_file_parse_error { + const TEST_NAME: &str = "import_file_parse_error"; + + /// Test parsing KCL. + #[test] + fn parse() { + super::parse(TEST_NAME); } /// Test that parsing and unparsing KCL produces the original KCL input. diff --git a/src/wasm-lib/kcl/tests/import_file_parse_error/artifact_commands.snap b/src/wasm-lib/kcl/tests/import_file_parse_error/artifact_commands.snap new file mode 100644 index 000000000..726888adc --- /dev/null +++ b/src/wasm-lib/kcl/tests/import_file_parse_error/artifact_commands.snap @@ -0,0 +1,284 @@ +--- +source: kcl/src/simulation_tests.rs +description: Artifact commands import_file_parse_error.kcl +--- +[ + { + "cmdId": "[uuid]", + "range": [ + 0, + 0, + 0 + ], + "command": { + "type": "make_plane", + "origin": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "x_axis": { + "x": 1.0, + "y": 0.0, + "z": 0.0 + }, + "y_axis": { + "x": 0.0, + "y": 1.0, + "z": 0.0 + }, + "size": 100.0, + "clobber": false, + "hide": true + } + }, + { + "cmdId": "[uuid]", + "range": [ + 0, + 0, + 0 + ], + "command": { + "type": "plane_set_color", + "plane_id": "[uuid]", + "color": { + "r": 0.7, + "g": 0.28, + "b": 0.28, + "a": 0.4 + } + } + }, + { + "cmdId": "[uuid]", + "range": [ + 0, + 0, + 0 + ], + "command": { + "type": "make_plane", + "origin": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "x_axis": { + "x": 0.0, + "y": 1.0, + "z": 0.0 + }, + "y_axis": { + "x": 0.0, + "y": 0.0, + "z": 1.0 + }, + "size": 100.0, + "clobber": false, + "hide": true + } + }, + { + "cmdId": "[uuid]", + "range": [ + 0, + 0, + 0 + ], + "command": { + "type": "plane_set_color", + "plane_id": "[uuid]", + "color": { + "r": 0.28, + "g": 0.7, + "b": 0.28, + "a": 0.4 + } + } + }, + { + "cmdId": "[uuid]", + "range": [ + 0, + 0, + 0 + ], + "command": { + "type": "make_plane", + "origin": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "x_axis": { + "x": 1.0, + "y": 0.0, + "z": 0.0 + }, + "y_axis": { + "x": 0.0, + "y": 0.0, + "z": 1.0 + }, + "size": 100.0, + "clobber": false, + "hide": true + } + }, + { + "cmdId": "[uuid]", + "range": [ + 0, + 0, + 0 + ], + "command": { + "type": "plane_set_color", + "plane_id": "[uuid]", + "color": { + "r": 0.28, + "g": 0.28, + "b": 0.7, + "a": 0.4 + } + } + }, + { + "cmdId": "[uuid]", + "range": [ + 0, + 0, + 0 + ], + "command": { + "type": "make_plane", + "origin": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "x_axis": { + "x": -1.0, + "y": 0.0, + "z": 0.0 + }, + "y_axis": { + "x": 0.0, + "y": 1.0, + "z": 0.0 + }, + "size": 100.0, + "clobber": false, + "hide": true + } + }, + { + "cmdId": "[uuid]", + "range": [ + 0, + 0, + 0 + ], + "command": { + "type": "make_plane", + "origin": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "x_axis": { + "x": 0.0, + "y": -1.0, + "z": 0.0 + }, + "y_axis": { + "x": 0.0, + "y": 0.0, + "z": 1.0 + }, + "size": 100.0, + "clobber": false, + "hide": true + } + }, + { + "cmdId": "[uuid]", + "range": [ + 0, + 0, + 0 + ], + "command": { + "type": "make_plane", + "origin": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "x_axis": { + "x": -1.0, + "y": 0.0, + "z": 0.0 + }, + "y_axis": { + "x": 0.0, + "y": 0.0, + "z": 1.0 + }, + "size": 100.0, + "clobber": false, + "hide": true + } + }, + { + "cmdId": "[uuid]", + "range": [ + 0, + 0, + 0 + ], + "command": { + "type": "edge_lines_visible", + "hidden": false + } + }, + { + "cmdId": "[uuid]", + "range": [ + 0, + 0, + 0 + ], + "command": { + "type": "set_scene_units", + "unit": "mm" + } + }, + { + "cmdId": "[uuid]", + "range": [ + 0, + 0, + 0 + ], + "command": { + "type": "object_visible", + "object_id": "[uuid]", + "hidden": true + } + }, + { + "cmdId": "[uuid]", + "range": [ + 0, + 0, + 0 + ], + "command": { + "type": "object_visible", + "object_id": "[uuid]", + "hidden": true + } + } +] diff --git a/src/wasm-lib/kcl/tests/import_file_parse_error/artifact_graph_flowchart.snap b/src/wasm-lib/kcl/tests/import_file_parse_error/artifact_graph_flowchart.snap new file mode 100644 index 000000000..11c77e5d8 --- /dev/null +++ b/src/wasm-lib/kcl/tests/import_file_parse_error/artifact_graph_flowchart.snap @@ -0,0 +1,6 @@ +--- +source: kcl/src/simulation_tests.rs +description: Artifact graph flowchart import_file_parse_error.kcl +extension: md +snapshot_kind: binary +--- diff --git a/src/wasm-lib/kcl/tests/import_file_parse_error/artifact_graph_flowchart.snap.md b/src/wasm-lib/kcl/tests/import_file_parse_error/artifact_graph_flowchart.snap.md new file mode 100644 index 000000000..13e533509 --- /dev/null +++ b/src/wasm-lib/kcl/tests/import_file_parse_error/artifact_graph_flowchart.snap.md @@ -0,0 +1,3 @@ +```mermaid +flowchart LR +``` diff --git a/src/wasm-lib/kcl/tests/import_file_parse_error/ast.snap b/src/wasm-lib/kcl/tests/import_file_parse_error/ast.snap new file mode 100644 index 000000000..7ec2ae6d4 --- /dev/null +++ b/src/wasm-lib/kcl/tests/import_file_parse_error/ast.snap @@ -0,0 +1,39 @@ +--- +source: kcl/src/simulation_tests.rs +description: Result of parsing import_file_parse_error.kcl +--- +{ + "Ok": { + "body": [ + { + "end": 38, + "path": { + "type": "Kcl", + "filename": "parse-failure.kcl" + }, + "selector": { + "type": "List", + "items": [ + { + "alias": null, + "end": 13, + "name": { + "end": 13, + "name": "hotdog", + "start": 7, + "type": "Identifier" + }, + "start": 7, + "type": "ImportItem" + } + ] + }, + "start": 0, + "type": "ImportStatement", + "type": "ImportStatement" + } + ], + "end": 39, + "start": 0 + } +} diff --git a/src/wasm-lib/kcl/tests/import_file_parse_error/execution_error.snap b/src/wasm-lib/kcl/tests/import_file_parse_error/execution_error.snap new file mode 100644 index 000000000..92a076f05 --- /dev/null +++ b/src/wasm-lib/kcl/tests/import_file_parse_error/execution_error.snap @@ -0,0 +1,11 @@ +--- +source: kcl/src/simulation_tests.rs +description: Error from executing import_file_parse_error.kcl +--- +KCL Syntax error + + × syntax: Unexpected token: } + ╭──── + 1 │ import hotdog from "parse-failure.kcl" + · ─ + ╰──── diff --git a/src/wasm-lib/kcl/tests/import_file_parse_error/input.kcl b/src/wasm-lib/kcl/tests/import_file_parse_error/input.kcl new file mode 100644 index 000000000..0edd71035 --- /dev/null +++ b/src/wasm-lib/kcl/tests/import_file_parse_error/input.kcl @@ -0,0 +1 @@ +import hotdog from "parse-failure.kcl" diff --git a/src/wasm-lib/kcl/tests/import_file_parse_error/ops.snap b/src/wasm-lib/kcl/tests/import_file_parse_error/ops.snap new file mode 100644 index 000000000..4214ec3e4 --- /dev/null +++ b/src/wasm-lib/kcl/tests/import_file_parse_error/ops.snap @@ -0,0 +1,5 @@ +--- +source: kcl/src/simulation_tests.rs +description: Operations executed import_file_parse_error.kcl +--- +[] diff --git a/src/wasm-lib/kcl/tests/import_file_parse_error/parse-failure.kcl b/src/wasm-lib/kcl/tests/import_file_parse_error/parse-failure.kcl new file mode 100644 index 000000000..b3876db46 --- /dev/null +++ b/src/wasm-lib/kcl/tests/import_file_parse_error/parse-failure.kcl @@ -0,0 +1,3 @@ +export fn hotdog () { + return +}