Compare commits

...

37 Commits

Author SHA1 Message Date
17e7df100c Commit changes to cargo.lock 2023-11-21 16:21:43 -06:00
d8aad4bd4f remove the buffer we were using for debugging, its too small for import (#1100)
Signed-off-by: Jess Frazelle <github@jessfraz.com>
2023-11-21 09:23:48 -08:00
1f1c44e598 Bump kittycad from 0.2.42 to 0.2.43 in /src/wasm-lib (#1097)
Bumps [kittycad](https://github.com/KittyCAD/kittycad.rs) from 0.2.42 to 0.2.43.
- [Release notes](https://github.com/KittyCAD/kittycad.rs/releases)
- [Commits](https://github.com/KittyCAD/kittycad.rs/compare/v0.2.42...v0.2.43)

---
updated-dependencies:
- dependency-name: kittycad
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-20 14:47:50 -08:00
b20e685eea Bump tauri-plugin-fs-extra from 642a195 to 20ef22f in /src-tauri (#1090)
Bumps [tauri-plugin-fs-extra](https://github.com/tauri-apps/plugins-workspace) from `642a195` to `20ef22f`.
- [Release notes](https://github.com/tauri-apps/plugins-workspace/releases)
- [Commits](642a195d34...20ef22fc3a)

---
updated-dependencies:
- dependency-name: tauri-plugin-fs-extra
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-20 13:55:59 -08:00
3690d986c1 Bump kittycad from 0.2.41 to 0.2.42 in /src-tauri (#1091)
Bumps [kittycad](https://github.com/KittyCAD/kittycad.rs) from 0.2.41 to 0.2.42.
- [Release notes](https://github.com/KittyCAD/kittycad.rs/releases)
- [Commits](https://github.com/KittyCAD/kittycad.rs/compare/v0.2.41...v0.2.42)

---
updated-dependencies:
- dependency-name: kittycad
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-20 13:55:43 -08:00
9a7f434ede Derive Databake now that it has HashMap support (#1095) 2023-11-20 12:24:37 -06:00
6afacd7427 KCL optional parameters (#1087)
Part of https://github.com/KittyCAD/modeling-app/issues/1006#issuecomment-1816978586

This adds support for optional parameters to the AST. They are declared with a ? suffix, e.g. `(x, tag?) => {...}`.

This PR does not actually _use_ these optional parameters anywhere. In particular, it does not change the KCL stdlib or any existing function definitions. That will happen in a follow-up PR.
2023-11-20 11:19:08 -06:00
957001ee88 Bump uuid from 1.5.0 to 1.6.0 in /src/wasm-lib (#1089)
Bumps [uuid](https://github.com/uuid-rs/uuid) from 1.5.0 to 1.6.0.
- [Release notes](https://github.com/uuid-rs/uuid/releases)
- [Commits](https://github.com/uuid-rs/uuid/compare/1.5.0...1.6.0)

---
updated-dependencies:
- dependency-name: uuid
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-20 11:17:04 -06:00
8b4cc306af Bump openapitor from 5ed477b to 9caff1f in /src/wasm-lib (#1085)
Bumps [openapitor](https://github.com/KittyCAD/kittycad.rs) from `5ed477b` to `9caff1f`.
- [Release notes](https://github.com/KittyCAD/kittycad.rs/releases)
- [Commits](5ed477b5c9...9caff1f4f0)

---
updated-dependencies:
- dependency-name: openapitor
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-20 11:16:33 -06:00
52d88171ca Bump kittycad from 0.2.41 to 0.2.42 in /src/wasm-lib (#1086)
Bumps [kittycad](https://github.com/KittyCAD/kittycad.rs) from 0.2.41 to 0.2.42.
- [Release notes](https://github.com/KittyCAD/kittycad.rs/releases)
- [Commits](https://github.com/KittyCAD/kittycad.rs/compare/v0.2.41...v0.2.42)

---
updated-dependencies:
- dependency-name: kittycad
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-20 11:16:18 -06:00
9142cf3af7 Bump databake from 0.1.6 to 0.1.7 in /src/wasm-lib (#1082)
Bumps [databake](https://github.com/unicode-org/icu4x) from 0.1.6 to 0.1.7.
- [Release notes](https://github.com/unicode-org/icu4x/releases)
- [Changelog](https://github.com/unicode-org/icu4x/blob/main/CHANGELOG.md)
- [Commits](https://github.com/unicode-org/icu4x/commits)

---
updated-dependencies:
- dependency-name: databake
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-20 11:16:01 -06:00
361500058c Bump tauri-plugin-fs-extra from b13d97c to 642a195 in /src-tauri (#1084)
Bumps [tauri-plugin-fs-extra](https://github.com/tauri-apps/plugins-workspace) from `b13d97c` to `642a195`.
- [Release notes](https://github.com/tauri-apps/plugins-workspace/releases)
- [Commits](b13d97c7c7...642a195d34)

---
updated-dependencies:
- dependency-name: tauri-plugin-fs-extra
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-17 11:00:43 -08:00
198479a71a Bump openapitor from 3afe554 to 5ed477b in /src/wasm-lib (#1080)
Bumps [openapitor](https://github.com/KittyCAD/kittycad.rs) from `3afe554` to `5ed477b`.
- [Release notes](https://github.com/KittyCAD/kittycad.rs/releases)
- [Commits](3afe554cf9...5ed477b5c9)

---
updated-dependencies:
- dependency-name: openapitor
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-17 11:00:04 -08:00
905784c1e5 Bump @vitest/coverage-istanbul from 0.34.1 to 0.34.6 (#1071)
Bumps [@vitest/coverage-istanbul](https://github.com/vitest-dev/vitest/tree/HEAD/packages/coverage-istanbul) from 0.34.1 to 0.34.6.
- [Release notes](https://github.com/vitest-dev/vitest/releases)
- [Commits](https://github.com/vitest-dev/vitest/commits/v0.34.6/packages/coverage-istanbul)

---
updated-dependencies:
- dependency-name: "@vitest/coverage-istanbul"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-16 05:48:35 -05:00
c33aaad800 Release KCL 0.1.36 (#1078) 2023-11-15 17:50:08 +00:00
d175c75780 Bump schemars, itertools, add comments to crates (#1077)
Bump itertools, schemars, add comments to crates
2023-11-15 11:41:12 -06:00
ba348d1222 Bump openapitor from 1b2562f to 3afe554 in /src/wasm-lib (#1073)
Bumps [openapitor](https://github.com/KittyCAD/kittycad.rs) from `1b2562f` to `3afe554`.
- [Release notes](https://github.com/KittyCAD/kittycad.rs/releases)
- [Commits](1b2562f4b3...3afe554cf9)

---
updated-dependencies:
- dependency-name: openapitor
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-14 13:31:34 -08:00
1f49ddfc29 Bump tauri-plugin-fs-extra from 61e8625 to b13d97c in /src-tauri (#1072)
Bumps [tauri-plugin-fs-extra](https://github.com/tauri-apps/plugins-workspace) from `61e8625` to `b13d97c`.
- [Release notes](https://github.com/tauri-apps/plugins-workspace/releases)
- [Commits](61e862597e...b13d97c7c7)

---
updated-dependencies:
- dependency-name: tauri-plugin-fs-extra
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-14 13:31:25 -08:00
58659652c1 Cut release v0.12.0 (#1069) 2023-11-13 21:11:38 -05:00
251971238d Fit resolutions to less than 2k x 2k (#1065)
* Fit resolutions to less than 2k x 2k

* Integer resolutions

* Scale mouse clicks

* Move stream maxResolution logic to getDimensions
2023-11-13 19:32:07 -05:00
381d0b3bc8 Add a console.error when ICE fails (#1067)
This is purely cosmetic right now, but I want to try and make it easier
to tell when the browser is unable to communicate with the ICE server
by writing it to the console.

I want to add some Sentry logging in the future, but for now, when we
see a stream failing to start, we can at least see what I suspect is the
most common trigger in the console.

Signed-off-by: Paul R. Tagliamonte <paul@kittycad.io>
2023-11-14 06:13:15 +11:00
fa7943d06a Bump clap from 4.4.7 to 4.4.8 in /src/wasm-lib (#1062)
Bumps [clap](https://github.com/clap-rs/clap) from 4.4.7 to 4.4.8.
- [Release notes](https://github.com/clap-rs/clap/releases)
- [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md)
- [Commits](https://github.com/clap-rs/clap/compare/v4.4.7...v4.4.8)

---
updated-dependencies:
- dependency-name: clap
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-13 13:08:16 -06:00
7a384251d4 Bump @babel/preset-env from 7.22.9 to 7.23.3 (#1058)
Bumps [@babel/preset-env](https://github.com/babel/babel/tree/HEAD/packages/babel-preset-env) from 7.22.9 to 7.23.3.
- [Release notes](https://github.com/babel/babel/releases)
- [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md)
- [Commits](https://github.com/babel/babel/commits/v7.23.3/packages/babel-preset-env)

---
updated-dependencies:
- dependency-name: "@babel/preset-env"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-13 05:13:28 -05:00
8e07ea32a6 Bump tailwindcss from 3.3.3 to 3.3.5 (#1059)
Bumps [tailwindcss](https://github.com/tailwindlabs/tailwindcss) from 3.3.3 to 3.3.5.
- [Release notes](https://github.com/tailwindlabs/tailwindcss/releases)
- [Changelog](https://github.com/tailwindlabs/tailwindcss/blob/master/CHANGELOG.md)
- [Commits](https://github.com/tailwindlabs/tailwindcss/compare/v3.3.3...v3.3.5)

---
updated-dependencies:
- dependency-name: tailwindcss
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-13 05:13:16 -05:00
23adf9d905 Disable eslint rule react-hooks/exhaustive-deps (#1055)
Disable react-hooks/exhaustive-deps
Workaround for #1014
2023-11-11 16:27:12 -05:00
9f0ac5f6fd Macro for parsing KCL at Rust compile-time (#1049)
Macro for parsing KCL at Rust compile-time

This adds a new `parse_kcl!` macro which takes a string as input. It parses the string into KCL source code _at compile-time_. Invalid KCL will make your Rust project fail to compile.

Fixes https://github.com/KittyCAD/modeling-app/issues/1018
2023-11-10 10:36:21 -06:00
08dbd2e9c3 Bump web-sys from 0.3.64 to 0.3.65 in /src/wasm-lib (#1052)
Bumps [web-sys](https://github.com/rustwasm/wasm-bindgen) from 0.3.64 to 0.3.65.
- [Release notes](https://github.com/rustwasm/wasm-bindgen/releases)
- [Changelog](https://github.com/rustwasm/wasm-bindgen/blob/main/CHANGELOG.md)
- [Commits](https://github.com/rustwasm/wasm-bindgen/commits)

---
updated-dependencies:
- dependency-name: web-sys
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-10 06:49:33 -05:00
2e2ba5adbd Bump tauri-plugin-fs-extra from 6865299 to 61e8625 in /src-tauri (#1054)
Bumps [tauri-plugin-fs-extra](https://github.com/tauri-apps/plugins-workspace) from `6865299` to `61e8625`.
- [Release notes](https://github.com/tauri-apps/plugins-workspace/releases)
- [Commits](6865299149...61e862597e)

---
updated-dependencies:
- dependency-name: tauri-plugin-fs-extra
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-10 06:49:12 -05:00
a21dbf1055 Bump tokio from 1.33.0 to 1.34.0 in /src-tauri (#1053)
Bumps [tokio](https://github.com/tokio-rs/tokio) from 1.33.0 to 1.34.0.
- [Release notes](https://github.com/tokio-rs/tokio/releases)
- [Commits](https://github.com/tokio-rs/tokio/compare/tokio-1.33.0...tokio-1.34.0)

---
updated-dependencies:
- dependency-name: tokio
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-10 05:24:59 -05:00
5ecb176467 Bump tokio from 1.33.0 to 1.34.0 in /src/wasm-lib (#1051)
Bumps [tokio](https://github.com/tokio-rs/tokio) from 1.33.0 to 1.34.0.
- [Release notes](https://github.com/tokio-rs/tokio/releases)
- [Commits](https://github.com/tokio-rs/tokio/compare/tokio-1.33.0...tokio-1.34.0)

---
updated-dependencies:
- dependency-name: tokio
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-10 05:24:40 -05:00
66135636ec Bump wasm-bindgen-futures from 0.4.37 to 0.4.38 in /src/wasm-lib (#1050)
Bumps [wasm-bindgen-futures](https://github.com/rustwasm/wasm-bindgen) from 0.4.37 to 0.4.38.
- [Release notes](https://github.com/rustwasm/wasm-bindgen/releases)
- [Changelog](https://github.com/rustwasm/wasm-bindgen/blob/main/CHANGELOG.md)
- [Commits](https://github.com/rustwasm/wasm-bindgen/commits)

---
updated-dependencies:
- dependency-name: wasm-bindgen-futures
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-10 05:24:10 -05:00
685a16545c Bump @vitejs/plugin-react from 4.0.4 to 4.1.1 (#1035)
Bumps [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/tree/HEAD/packages/plugin-react) from 4.0.4 to 4.1.1.
- [Release notes](https://github.com/vitejs/vite-plugin-react/releases)
- [Changelog](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/CHANGELOG.md)
- [Commits](https://github.com/vitejs/vite-plugin-react/commits/v4.1.1/packages/plugin-react)

---
updated-dependencies:
- dependency-name: "@vitejs/plugin-react"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-10 05:20:45 -05:00
9adb15ee93 Bump @headlessui/react from 1.7.16 to 1.7.17 (#1037)
Bumps [@headlessui/react](https://github.com/tailwindlabs/headlessui/tree/HEAD/packages/@headlessui-react) from 1.7.16 to 1.7.17.
- [Release notes](https://github.com/tailwindlabs/headlessui/releases)
- [Changelog](https://github.com/tailwindlabs/headlessui/blob/main/packages/@headlessui-react/CHANGELOG.md)
- [Commits](https://github.com/tailwindlabs/headlessui/commits/@headlessui/react@v1.7.17/packages/@headlessui-react)

---
updated-dependencies:
- dependency-name: "@headlessui/react"
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-10 05:20:02 -05:00
a8c4c97d79 Bump fuse.js from 6.6.2 to 7.0.0 (#1036)
Bumps [fuse.js](https://github.com/krisk/Fuse) from 6.6.2 to 7.0.0.
- [Release notes](https://github.com/krisk/Fuse/releases)
- [Changelog](https://github.com/krisk/Fuse/blob/main/CHANGELOG.md)
- [Commits](https://github.com/krisk/Fuse/compare/v6.6.2...v7.0.0)

---
updated-dependencies:
- dependency-name: fuse.js
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-10 05:19:46 -05:00
39e8e1f259 Bump eslint-plugin-css-modules from 2.11.0 to 2.12.0 (#1034)
Bumps [eslint-plugin-css-modules](https://github.com/atfzl/eslint-plugin-css-modules) from 2.11.0 to 2.12.0.
- [Release notes](https://github.com/atfzl/eslint-plugin-css-modules/releases)
- [Commits](https://github.com/atfzl/eslint-plugin-css-modules/compare/v2.11.0...v2.12.0)

---
updated-dependencies:
- dependency-name: eslint-plugin-css-modules
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-10 05:18:09 -05:00
1672c1fd1f Impl databake for all AST node types (#1047)
Databake doesn't have any derive for HashMap, so for NonCodeMeta I decided to skip serializing the non_code_nodes. This should be OK for now.

See <https://github.com/unicode-org/icu4x/issues/4266> for the Databake hashmap issue.
2023-11-09 16:39:12 -06:00
6ec5881985 top level expressions fix (#1046)
#1033 top level expressions fix

Signed-off-by: Jess Frazelle <github@jessfraz.com>
2023-11-09 13:08:11 -08:00
31 changed files with 1209 additions and 662 deletions

View File

@ -11,6 +11,7 @@
"semi": [
"error",
"never"
]
],
"react-hooks/exhaustive-deps": "off"
}
}

View File

@ -1,6 +1,6 @@
{
"name": "untitled-app",
"version": "0.11.3",
"version": "0.12.0",
"private": true,
"dependencies": {
"@codemirror/autocomplete": "^6.10.2",
@ -8,7 +8,7 @@
"@fortawesome/free-brands-svg-icons": "^6.4.2",
"@fortawesome/free-solid-svg-icons": "^6.4.2",
"@fortawesome/react-fontawesome": "^0.2.0",
"@headlessui/react": "^1.7.13",
"@headlessui/react": "^1.7.17",
"@headlessui/tailwindcss": "^0.2.0",
"@kittycad/lib": "^0.0.45",
"@lezer/javascript": "^1.4.7",
@ -30,7 +30,7 @@
"crypto-js": "^4.2.0",
"debounce-promise": "^3.1.2",
"formik": "^2.4.3",
"fuse.js": "^6.6.2",
"fuse.js": "^7.0.0",
"http-server": "^14.1.1",
"json-rpc-2.0": "^1.6.0",
"re-resizable": "^6.9.11",
@ -102,7 +102,7 @@
},
"devDependencies": {
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
"@babel/preset-env": "^7.22.9",
"@babel/preset-env": "^7.23.3",
"@tauri-apps/cli": "^1.5.6",
"@types/crypto-js": "^4.1.1",
"@types/debounce-promise": "^3.1.8",
@ -111,18 +111,18 @@
"@types/uuid": "^9.0.4",
"@types/wicg-file-system-access": "^2020.9.6",
"@types/ws": "^8.5.5",
"@vitejs/plugin-react": "^4.0.3",
"@vitest/coverage-istanbul": "^0.34.1",
"@vitejs/plugin-react": "^4.1.1",
"@vitest/coverage-istanbul": "^0.34.6",
"autoprefixer": "^10.4.13",
"eslint": "^8.53.0",
"eslint-config-react-app": "^7.0.1",
"eslint-plugin-css-modules": "^2.11.0",
"eslint-plugin-css-modules": "^2.12.0",
"happy-dom": "^10.8.0",
"husky": "^8.0.3",
"postcss": "^8.4.31",
"prettier": "^2.8.0",
"setimmediate": "^1.0.5",
"tailwindcss": "^3.2.4",
"tailwindcss": "^3.3.5",
"vite": "^4.5.0",
"vite-plugin-eslint": "^1.8.1",
"vite-tsconfig-paths": "^4.2.1",

32
src-tauri/Cargo.lock generated
View File

@ -1664,9 +1664,9 @@ dependencies = [
[[package]]
name = "kittycad"
version = "0.2.41"
version = "0.2.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "874914cd40bfd43674406683bb3f0924d41780698a4ade96f2e180a73678bdd1"
checksum = "6aa554d86b6dbbd976a659c912ae25ce817b4378eb12a5684907e263410f0a7b"
dependencies = [
"anyhow",
"async-trait",
@ -1732,9 +1732,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.148"
version = "0.2.150"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9cdc71e17332e86d2e1d38c1f99edcb6288ee11b815fb1a4b049eaa2114d369b"
checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c"
[[package]]
name = "libm"
@ -1940,9 +1940,9 @@ dependencies = [
[[package]]
name = "mio"
version = "0.8.8"
version = "0.8.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2"
checksum = "3dce281c5e46beae905d4de1870d8b1509a9142b62eedf18b443b011ca8343d0"
dependencies = [
"libc",
"wasi 0.11.0+wasi-snapshot-preview1",
@ -3112,9 +3112,9 @@ dependencies = [
[[package]]
name = "schemars"
version = "0.8.15"
version = "0.8.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f7b0ce13155372a76ee2e1c5ffba1fe61ede73fbea5630d61eee6fac4929c0c"
checksum = "45a28f4c49489add4ce10783f7911893516f15afe45d015608d41faca6bc4d29"
dependencies = [
"bigdecimal",
"bytes",
@ -3129,9 +3129,9 @@ dependencies = [
[[package]]
name = "schemars_derive"
version = "0.8.15"
version = "0.8.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e85e2a16b12bdb763244c69ab79363d71db2b4b918a2def53f80b02e0574b13c"
checksum = "c767fd6fa65d9ccf9cf026122c1b555f2ef9a4f0cea69da4d7dbc3e258d30967"
dependencies = [
"proc-macro2",
"quote",
@ -3438,9 +3438,9 @@ dependencies = [
[[package]]
name = "socket2"
version = "0.5.4"
version = "0.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4031e820eb552adee9295814c0ced9e5cf38ddf1e8b7d566d6de8e2538ea989e"
checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9"
dependencies = [
"libc",
"windows-sys 0.48.0",
@ -3856,7 +3856,7 @@ dependencies = [
[[package]]
name = "tauri-plugin-fs-extra"
version = "0.0.0"
source = "git+https://github.com/tauri-apps/plugins-workspace?branch=v1#6865299149ffd183365e3ff291acf3edac78ca61"
source = "git+https://github.com/tauri-apps/plugins-workspace?branch=v1#20ef22fc3ab76cab770c2c0dac0cc75dfc982c22"
dependencies = [
"log",
"serde",
@ -4035,9 +4035,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
[[package]]
name = "tokio"
version = "1.33.0"
version = "1.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4f38200e3ef7995e5ef13baec2f432a6da0aa9ac495b2c0e8f3b7eec2c92d653"
checksum = "d0c014766411e834f7af5b8f4cf46257aab4036ca95e9d2c144a10f59ad6f5b9"
dependencies = [
"backtrace",
"bytes",
@ -4045,7 +4045,7 @@ dependencies = [
"mio",
"num_cpus",
"pin-project-lite",
"socket2 0.5.4",
"socket2 0.5.5",
"windows-sys 0.48.0",
]

View File

@ -16,13 +16,13 @@ tauri-build = { version = "1.5.0", features = [] }
[dependencies]
anyhow = "1"
kittycad = "0.2.41"
kittycad = "0.2.42"
oauth2 = "4.4.2"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tauri = { version = "1.5.2", features = [ "os-all", "dialog-all", "fs-all", "http-request", "path-all", "shell-open", "shell-open-api", "updater", "devtools"] }
tauri-plugin-fs-extra = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" }
tokio = { version = "1.33.0", features = ["time"] }
tokio = { version = "1.34.0", features = ["time"] }
toml = "0.8.2"
[features]

View File

@ -8,7 +8,7 @@
},
"package": {
"productName": "kittycad-modeling",
"version": "0.11.3"
"version": "0.12.0"
},
"tauri": {
"allowlist": {

View File

@ -9,7 +9,6 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { faChevronRight, faTrashAlt } from '@fortawesome/free-solid-svg-icons'
import { useFileContext } from 'hooks/useFileContext'
import { useHotkeys } from 'react-hotkeys-hook'
import { kclManager } from 'lang/KclSinglton'
import styles from './FileTree.module.css'
import { sortProject } from 'lib/tauriFS'

View File

@ -82,9 +82,14 @@ export function useSetupEngineManager(
}
function getDimensions(streamWidth?: number, streamHeight?: number) {
const maxResolution = 2000
const width = streamWidth ? streamWidth : 0
const quadWidth = Math.round(width / 4) * 4
const height = streamHeight ? streamHeight : 0
const quadHeight = Math.round(height / 4) * 4
const ratio = Math.min(
Math.min(maxResolution / width, maxResolution / height),
1.0
)
const quadWidth = Math.round((width * ratio) / 4) * 4
const quadHeight = Math.round((height * ratio) / 4) * 4
return { width: quadWidth, height: quadHeight }
}

View File

@ -169,17 +169,25 @@ describe('testing function declaration', () => {
end: 39,
params: [
{
type: 'Parameter',
identifier: {
type: 'Identifier',
start: 12,
end: 13,
name: 'a',
},
optional: false,
},
{
type: 'Parameter',
identifier: {
type: 'Identifier',
start: 15,
end: 16,
name: 'b',
},
optional: false,
},
],
body: {
start: 21,
@ -244,17 +252,25 @@ const myVar = funcN(1, 2)`
end: 37,
params: [
{
type: 'Parameter',
identifier: {
type: 'Identifier',
start: 12,
end: 13,
name: 'a',
},
optional: false,
},
{
type: 'Parameter',
identifier: {
type: 'Identifier',
start: 15,
end: 16,
name: 'b',
},
optional: false,
},
],
body: {
start: 21,

View File

@ -1,5 +1,5 @@
import { getNodePathFromSourceRange, getNodeFromPath } from './queryAst'
import { Identifier, parse, initPromise } from './wasm'
import { Identifier, parse, initPromise, Parameter } from './wasm'
beforeAll(() => initPromise)
@ -46,7 +46,7 @@ const b1 = cube([0,0], 10)`
const ast = parse(code)
const nodePath = getNodePathFromSourceRange(ast, sourceRange)
const node = getNodeFromPath<Identifier>(ast, nodePath).node
const node = getNodeFromPath<Parameter>(ast, nodePath).node
expect(nodePath).toEqual([
['body', ''],
@ -57,8 +57,8 @@ const b1 = cube([0,0], 10)`
['params', 'FunctionExpression'],
[0, 'index'],
])
expect(node.type).toBe('Identifier')
expect(node.name).toBe('pos')
expect(node.type).toBe('Parameter')
expect(node.identifier.name).toBe('pos')
})
it('gets path right for deep within function definition body', () => {
const code = `fn cube = (pos, scale) => {

View File

@ -247,10 +247,10 @@ function moreNodePathFromSourceRange(
if (_node.type === 'FunctionExpression' && isInRange) {
for (let i = 0; i < _node.params.length; i++) {
const param = _node.params[i]
if (param.start <= start && param.end >= end) {
if (param.identifier.start <= start && param.identifier.end >= end) {
path.push(['params', 'FunctionExpression'])
path.push([i, 'index'])
return moreNodePathFromSourceRange(param, sourceRange, path)
return moreNodePathFromSourceRange(param.identifier, sourceRange, path)
}
}
if (_node.body.start <= start && _node.body.end >= end) {

View File

@ -216,6 +216,26 @@ export class EngineConnection {
}
})
this.pc.addEventListener('icecandidateerror', (_event) => {
const event = _event as RTCPeerConnectionIceErrorEvent
console.error(
`ICE candidate returned an error: ${event.errorCode}: ${event.errorText} for ${event.url}`
)
})
this.pc.addEventListener('connectionstatechange', (event) => {
if (this.pc?.iceConnectionState === 'connected') {
if (this.shouldTrace()) {
iceSpan.resolve?.()
}
} else if (this.pc?.iceConnectionState === 'failed') {
// failed is a terminal state; let's explicitly kill the
// connection to the server at this point.
console.log('failed to negotiate ice connection; restarting')
this.close()
}
})
this.websocket.addEventListener('open', (event) => {
if (this.shouldTrace()) {
websocketSpan.resolve?.()
@ -351,19 +371,6 @@ export class EngineConnection {
// until the end of this function is setup of our end of the
// PeerConnection and waiting for events to fire our callbacks.
this.pc.addEventListener('connectionstatechange', (event) => {
if (this.pc?.iceConnectionState === 'connected') {
if (this.shouldTrace()) {
iceSpan.resolve?.()
}
} else if (this.pc?.iceConnectionState === 'failed') {
// failed is a terminal state; let's explicitly kill the
// connection to the server at this point.
console.log('failed to negotiate ice connection; restarting')
this.close()
}
})
this.pc.addEventListener('icecandidate', (event) => {
if (!this.pc || !this.websocket) return
if (event.candidate !== null) {
@ -633,7 +640,10 @@ export class EngineCommandManager {
// If we already have an engine connection, just need to resize the stream.
if (this.engineConnection) {
this.handleResize({ streamWidth: width, streamHeight: height })
this.handleResize({
streamWidth: width,
streamHeight: height,
})
return
}

View File

@ -20,6 +20,7 @@ export type { ObjectExpression } from '../wasm-lib/kcl/bindings/ObjectExpression
export type { MemberExpression } from '../wasm-lib/kcl/bindings/MemberExpression'
export type { PipeExpression } from '../wasm-lib/kcl/bindings/PipeExpression'
export type { VariableDeclaration } from '../wasm-lib/kcl/bindings/VariableDeclaration'
export type { Parameter } from '../wasm-lib/kcl/bindings/Parameter'
export type { PipeSubstitution } from '../wasm-lib/kcl/bindings/PipeSubstitution'
export type { Identifier } from '../wasm-lib/kcl/bindings/Identifier'
export type { UnaryExpression } from '../wasm-lib/kcl/bindings/UnaryExpression'

106
src/wasm-lib/Cargo.lock generated
View File

@ -447,9 +447,9 @@ dependencies = [
[[package]]
name = "clap"
version = "4.4.7"
version = "4.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac495e00dcec98c83465d5ad66c5c4fabd652fd6686e7c6269b117e729a6f17b"
checksum = "2275f18819641850fa26c89acc84d465c1bf91ce57bc2748b28c420473352f64"
dependencies = [
"clap_builder",
"clap_derive",
@ -457,9 +457,9 @@ dependencies = [
[[package]]
name = "clap_builder"
version = "4.4.7"
version = "4.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c77ed9a32a62e6ca27175d00d29d05ca32e396ea1eb5fb01d8256b669cec7663"
checksum = "07cdf1b148b25c1e1f7a42225e30a0d99a615cd4637eae7365548dd4529b95bc"
dependencies = [
"anstream",
"anstyle",
@ -681,6 +681,29 @@ version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2e66c9d817f1720209181c316d28635c050fa304f9c79e47a520882661b7308"
[[package]]
name = "databake"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "82175d72e69414ceafbe2b49686794d3a8bed846e0d50267355f83ea8fdd953a"
dependencies = [
"databake-derive",
"proc-macro2",
"quote",
]
[[package]]
name = "databake-derive"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "377af281d8f23663862a7c84623bc5dcf7f8c44b13c7496a590bdc157f941a43"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.39",
"synstructure",
]
[[package]]
name = "deranged"
version = "0.3.9"
@ -1359,9 +1382,9 @@ dependencies = [
[[package]]
name = "itertools"
version = "0.11.0"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57"
checksum = "25db6b064527c5d482d0423354fcd07a89a2dfe07b67892e62411946db7f07b0"
dependencies = [
"either",
]
@ -1403,7 +1426,7 @@ dependencies = [
[[package]]
name = "kcl-lib"
version = "0.1.35"
version = "0.1.37"
dependencies = [
"anyhow",
"async-recursion",
@ -1412,11 +1435,12 @@ dependencies = [
"clap",
"criterion",
"dashmap",
"databake",
"derive-docs 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"expectorate",
"futures",
"insta",
"itertools 0.11.0",
"itertools 0.12.0",
"js-sys",
"kittycad",
"lazy_static",
@ -1438,11 +1462,23 @@ dependencies = [
"winnow",
]
[[package]]
name = "kcl-macros"
version = "0.1.0"
dependencies = [
"databake",
"kcl-lib",
"pretty_assertions",
"proc-macro2",
"quote",
"syn 2.0.39",
]
[[package]]
name = "kittycad"
version = "0.2.41"
version = "0.2.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "874914cd40bfd43674406683bb3f0924d41780698a4ade96f2e180a73678bdd1"
checksum = "41ab6de34cc4ab06519d65a613d4030ade14036ac619d8fee5ce6f35d1766c11"
dependencies = [
"anyhow",
"async-trait",
@ -1747,7 +1783,7 @@ checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575"
[[package]]
name = "openapitor"
version = "0.0.9"
source = "git+https://github.com/KittyCAD/kittycad.rs?branch=main#1b2562f4b3ecd26a3683c3fc48a0d33707097a36"
source = "git+https://github.com/KittyCAD/kittycad.rs?branch=main#9caff1f4f00c64632ff5a226251e3dc68210b455"
dependencies = [
"Inflector",
"anyhow",
@ -1917,7 +1953,7 @@ dependencies = [
"bincode",
"either",
"fnv",
"itertools 0.11.0",
"itertools 0.10.5",
"lazy_static",
"nom",
"quick-xml",
@ -2484,9 +2520,9 @@ dependencies = [
[[package]]
name = "schemars"
version = "0.8.15"
version = "0.8.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f7b0ce13155372a76ee2e1c5ffba1fe61ede73fbea5630d61eee6fac4929c0c"
checksum = "45a28f4c49489add4ce10783f7911893516f15afe45d015608d41faca6bc4d29"
dependencies = [
"bigdecimal",
"bytes",
@ -2501,9 +2537,9 @@ dependencies = [
[[package]]
name = "schemars_derive"
version = "0.8.15"
version = "0.8.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e85e2a16b12bdb763244c69ab79363d71db2b4b918a2def53f80b02e0574b13c"
checksum = "c767fd6fa65d9ccf9cf026122c1b555f2ef9a4f0cea69da4d7dbc3e258d30967"
dependencies = [
"proc-macro2",
"quote",
@ -2906,6 +2942,18 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "synstructure"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "285ba80e733fac80aa4270fbcdf83772a79b80aa35c97075320abfee4a915b06"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.39",
"unicode-xid",
]
[[package]]
name = "system-configuration"
version = "0.5.1"
@ -3090,9 +3138,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
[[package]]
name = "tokio"
version = "1.33.0"
version = "1.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4f38200e3ef7995e5ef13baec2f432a6da0aa9ac495b2c0e8f3b7eec2c92d653"
checksum = "d0c014766411e834f7af5b8f4cf46257aab4036ca95e9d2c144a10f59ad6f5b9"
dependencies = [
"backtrace",
"bytes",
@ -3109,9 +3157,9 @@ dependencies = [
[[package]]
name = "tokio-macros"
version = "2.1.0"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e"
checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b"
dependencies = [
"proc-macro2",
"quote",
@ -3455,6 +3503,12 @@ version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85"
[[package]]
name = "unicode-xid"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
[[package]]
name = "unsafe-libyaml"
version = "0.2.9"
@ -3493,9 +3547,9 @@ checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
[[package]]
name = "uuid"
version = "1.5.0"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88ad59a7560b41a70d191093a945f0b87bc1deeda46fb237479708a1d6b6cdfc"
checksum = "c58fe91d841bc04822c9801002db4ea904b9e4b8e6bbad25127b46eff8dc516b"
dependencies = [
"atomic",
"getrandom",
@ -3573,9 +3627,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-futures"
version = "0.4.37"
version = "0.4.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c02dbc21516f9f1f04f187958890d7e6026df8d16540b7ad9492bc34a67cea03"
checksum = "9afec9963e3d0994cac82455b2b3502b81a7f40f9a0d32181f7528d9f4b43e02"
dependencies = [
"cfg-if",
"futures-core",
@ -3668,9 +3722,9 @@ dependencies = [
[[package]]
name = "web-sys"
version = "0.3.64"
version = "0.3.65"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b85cbef8c220a6abc02aefd892dfc0fc23afb1c6a426316ec33253a3877249b"
checksum = "5db499c5f66323272151db0e666cd34f78617522fb0c1604d31a27c50c206a85"
dependencies = [
"js-sys",
"wasm-bindgen",

View File

@ -15,9 +15,9 @@ gloo-utils = "0.2.0"
kcl-lib = { path = "kcl" }
kittycad = { workspace = true }
serde_json = "1.0.108"
uuid = { version = "1.5.0", features = ["v4", "js", "serde"] }
uuid = { version = "1.6.0", features = ["v4", "js", "serde"] }
wasm-bindgen = "0.2.88"
wasm-bindgen-futures = "0.4.37"
wasm-bindgen-futures = "0.4.38"
[dev-dependencies]
anyhow = "1"
@ -25,9 +25,9 @@ image = "0.24.7"
kittycad = { workspace = true, default-features = true }
pretty_assertions = "1.4.0"
reqwest = { version = "0.11.22", default-features = false }
tokio = { version = "1.33.0", features = ["rt-multi-thread", "macros", "time"] }
tokio = { version = "1.34.0", features = ["rt-multi-thread", "macros", "time"] }
twenty-twenty = "0.6.1"
uuid = { version = "1.5.0", features = ["v4", "js", "serde"] }
uuid = { version = "1.6.0", features = ["v4", "js", "serde"] }
[target.'cfg(target_arch = "wasm32")'.dependencies]
futures = "0.3.29"
@ -37,7 +37,7 @@ wasm-bindgen-futures = { version = "0.4.37", features = ["futures-core-03-stream
wasm-streams = "0.4.0"
[target.'cfg(target_arch = "wasm32")'.dependencies.web-sys]
version = "0.3.57"
version = "0.3.65"
features = [
"console",
"HtmlTextAreaElement",
@ -53,10 +53,11 @@ debug = true
members = [
"derive-docs",
"kcl",
"kcl-macros",
]
[workspace.dependencies]
kittycad = { version = "0.2.41", default-features = false, features = ["js"] }
kittycad = { version = "0.2.43", default-features = false, features = ["js"] }
[[test]]
name = "executor"

View File

@ -0,0 +1,22 @@
[package]
name = "kcl-macros"
description = "Macro for compiling KCL to its AST during Rust compile-time"
version = "0.1.0"
edition = "2021"
license = "MIT"
repository = "https://github.com/KittyCAD/modeling-app"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
proc-macro = true
[dependencies]
databake = "0.1.7"
kcl-lib = { path = "../kcl" }
proc-macro2 = "1"
quote = "1"
syn = { version = "2.0.39", features = ["full"] }
[dev-dependencies]
pretty_assertions = "1.4.0"

View File

@ -0,0 +1,23 @@
//! This crate contains macros for parsing KCL at Rust compile-time.
use databake::*;
use proc_macro::TokenStream;
use quote::quote;
use syn::{parse_macro_input, LitStr};
/// Parses KCL into its AST at compile-time.
/// This macro takes exactly one argument: A string literal containing KCL.
/// # Examples
/// ```
/// extern crate alloc;
/// use kcl_compile_macro::parse_kcl;
/// let ast: kcl_lib::ast::types::Program = parse_kcl!("const y = 4");
/// ```
#[proc_macro]
pub fn parse(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as LitStr);
let kcl_src = input.value();
let tokens = kcl_lib::token::lexer(&kcl_src);
let ast = kcl_lib::parser::Parser::new(tokens).ast().unwrap();
let ast_struct = ast.bake(&Default::default());
quote!(#ast_struct).into()
}

View File

@ -0,0 +1,38 @@
extern crate alloc;
use kcl_lib::ast::types::{
BodyItem, Identifier, Literal, LiteralValue, NonCodeMeta, Program, Value, VariableDeclaration, VariableDeclarator,
VariableKind,
};
use kcl_macros::parse;
use pretty_assertions::assert_eq;
#[test]
fn basic() {
let actual = parse!("const y = 4");
let expected = Program {
start: 0,
end: 11,
body: vec![BodyItem::VariableDeclaration(VariableDeclaration {
start: 0,
end: 11,
declarations: vec![VariableDeclarator {
start: 6,
end: 11,
id: Identifier {
start: 6,
end: 7,
name: "y".to_owned(),
},
init: Value::Literal(Box::new(Literal {
start: 10,
end: 11,
value: LiteralValue::IInteger(4),
raw: "4".to_owned(),
})),
}],
kind: VariableKind::Const,
})],
non_code_meta: NonCodeMeta::default(),
};
assert_eq!(expected, actual);
}

View File

@ -1,11 +1,13 @@
[package]
name = "kcl-lib"
description = "KittyCAD Language"
version = "0.1.35"
description = "KittyCAD Language implementation and tools"
version = "0.1.37"
edition = "2021"
license = "MIT"
repository = "https://github.com/KittyCAD/modeling-app"
rust-version = "1.73"
authors = ["Jess Frazelle", "Adam Chalmers", "KittyCAD, Inc"]
keywords = ["kcl", "KittyCAD", "CAD"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@ -13,33 +15,34 @@ rust-version = "1.73"
anyhow = { version = "1.0.75", features = ["backtrace"] }
async-recursion = "1.0.5"
async-trait = "0.1.73"
clap = { version = "4.4.7", features = ["cargo", "derive", "env", "unicode"], optional = true }
clap = { version = "4.4.8", features = ["cargo", "derive", "env", "unicode"], optional = true }
dashmap = "5.5.3"
databake = { version = "0.1.7", features = ["derive"] }
derive-docs = { version = "0.1.4" }
#derive-docs = { path = "../derive-docs" }
kittycad = { workspace = true }
lazy_static = "1.4.0"
parse-display = "0.8.2"
schemars = { version = "0.8", features = ["impl_json_schema", "url", "uuid1"] }
schemars = { version = "0.8.16", features = ["impl_json_schema", "url", "uuid1"] }
serde = { version = "1.0.192", features = ["derive"] }
serde_json = "1.0.108"
thiserror = "1.0.50"
ts-rs = { version = "7", package = "ts-rs-json-value", features = ["serde-json-impl", "schemars-impl", "uuid-impl"] }
uuid = { version = "1.5.0", features = ["v4", "js", "serde"] }
uuid = { version = "1.6.0", features = ["v4", "js", "serde"] }
winnow = "0.5.18"
[target.'cfg(target_arch = "wasm32")'.dependencies]
js-sys = { version = "0.3.65" }
tower-lsp = { version = "0.20.0", default-features = false, features = ["runtime-agnostic"] }
wasm-bindgen = "0.2.88"
wasm-bindgen-futures = "0.4.37"
web-sys = { version = "0.3.64", features = ["console"] }
wasm-bindgen-futures = "0.4.38"
web-sys = { version = "0.3.65", features = ["console"] }
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
bson = { version = "2.7.0", features = ["uuid-1", "chrono"] }
futures = { version = "0.3.29" }
reqwest = { version = "0.11.22", default-features = false }
tokio = { version = "1.33.0", features = ["full"] }
tokio = { version = "1.34.0", features = ["full"] }
tokio-tungstenite = { version = "0.20.0", features = ["rustls-tls-native-roots"] }
tower-lsp = { version = "0.20.0", features = ["proposed"] }
@ -59,9 +62,9 @@ debug = true # Flamegraphs of benchmarks require accurate debug symbols
criterion = "0.5.1"
expectorate = "1.1.0"
insta = { version = "1.34.0", features = ["json"] }
itertools = "0.11.0"
itertools = "0.12.0"
pretty_assertions = "1.4.0"
tokio = { version = "1.33.0", features = ["rt-multi-thread", "macros", "time"] }
tokio = { version = "1.34.0", features = ["rt-multi-thread", "macros", "time"] }
[[bench]]
name = "compiler_benchmark"

View File

@ -3,6 +3,7 @@
use std::{collections::HashMap, fmt::Write};
use anyhow::Result;
use databake::*;
use parse_display::{Display, FromStr};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
@ -20,7 +21,8 @@ use crate::{
mod literal_value;
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema, Bake)]
#[databake(path = kcl_lib::ast::types)]
#[ts(export)]
#[serde(rename_all = "camelCase")]
pub struct Program {
@ -219,11 +221,11 @@ impl Program {
if let Some(Value::FunctionExpression(ref mut function_expression)) = &mut value {
// Check if the params to the function expression contain the position.
for param in &mut function_expression.params {
let param_source_range: SourceRange = param.clone().into();
let param_source_range: SourceRange = (&param.identifier).into();
if param_source_range.contains(pos) {
let old_name = param.name.clone();
let old_name = param.identifier.name.clone();
// Rename the param.
param.rename(&old_name, new_name);
param.identifier.rename(&old_name, new_name);
// Now rename all the identifiers in the rest of the program.
function_expression.body.rename_identifiers(&old_name, new_name);
return;
@ -349,7 +351,8 @@ macro_rules! impl_value_meta {
pub(crate) use impl_value_meta;
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema, Bake)]
#[databake(path = kcl_lib::ast::types)]
#[ts(export)]
#[serde(tag = "type")]
pub enum BodyItem {
@ -388,7 +391,8 @@ impl From<&BodyItem> for SourceRange {
}
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema, Bake)]
#[databake(path = kcl_lib::ast::types)]
#[ts(export)]
#[serde(tag = "type")]
pub enum Value {
@ -551,7 +555,8 @@ impl From<&Value> for SourceRange {
}
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema, Bake)]
#[databake(path = kcl_lib::ast::types)]
#[ts(export)]
#[serde(tag = "type")]
pub enum BinaryPart {
@ -707,7 +712,8 @@ impl BinaryPart {
}
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema, Bake)]
#[databake(path = kcl_lib::ast::types)]
#[ts(export)]
#[serde(tag = "type")]
pub struct NonCodeNode {
@ -755,7 +761,8 @@ impl NonCodeNode {
}
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema, Bake)]
#[databake(path = kcl_lib::ast::types)]
#[ts(export)]
#[serde(rename_all = "camelCase")]
pub enum CommentStyle {
@ -765,7 +772,8 @@ pub enum CommentStyle {
Block,
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema, Bake)]
#[databake(path = kcl_lib::ast::types)]
#[ts(export)]
#[serde(tag = "type", rename_all = "camelCase")]
pub enum NonCodeValue {
@ -802,7 +810,8 @@ pub enum NonCodeValue {
NewLine,
}
#[derive(Debug, Default, Clone, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
#[derive(Debug, Default, Clone, Serialize, PartialEq, ts_rs::TS, JsonSchema, Bake)]
#[databake(path = kcl_lib::ast::types)]
#[ts(export)]
#[serde(rename_all = "camelCase")]
pub struct NonCodeMeta {
@ -843,7 +852,8 @@ impl NonCodeMeta {
}
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema, Bake)]
#[databake(path = kcl_lib::ast::types)]
#[ts(export)]
#[serde(tag = "type")]
pub struct ExpressionStatement {
@ -854,7 +864,8 @@ pub struct ExpressionStatement {
impl_value_meta!(ExpressionStatement);
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema, Bake)]
#[databake(path = kcl_lib::ast::types)]
#[ts(export)]
#[serde(tag = "type")]
pub struct CallExpression {
@ -991,7 +1002,11 @@ impl CallExpression {
// Add the arguments to the memory.
let mut fn_memory = memory.clone();
for (index, param) in function_expression.params.iter().enumerate() {
fn_memory.add(&param.name, fn_args.get(index).unwrap().clone(), param.into())?;
fn_memory.add(
&param.identifier.name,
fn_args.get(index).unwrap().clone(),
param.identifier.clone().into(),
)?;
}
// Call the stdlib function
@ -1122,7 +1137,8 @@ impl PartialEq for Function {
}
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema, Bake)]
#[databake(path = kcl_lib::ast::types)]
#[ts(export)]
#[serde(tag = "type")]
pub struct VariableDeclaration {
@ -1225,10 +1241,10 @@ impl VariableDeclaration {
symbol_kind = SymbolKind::FUNCTION;
let mut children = vec![];
for param in &function_expression.params {
let param_source_range: SourceRange = param.into();
let param_source_range: SourceRange = (&param.identifier).into();
#[allow(deprecated)]
children.push(DocumentSymbol {
name: param.name.clone(),
name: param.identifier.name.clone(),
detail: None,
kind: SymbolKind::VARIABLE,
range: param_source_range.to_lsp_range(code),
@ -1272,7 +1288,8 @@ impl VariableDeclaration {
}
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema, FromStr, Display)]
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema, FromStr, Display, Bake)]
#[databake(path = kcl_lib::ast::types)]
#[ts(export)]
#[serde(rename_all = "snake_case")]
#[display(style = "snake_case")]
@ -1316,7 +1333,8 @@ impl VariableKind {
}
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema, Bake)]
#[databake(path = kcl_lib::ast::types)]
#[ts(export)]
#[serde(tag = "type")]
pub struct VariableDeclarator {
@ -1345,7 +1363,8 @@ impl VariableDeclarator {
}
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema, Bake)]
#[databake(path = kcl_lib::ast::types)]
#[ts(export)]
#[serde(tag = "type")]
pub struct Literal {
@ -1415,7 +1434,8 @@ impl From<&Box<Literal>> for MemoryItem {
}
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema, Bake, Eq)]
#[databake(path = kcl_lib::ast::types)]
#[ts(export)]
#[serde(tag = "type")]
pub struct Identifier {
@ -1451,7 +1471,8 @@ impl Identifier {
}
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema, Bake)]
#[databake(path = kcl_lib::ast::types)]
#[ts(export)]
#[serde(tag = "type")]
pub struct PipeSubstitution {
@ -1479,7 +1500,8 @@ impl From<PipeSubstitution> for Value {
}
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema, Bake)]
#[databake(path = kcl_lib::ast::types)]
#[ts(export)]
#[serde(tag = "type")]
pub struct ArrayExpression {
@ -1639,7 +1661,8 @@ impl ArrayExpression {
}
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema, Bake)]
#[databake(path = kcl_lib::ast::types)]
#[ts(export)]
#[serde(tag = "type")]
pub struct ObjectExpression {
@ -1796,7 +1819,8 @@ impl ObjectExpression {
impl_value_meta!(ObjectExpression);
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema, Bake)]
#[databake(path = kcl_lib::ast::types)]
#[ts(export)]
#[serde(tag = "type")]
pub struct ObjectProperty {
@ -1838,7 +1862,8 @@ impl ObjectProperty {
}
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema, Bake)]
#[databake(path = kcl_lib::ast::types)]
#[ts(export)]
#[serde(tag = "type")]
pub enum MemberObject {
@ -1884,7 +1909,8 @@ impl From<&MemberObject> for SourceRange {
}
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema, Bake)]
#[databake(path = kcl_lib::ast::types)]
#[ts(export)]
#[serde(tag = "type")]
pub enum LiteralIdentifier {
@ -1920,7 +1946,8 @@ impl From<&LiteralIdentifier> for SourceRange {
}
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema, Bake)]
#[databake(path = kcl_lib::ast::types)]
#[ts(export)]
#[serde(tag = "type")]
pub struct MemberExpression {
@ -2083,7 +2110,8 @@ pub struct ObjectKeyInfo {
pub computed: bool,
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema, Bake)]
#[databake(path = kcl_lib::ast::types)]
#[ts(export)]
#[serde(tag = "type")]
pub struct BinaryExpression {
@ -2262,7 +2290,8 @@ pub fn parse_json_value_as_string(j: &serde_json::Value) -> Option<String> {
}
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema, FromStr, Display)]
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema, FromStr, Display, Bake)]
#[databake(path = kcl_lib::ast::types)]
#[ts(export)]
#[serde(rename_all = "snake_case")]
#[display(style = "snake_case")]
@ -2330,7 +2359,8 @@ impl BinaryOperator {
}
}
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema, Bake)]
#[databake(path = kcl_lib::ast::types)]
#[ts(export)]
#[serde(tag = "type")]
pub struct UnaryExpression {
@ -2408,7 +2438,8 @@ impl UnaryExpression {
}
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema, FromStr, Display)]
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema, FromStr, Display, Bake)]
#[databake(path = kcl_lib::ast::types)]
#[ts(export)]
#[serde(rename_all = "snake_case")]
#[display(style = "snake_case")]
@ -2423,7 +2454,8 @@ pub enum UnaryOperator {
Not,
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema, Bake)]
#[databake(path = kcl_lib::ast::types)]
#[ts(export)]
#[serde(rename_all = "camelCase", tag = "type")]
pub struct PipeExpression {
@ -2581,13 +2613,26 @@ async fn execute_pipe_body(
}
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
/// Parameter of a KCL function.
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema, Bake)]
#[databake(path = kcl_lib::ast::types)]
#[ts(export)]
#[serde(tag = "type")]
pub struct Parameter {
/// The parameter's label or name.
pub identifier: Identifier,
/// Is the parameter optional?
pub optional: bool,
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema, Bake)]
#[databake(path = kcl_lib::ast::types)]
#[ts(export)]
#[serde(tag = "type")]
pub struct FunctionExpression {
pub start: usize,
pub end: usize,
pub params: Vec<Identifier>,
pub params: Vec<Parameter>,
pub body: Program,
}
@ -2613,7 +2658,7 @@ impl FunctionExpression {
"({}) => {{\n{}{}\n}}",
self.params
.iter()
.map(|param| param.name.clone())
.map(|param| param.identifier.name.clone())
.collect::<Vec<String>>()
.join(", "),
options.get_indentation(indentation_level + 1),
@ -2631,7 +2676,8 @@ impl FunctionExpression {
}
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema, Bake)]
#[databake(path = kcl_lib::ast::types)]
#[ts(export)]
#[serde(tag = "type")]
pub struct ReturnStatement {

View File

@ -1,10 +1,12 @@
use databake::*;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use serde_json::Value as JValue;
use super::{Literal, Value};
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema, Bake)]
#[databake(path = kcl_lib::ast::types)]
#[ts(export)]
#[serde(untagged, rename_all = "snake_case")]
pub enum LiteralValue {

View File

@ -88,11 +88,7 @@ impl EngineConnection {
let ws_stream = tokio_tungstenite::WebSocketStream::from_raw_socket(
ws,
tokio_tungstenite::tungstenite::protocol::Role::Client,
Some(tokio_tungstenite::tungstenite::protocol::WebSocketConfig {
write_buffer_size: 1024 * 128,
max_write_buffer_size: 1024 * 256,
..Default::default()
}),
Some(tokio_tungstenite::tungstenite::protocol::WebSocketConfig { ..Default::default() }),
)
.await;

View File

@ -795,7 +795,9 @@ pub async fn execute(
for statement in &program.body {
match statement {
BodyItem::ExpressionStatement(expression_statement) => {
if let Value::CallExpression(call_expr) = &expression_statement.expression {
if let Value::PipeExpression(pipe_expr) = &expression_statement.expression {
pipe_expr.get_result(memory, &mut pipe_info, ctx).await?;
} else if let Value::CallExpression(call_expr) = &expression_statement.expression {
let fn_name = call_expr.callee.name.to_string();
let mut args: Vec<MemoryItem> = Vec::new();
for arg in &call_expr.arguments {
@ -906,9 +908,9 @@ pub async fn execute(
// Add the arguments to the memory.
for (index, param) in function_expression.params.iter().enumerate() {
fn_memory.add(
&param.name,
&param.identifier.name,
args.get(index).unwrap().clone(),
param.into(),
(&param.identifier).into(),
)?;
}

View File

@ -1,3 +1,7 @@
//! Rust support for KCL (aka the KittyCAD Language).
//!
//! KCL is written in Rust. This crate contains the compiler tooling (e.g. parser, lexer, code generation),
//! the standard library implementation, a LSP implementation, generator for the docs, and more.
#![recursion_limit = "1024"]
pub mod ast;

View File

@ -12,7 +12,7 @@ use crate::{
ArrayExpression, BinaryExpression, BinaryOperator, BinaryPart, BodyItem, CallExpression, CommentStyle,
ExpressionStatement, FunctionExpression, Identifier, Literal, LiteralIdentifier, LiteralValue,
MemberExpression, MemberObject, NonCodeMeta, NonCodeNode, NonCodeValue, ObjectExpression, ObjectProperty,
PipeExpression, PipeSubstitution, Program, ReturnStatement, UnaryExpression, UnaryOperator, Value,
Parameter, PipeExpression, PipeSubstitution, Program, ReturnStatement, UnaryExpression, UnaryOperator, Value,
VariableDeclaration, VariableDeclarator, VariableKind,
},
errors::{KclError, KclErrorDetails},
@ -1208,26 +1208,62 @@ fn arguments(i: TokenSlice) -> PResult<Vec<Value>> {
.parse_next(i)
}
fn not_close_paren(i: TokenSlice) -> PResult<Token> {
fn required_param(i: TokenSlice) -> PResult<Token> {
any.verify(|token: &Token| !matches!(token.token_type, TokenType::Brace) || token.value != ")")
.parse_next(i)
}
fn optional_param(i: TokenSlice) -> PResult<Token> {
let token = required_param.parse_next(i)?;
let _question_mark = one_of(TokenType::QuestionMark).parse_next(i)?;
Ok(token)
}
/// Parameters are declared in a function signature, and used within a function.
fn parameters(i: TokenSlice) -> PResult<Vec<Identifier>> {
fn parameters(i: TokenSlice) -> PResult<Vec<Parameter>> {
// Get all tokens until the next ), because that ends the parameter list.
let candidates: Vec<Token> = separated(0.., not_close_paren, comma_sep)
let candidates: Vec<_> = separated(
0..,
alt((optional_param.map(|t| (t, true)), required_param.map(|t| (t, false)))),
comma_sep,
)
.context(expected("function parameters"))
.parse_next(i)?;
// Make sure all those tokens are valid parameters.
let params = candidates
let params: Vec<Parameter> = candidates
.into_iter()
.map(|token| Identifier::try_from(token).and_then(Identifier::into_valid_binding_name))
.map(|(token, optional)| {
let identifier = Identifier::try_from(token).and_then(Identifier::into_valid_binding_name)?;
Ok(Parameter { identifier, optional })
})
.collect::<Result<_, _>>()
.map_err(|e| ErrMode::Backtrack(ContextError::from(e)))?;
.map_err(|e: KclError| ErrMode::Backtrack(ContextError::from(e)))?;
// Make sure optional parameters are last.
if let Err(e) = optional_after_required(&params) {
return Err(ErrMode::Cut(ContextError::from(e)));
}
Ok(params)
}
fn optional_after_required(params: &[Parameter]) -> Result<(), KclError> {
let mut found_optional = false;
for p in params {
if p.optional {
found_optional = true;
}
if !p.optional && found_optional {
let e = KclError::Syntax(KclErrorDetails {
source_ranges: vec![(&p.identifier).into()],
message: "mandatory parameters must be declared before optional parameters".to_owned(),
});
return Err(e);
}
}
Ok(())
}
impl Identifier {
fn into_valid_binding_name(self) -> Result<Identifier, KclError> {
// Make sure they are not assigning a variable to a stdlib function.
@ -1895,7 +1931,7 @@ const mySk1 = startSketchAt([0, 0])"#;
let tokens = crate::token::lexer(input);
let actual = parameters.parse(&tokens);
assert!(actual.is_ok(), "could not parse test {i}");
let actual_ids: Vec<_> = actual.unwrap().into_iter().map(|id| id.name).collect();
let actual_ids: Vec<_> = actual.unwrap().into_iter().map(|p| p.identifier.name).collect();
assert_eq!(actual_ids, expected);
}
}
@ -2322,6 +2358,82 @@ e
assert!(result.err().unwrap().to_string().contains("Unexpected token"));
}
#[test]
fn test_optional_param_order() {
for (i, (params, expect_ok)) in [
(
vec![Parameter {
identifier: Identifier {
start: 0,
end: 0,
name: "a".to_owned(),
},
optional: true,
}],
true,
),
(
vec![Parameter {
identifier: Identifier {
start: 0,
end: 0,
name: "a".to_owned(),
},
optional: false,
}],
true,
),
(
vec![
Parameter {
identifier: Identifier {
start: 0,
end: 0,
name: "a".to_owned(),
},
optional: false,
},
Parameter {
identifier: Identifier {
start: 0,
end: 0,
name: "b".to_owned(),
},
optional: true,
},
],
true,
),
(
vec![
Parameter {
identifier: Identifier {
start: 0,
end: 0,
name: "a".to_owned(),
},
optional: true,
},
Parameter {
identifier: Identifier {
start: 0,
end: 0,
name: "b".to_owned(),
},
optional: false,
},
],
false,
),
]
.into_iter()
.enumerate()
{
let actual = optional_after_required(&params);
assert_eq!(actual.is_ok(), expect_ok, "failed test {i}");
}
}
#[test]
fn test_parse_expand_array() {
let code = "const myArray = [0..10]";
@ -2801,4 +2913,5 @@ mod snapshot_tests {
snapshot_test!(ar, r#"5 + "a""#);
snapshot_test!(at, "line([0, l], %)");
snapshot_test!(au, include_str!("../../../tests/executor/inputs/cylinder.kcl"));
snapshot_test!(av, "fn f = (angle?) => { return default(angle, 360) }");
}

View File

@ -29,10 +29,13 @@ expression: actual
"end": 49,
"params": [
{
"identifier": {
"type": "Identifier",
"start": 12,
"end": 17,
"name": "param"
},
"optional": false
}
],
"body": {

View File

@ -0,0 +1,97 @@
---
source: kcl/src/parser/parser_impl.rs
expression: actual
---
{
"start": 0,
"end": 49,
"body": [
{
"type": "VariableDeclaration",
"type": "VariableDeclaration",
"start": 0,
"end": 49,
"declarations": [
{
"type": "VariableDeclarator",
"start": 3,
"end": 49,
"id": {
"type": "Identifier",
"start": 3,
"end": 4,
"name": "f"
},
"init": {
"type": "FunctionExpression",
"type": "FunctionExpression",
"start": 7,
"end": 49,
"params": [
{
"identifier": {
"type": "Identifier",
"start": 8,
"end": 13,
"name": "angle"
},
"optional": true
}
],
"body": {
"start": 19,
"end": 49,
"body": [
{
"type": "ReturnStatement",
"type": "ReturnStatement",
"start": 21,
"end": 47,
"argument": {
"type": "CallExpression",
"type": "CallExpression",
"start": 28,
"end": 47,
"callee": {
"type": "Identifier",
"start": 28,
"end": 35,
"name": "default"
},
"arguments": [
{
"type": "Identifier",
"type": "Identifier",
"start": 36,
"end": 41,
"name": "angle"
},
{
"type": "Literal",
"type": "Literal",
"start": 43,
"end": 46,
"value": 360,
"raw": "360"
}
],
"optional": false
}
}
],
"nonCodeMeta": {
"nonCodeNodes": {},
"start": []
}
}
}
}
],
"kind": "fn"
}
],
"nonCodeMeta": {
"nonCodeNodes": {},
"start": []
}
}

View File

@ -47,6 +47,8 @@ pub enum TokenType {
Function,
/// Unknown lexemes.
Unknown,
/// The ? symbol, used for optional values.
QuestionMark,
}
/// Most KCL tokens correspond to LSP semantic tokens (but not all).
@ -58,6 +60,7 @@ impl TryFrom<TokenType> for SemanticTokenType {
TokenType::Word => Self::VARIABLE,
TokenType::Keyword => Self::KEYWORD,
TokenType::Operator => Self::OPERATOR,
TokenType::QuestionMark => Self::OPERATOR,
TokenType::String => Self::STRING,
TokenType::LineComment => Self::COMMENT,
TokenType::BlockComment => Self::COMMENT,

View File

@ -21,6 +21,7 @@ pub fn token(i: &mut Located<&str>) -> PResult<Token> {
'{' | '(' | '[' => brace_start,
'}' | ')' | ']' => brace_end,
',' => comma,
'?' => question_mark,
'0'..='9' => number,
':' => colon,
'.' => alt((number, double_period, period)),
@ -108,6 +109,11 @@ fn comma(i: &mut Located<&str>) -> PResult<Token> {
Ok(Token::from_range(range, TokenType::Comma, value.to_string()))
}
fn question_mark(i: &mut Located<&str>) -> PResult<Token> {
let (value, range) = '?'.with_span().parse_next(i)?;
Ok(Token::from_range(range, TokenType::QuestionMark, value.to_string()))
}
fn colon(i: &mut Located<&str>) -> PResult<Token> {
let (value, range) = ':'.with_span().parse_next(i)?;
Ok(Token::from_range(range, TokenType::Colon, value.to_string()))

View File

@ -518,3 +518,23 @@ show(part)"#;
let result = execute_and_snapshot(code).await.unwrap();
twenty_twenty::assert_image("tests/executor/outputs/rounded_with_holes.png", &result, 0.999);
}
#[tokio::test(flavor = "multi_thread")]
async fn serial_test_top_level_expression() {
let code = r#"fn circle = (pos, radius) => {
const sg = startSketchOn('XY')
|> startProfileAt([pos[0] + radius, pos[1]], %)
|> arc({
angle_end: 360,
angle_start: 0,
radius: radius
}, %)
|> close(%)
return sg
}
circle([0,0], 22) |> extrude(14, %)"#;
let result = execute_and_snapshot(code).await.unwrap();
twenty_twenty::assert_image("tests/executor/outputs/top_level_expression.png", &result, 0.999);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

1068
yarn.lock

File diff suppressed because it is too large Load Diff