Compare commits

...

73 Commits

Author SHA1 Message Date
eb2327827b Release KCL 77 (#7188) 2025-05-23 18:54:04 +00:00
1f53dd1357 KCL: [number; 3] to RGB hex string color function (#7184)
Closes https://github.com/KittyCAD/modeling-app/issues/6805. Enables users to programatically construct colors, which will be helpful for 

- Applying color to visualize program execution and help debugging
- Doing weird cool shit
2025-05-23 13:53:58 -05:00
034366e65e Bugfix: formatter changed [0..<4] to [0..4] (#7186)
In #7179 I added exclusive ranges for KCL, but I forgot to update the
formatter/unparser to handle them. So it was silently changing exclusive-end
ranges to inclusive-end ranges.
2025-05-23 17:03:46 +00:00
cd537cd9c2 Remove the version badge on web signin (#7187)
Thanks @jacebrowning for reporting
2025-05-23 16:52:23 +00:00
22f92942f6 #6567 Code errors disappear when closing and reopening the editor (#7166)
* Fix error of not showing errors when reopening KCL code pane

* add test for errors not shown after reopening code pane

* rename test

* typo in e2e/playwright/editor-tests.spec.ts

Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>

* lint

* fmt

* fix test: Opening and closing the code pane will consistently show error diagnostics

* PR feedback: use catch(reportRejection) for safeParse

* no need for lint rule

---------

Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
2025-05-23 12:41:37 -04:00
4eee50d79e Remove Owners font from the modeling app (#7185)
Our team started getting *rate limited* with access to the font, which
meant the app wasn't loading for them 😱. I don't want us to risk any
user being rate limited because of a font ever.
2025-05-23 12:33:05 -04:00
125b2c44d4 Clean up release process readme (#7182)
* Clean up release process readme

* Update CONTRIBUTING.md

Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>

---------

Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
2025-05-23 11:22:39 -04:00
db9e35d686 Fix mirror2d selection by adding artifact graph support (#7178)
* Add artifact graph support for mirror2d

* Update output

* Disable test that can't pass
2025-05-23 11:16:36 -04:00
d0958220fe KCL: End-exclusive ranges like [0..<10] (#7179)
Closes https://github.com/KittyCAD/modeling-app/issues/6843

To clarify:
`[1..10]` is 1, 2, ..., 8, 9, 10
`[1..<10]` is 1, 2, ... 8, 9
2025-05-22 22:13:27 -05:00
fa4b3cfd1b Change artifact panics to runtime errors (#7177)
* Change artifact panics to runtime errors

* Condense format!()

* Remove unwrap
2025-05-22 17:48:19 -04:00
8972f8f109 Fix up the sign-in page's mobile layout (#7176)
@JBEmbedded pointed this out, and we don't want a bad look for website
browsers who click a stray "Try in Browser" link. There's a little
message saying we're working on touch controls for now, and we steal
their signin button.
2025-05-22 21:31:06 +00:00
85ccc6900c Do multiple chamfer/fillet in one API call (#6750)
KCL's `fillet` function takes an array of edges to fillet. Previously this would do `n` fillet API commands, one per edge. This PR combines them all into one call, which should improve performance. You can see the effect in the  artifact_commands snapshots, e.g. `rust/kcl-lib/tests/kcl_samples/axial-fan/artifact_commands.snap` 

Besides performance, this should fix a bug where some KCL fillets would fail, when they should have succeeded. Example from @max-mrgrsk:

```kcl
sketch001 = startSketchOn(XY)
  |> startProfile(at = [-12, -6])
  |> line(end = [0, 12], tag = $seg04)
  |> line(end = [24, 0], tag = $seg03)
  |> line(end = [0, -12], tag = $seg02)
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)], tag = $seg01)
  |> close()
extrude001 = extrude(
       sketch001,
       length = 12,
       tagEnd = $capEnd001,
       tagStart = $capStart001,
     )
  |> fillet(
       radius = 5,
       tags = [
         getCommonEdge(faces = [seg02, capEnd001]),
         getCommonEdge(faces = [seg01, capEnd001]),
         getCommonEdge(faces = [seg03, capEnd001]),
         getCommonEdge(faces = [seg04, capEnd001])
       ],
     )
```

This program fails on main, but succeeds on this branch.
2025-05-22 21:25:55 +00:00
4e2deca5d8 KCL: Set sensible defaults for pattern 'axis' arg (#7168) 2025-05-22 14:24:21 -05:00
04a2c184d7 KCL: Absolute point bezier curves (#7172)
Previously KCL bezier curves could only use relative control points. Now you can use absolute control points too. 

Here's an example of the new arguments:

```kcl
startSketchOn(XY)
  |> startProfile(at = [300, 300])
  |> bezierCurve(control1Absolute = [600, 300], control2Absolute = [-300, -100], endAbsolute = [600, 300])
  |> close()
  |> extrude(length = 10)
```

Closes https://github.com/KittyCAD/modeling-app/issues/7083
2025-05-22 13:06:06 -04:00
2c7701e2d4 Add markdown rendering to TTC error toast, with component tests (#7170)
Closes #5792. I tried to move these over to our new component test
bucket, but Remark doesn't play nice with that testing setup at least in
my initial attempts.
2025-05-22 13:00:21 -04:00
ae569b61db Use typed KclValue instead of any in sketchFromKclValue (#7144)
* use KclValue instead of any

* no need for any in sketchFromKclValueOptional

* simplify error reason for sketchFromKclValueOptional
2025-05-22 11:15:31 +02:00
0a0e6abd3f KCL: Autocomplete snippets for 'center' should suggest the origin (#7164)
Pattern functions and `polygon` both take a parameter `center` which
defaulted to [3.14, 3.14] for silly reasons. They now default to
[0, 0].
2025-05-22 04:08:34 +00:00
9c7aee32bd KCL: Custom snippet values for kcl-in-kcl (#7163)
In #7156, I allowed KCL to set specific snippet completions for each arg of each function. They're optional -- if you don't set one, it'll fall back to the type-driven defaults.

That PR only worked for KCL stdlib functions defined in Rust. This PR enables the same feature, but for functions defined in KCL.
2025-05-21 22:16:04 -05:00
ed979d807b Fix ascription to array type to not convert units (#7160) 2025-05-22 09:22:30 +12:00
f5c244dbb1 KCL: stdlib macro should now assume all functions use keywords (#7158)
This has been enforced by the parser since #6639, so there's no need for `keywords = true` in every stdlib function anymore.
2025-05-21 21:10:40 +00:00
0ea1e9a6da KCL: Customizable per-arg and per-fn snippet values (#7156)
Before, the LSP snippet for `startProfile` was 

```
startProfile(%, at = [3.14, 3.14])
```

Now it's 

```
startProfile(%, at = [0, 0])
```

This is configured by adding a `snippet_value=` field to the stdlib macro. For example:


```diff
#[stdlib {
    name = "startProfile",
    keywords = true,
    unlabeled_first = true,
    args = {
        sketch_surface = { docs = "What to start the profile on" },
-       at = { docs = "Where to start the profile. An absolute point." },
+       at = { docs = "Where to start the profile. An absolute point.", snippet_value = "[0, 0]" },        tag = { docs = "Tag this first starting point" },
    },
    tags = ["sketch"]
}]
```

## Work for follow-up PRs

 - Make this work for KCL functions defined in KCL, e.g. [`fn circle`](36c8ad439d/rust/kcl-lib/std/sketch.kcl (L31-L32)) -- something like `@(snippet_value = "[0, 0]")` perhaps
 - Go through the stdlib and change defaults where appropriate
2025-05-21 20:18:20 +00:00
a36530d6df Make Create with Zoo ML the default again (#7159) 2025-05-21 18:29:03 +00:00
825d34718a Update telemetry antenna entity names (#7155)
* Update telemetry antenna entity names

Changed the generic sketch and profile entity names to more specific names

* Update kcl-samples simulation test output

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2025-05-21 15:46:05 +00:00
d90d445d84 Pass the query parameters through to sign-in flow (#7157)
* Pass the query parameters through to sign-in flow

So users can return to their invoked command after signing in

* Don't run query param commands if not logged in
2025-05-21 15:32:52 +00:00
5976a0cba6 Change to skip asserting the artifact graph for samples (#7153)
* Change to skip asserting the artifact graph for samples

* Fix clippy warning
2025-05-21 14:51:31 +00:00
b50f2f5a2a Link to the dedicated page when there is intent to download (#7152) 2025-05-21 14:20:36 +00:00
f877b52898 Update telemetry antenna (#7150)
* Update telemetry antenna

* Update kcl-samples simulation test output

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2025-05-21 10:05:56 -04:00
4a585db637 Link to the new download page (#7149) 2025-05-21 13:42:11 +00:00
4d404bf137 Delete redundant Text-to-CAD tests (#7118) 2025-05-21 13:33:32 +00:00
e644b7e1fc Run the KCL tests every hour to detect regressions (#7139) 2025-05-21 09:21:04 -04:00
aff1684064 Chrome toast touchup (#7148) 2025-05-21 08:47:40 -04:00
d9afc50f91 Nickmccleery/add more samples (#7145) 2025-05-21 12:27:43 +00:00
eb7b4ccda6 Fix web app issue with search params on Safari (#7147)
* pierremtb/adhoc/safari-link-issue

* Fix both places with [...searchParams.entries()]
2025-05-21 12:06:17 +00:00
bbf4f1d251 Add title line which I didn't know did anything important. (#7135) 2025-05-21 09:00:21 +00:00
3cc7859ca5 load samples on web (#7142)
* load samples on web

* Update src/hooks/useQueryParamEffects.ts

Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>

---------

Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
2025-05-21 07:59:42 +00:00
ab63345c57 Run std lib example tests one at a time (#7127)
Signed-off-by: Nick Cameron <nrc@ncameron.org>
2025-05-21 05:20:36 +00:00
3df02e02fa Release 76 (#7138) 2025-05-21 02:39:32 +00:00
35f5c62633 Don't race exiting a sketch scene (#7128)
* Turn sketch exit execute into actor, no more racey exits

* Turn sketch exit execute into actor, no more racey exits

* Fix types

---------

Co-authored-by: Frank Noirot <frank@zoo.dev>
2025-05-21 01:09:16 +00:00
0f0fc39d07 Add display of array element types in error messages (#7113)
* Add test showing unhelpful error message

* Add display of array element types in error messages

* Change to prose description

* Update output
2025-05-20 20:50:24 -04:00
a13b6b2b70 Fix open KCL sample via URL query param in browser (#7133)
There is now a `projectName` that isn't included in the query params I
was using and wasn't including in the URLs I was building.
2025-05-20 20:48:23 -04:00
4212b95232 Add KCL importing relative to where you're importing from (#7125)
* add test

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* Add importing relative to where you're importing from

* Update output

* Remove runtime panics

* Change to debug_assert

---------

Signed-off-by: Jess Frazelle <github@jessfraz.com>
Co-authored-by: Jess Frazelle <github@jessfraz.com>
2025-05-21 00:47:32 +00:00
38a73a603b Update output to match latest (#7129) 2025-05-21 00:45:41 +00:00
c48d9fd4d7 Allow point-and-click Insert to suggest nested files (#7130)
* fix: saving off code

* fix: saving off progress

* chore: implemented kcl sample assembly unique sub dir creation

* fix: removing testing console logs

* fix: cleaning up old comment

* fix: add to file always does subdir/main.kcl now for single files

* fix: auto fmt

* fix: delete project and folder from ttc

* fix: fixed deleting projects and subdirs

* fix: if statement logic fixed for deleting project or subdir

* fix: TTC isProjectNew makes main.kcl not a subdir.

* fix: fixing e2e test

* fix: this should pass now

* pierremtb/make-insert-take-over-the-import-world

* Add test that doesn't work locally yet :(

* Fix test 🤦

* Change splice for push

* Fix up windows path

---------

Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Kevin Nadro <nadr0@users.noreply.github.com>
2025-05-20 20:44:22 -04:00
0753987b5a [Fix]: Allow importing assemblies into exsiting projects and handling the collision (#7108)
* fix: saving off code

* fix: saving off progress

* chore: implemented kcl sample assembly unique sub dir creation

* fix: removing testing console logs

* fix: cleaning up old comment

* fix: add to file always does subdir/main.kcl now for single files

* fix: auto fmt

* fix: delete project and folder from ttc

* fix: fixed deleting projects and subdirs

* fix: if statement logic fixed for deleting project or subdir

* fix: TTC isProjectNew makes main.kcl not a subdir.

* fix: fixing e2e test

* fix: this should pass now
2025-05-20 19:03:54 -04:00
815ff7dc2b more subtract regression tests (#7123)
* more regression tests

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* snaps

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* iupdates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

---------

Signed-off-by: Jess Frazelle <github@jessfraz.com>
2025-05-20 16:02:44 -07:00
46684d420d Test nested imports on all platforms (#7126) 2025-05-20 18:45:04 -04:00
eca09984a3 Fix: Follow up Text-to-CAD Edit to fix in browser (#7124)
* fix: web vs desktop who wins

* fix: fixed logic round two :(
2025-05-20 21:11:31 +00:00
ce63c6423e Impove naming in point-and-click Revolve to convey that axis are relative (#7122)
* Better axis options in point-and-click Revolve to convey the axis are relative
Fixes #7121

* Less changes
2025-05-20 16:57:55 -04:00
09699afe82 Fix: Can't go back to Profiles arg in Extrude, Revolve, Loft (#7106)
* Revert "Update failing E2E tests with new behavior, which allows skip with preselection"

This reverts commit d72bee8637.

* Fix: Can't go back to Profiles step in sweep commands
Fixes #7080

* Make it better but still not quite there

* I think I got it: this was likely the real bug making submit fire twice

* Bring timemouts back
2025-05-20 20:07:56 +00:00
36c8ad439d KCL: Add diameter arg to circle (#7116)
Paul's been requesting this for a long time. Now that we're fully using keyword args, this is easy to do.

We should probably add a similar `diameter` arg to `arc`, `tangentialArc`, `polygon` etc. And _maybe_ to `fillet`, but that might not be as helpful.
2025-05-20 19:44:35 +00:00
5dc77ceed5 Only start saving camera after scene is ready (#7120) 2025-05-20 15:12:08 -04:00
c7baa26b2d idiomatic kcl for hip sample (#7095)
* idiomatic kcl for hip sample

* Update kcl-samples simulation test output

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

---------

Signed-off-by: Jess Frazelle <github@jessfraz.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Jess Frazelle <github@jessfraz.com>
2025-05-20 11:36:08 -07:00
4d0454abcd Remove old ZMA logos, rip out JS theme state from open-in-desktop view (#7119)
* Remove old ZMA logos, rip out JS theme state from open-in-desktop view

Make this page dumber so that it doesn't break

* Lint and remove kcma refs

---------

Co-authored-by: Pierre Jacquier <pierre@zoo.dev>
2025-05-20 18:13:58 +00:00
1dafbf105e Identify distinct test suites (#7109) 2025-05-20 12:56:55 -04:00
773f013115 [Fix]: When loading the modeling page the user's settings for camera projection was ignored (#7111)
* fix: initialization of user camera projection is now used again, ope

* fix: removing comment
2025-05-20 12:46:53 -04:00
c5cd460595 Show error when trying to export at non-top-level (#7110) 2025-05-20 12:43:11 -04:00
845352046b Modeling machine unit tests (#7098)
* successfully transition to sketch idle

* get constraint to mod code

* clean up

* remove .only

* Fixed tsc

---------

Co-authored-by: lee-at-zoo-corp <lee@zoo.dev>
2025-05-20 12:22:52 -04:00
597f1087f9 Fix enter key loop in sweep commands (#7112)
* use effect for focus of command palette submit button, not autoFocus

autoFocus is being overridden by the Headless UI Dialog component's
focus management here
https://headlessui.com/v1/react/dialog#focus-management (we do not have
access to pass back initialFocus in this case). So we can use an effect
to imperatively focus the button when this component is mounted.

* Update sweep tests to submit the command with Enter
2025-05-20 16:04:56 +00:00
511334683a test: Add regression test for importing only at the top level (#7104)
Add regression test for importing only at the top level
2025-05-20 11:43:48 -04:00
223a4ad45d Style the experimental badge to match the website (#7100)
* Style the experimental badge to match the website

* Match the styling of the rest of the app

We don't use all apps monospace fonts anywhere.

* Bring back all caps
2025-05-20 14:57:53 +00:00
edf31ec1d3 Make the textarea command bar input run its resize initially (#7103)
We have a hook to auto-grow the textarea input but it wasn't running
once initially. This is noticable on the onboarding, where we show the
user a long Text-to-CAD Edit prompt that overflows.
2025-05-20 10:56:03 -04:00
1539557005 Always update snapshots if needed (#7105) 2025-05-20 14:34:26 +00:00
1d3ba4e3ac [Fix]: Remove console logs (#7102)
* fix: these got in when they should not have

* fix: spacemacs found wrong eslint again biome thing..
2025-05-20 14:12:32 +00:00
4110aa00db Only update snapshots for tests that repeatedly fail (#7101)
* Only update snapshots for tests that repeatedly fail

* Let TAB silence snapshot capture failures as well
2025-05-20 14:00:33 +00:00
7eb52cda36 Fix: creating a dir ending with .kcl panics the app (#7099)
* Fix: creating a dir ending with .kcl panics the app
Fixes #7082

* Update snapshots

* Update snapshots

* Add test

* tag: ['@electron', '@macos', '@windows']

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2025-05-20 13:53:26 +00:00
7872fb9cbd Update snapshots on CI (#7069) 2025-05-20 06:00:31 -04:00
651181e62c Restrict subdirectory imports to main.kcl (#7094)
Signed-off-by: Nick Cameron <nrc@ncameron.org>
2025-05-20 18:13:17 +12:00
max
38a245f2fc fix typos in the kcl samples (#7078)
typos
2025-05-20 05:47:33 +00:00
1b4289f93f allow nested files imported (#7090)
* allow nested files

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* fix test

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* disallow bad things

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* add playwright test on windows

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* add playwright test on windows

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* fixes

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* fix test

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* Update rust/kcl-lib/tests/nested_windows_main_kcl/unparsed@main.kcl.snap

Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

---------

Signed-off-by: Jess Frazelle <github@jessfraz.com>
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
2025-05-19 22:42:25 -04:00
d0697c24fd Change Sketch to use the units of the module (#7076)
* Change Sketch to use the units of the module

* Update output
2025-05-19 20:20:47 -04:00
8c24e29081 [Fix]: P2E base path is always the project directory, P2E when completed stays in your current file (#7091)
* fix: fixes for p2e

* fix: yep tsc fixes

* fix: fixing reject workflow and navigate
2025-05-19 20:05:38 -04:00
2b9d26e2ff Make Text-to-CAD Edit the default workflow in the toolbar (#7092)
We want users to make edits first and foremost within projects, so we're
going to surface it as the default workflow button in the toolbar. WIP
until I verify that tests are okay with this.
2025-05-19 19:58:18 -04:00
ab148a7654 Fix: Esc key doesn't work in Text-to-CAD prompt (#7089)
* Fix: Esc key doesn't work in Text-to-CAD prompt
Fixes #7086

* Add e2e test because why not
2025-05-19 23:31:33 +00:00
336 changed files with 48464 additions and 11441 deletions

View File

@ -6,6 +6,7 @@ if [ -z "${TAB_API_URL:-}" ] || [ -z "${TAB_API_KEY:-}" ]; then
fi
project="https://github.com/KittyCAD/modeling-app"
suite="${CI_SUITE:-unit}"
branch="${GITHUB_HEAD_REF:-${GITHUB_REF_NAME:-}}"
commit="${CI_COMMIT_SHA:-${GITHUB_SHA:-}}"
@ -13,6 +14,7 @@ echo "Uploading batch results"
curl --silent --request POST \
--header "X-API-Key: ${TAB_API_KEY}" \
--form "project=${project}" \
--form "suite=${suite}" \
--form "branch=${branch}" \
--form "commit=${commit}" \
--form "tests=@test-results/junit.xml" \

View File

@ -1,16 +1,22 @@
name: cargo test
on:
push:
branches:
- main
pull_request:
workflow_dispatch:
schedule:
- cron: 0 * * * * # hourly
permissions:
contents: read
pull-requests: write
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
name: cargo test
jobs:
build-test-artifacts:
name: Build test artifacts
@ -193,6 +199,7 @@ jobs:
TAB_API_KEY: ${{ secrets.TAB_API_KEY }}
CI_COMMIT_SHA: ${{ github.event.pull_request.head.sha }}
CI_PR_NUMBER: ${{ github.event.pull_request.number }}
CI_SUITE: e2e:kcl
run-internal-kcl-samples:
name: cargo test (internal-kcl-samples)
runs-on:

View File

@ -1,4 +1,5 @@
name: E2E Tests
on:
push:
branches:
@ -143,7 +144,7 @@ jobs:
- name: Install browsers
run: npm run playwright install --with-deps
- name: Capture snapshots
- name: Test snapshots
uses: nick-fields/retry@v3.0.2
with:
shell: bash
@ -156,6 +157,19 @@ jobs:
TAB_API_KEY: ${{ secrets.TAB_API_KEY }}
CI_COMMIT_SHA: ${{ github.event.pull_request.head.sha }}
CI_PR_NUMBER: ${{ github.event.pull_request.number }}
CI_SUITE: e2e:snapshots
TARGET: web
- name: Update snapshots
if: always()
run: npm run test:snapshots -- --last-failed --update-snapshots
env:
token: ${{ secrets.KITTYCAD_API_TOKEN_DEV }}
TAB_API_URL: ${{ secrets.TAB_API_URL }}
TAB_API_KEY: ${{ secrets.TAB_API_KEY }}
CI_COMMIT_SHA: ${{ github.event.pull_request.head.sha }}
CI_PR_NUMBER: ${{ github.event.pull_request.number }}
CI_SUITE: e2e:snapshots
TARGET: web
- uses: actions/upload-artifact@v4
@ -173,7 +187,7 @@ jobs:
id: git-check
run: |
git add e2e/playwright/snapshot-tests.spec.ts-snapshots e2e/playwright/snapshots
if git status | grep -q "Changes to be committed"
if git status | grep --quiet "Changes to be committed"
then echo "modified=true" >> $GITHUB_OUTPUT
else echo "modified=false" >> $GITHUB_OUTPUT
fi
@ -306,6 +320,7 @@ jobs:
TAB_API_KEY: ${{ secrets.TAB_API_KEY }}
CI_COMMIT_SHA: ${{ github.event.pull_request.head.sha }}
CI_PR_NUMBER: ${{ github.event.pull_request.number }}
CI_SUITE: e2e:desktop
TARGET: desktop
- uses: actions/upload-artifact@v4

View File

@ -122,12 +122,11 @@ https://github.com/KittyCAD/modeling-app/issues/new
#### 2. Push a new tag
Create a new tag and push it to the repo. The `semantic-release.sh` script will automatically bump the minor part, which we use the most. For instance going from `v0.27.0` to `v0.28.0`.
Decide on a `v`-prefixed semver `VERSION` (eg. `v1.2.3`) with the team and tag the repo, eg. on latest main:
```
VERSION=$(./scripts/semantic-release.sh)
git tag $VERSION
git push origin --tags
git push origin $VERSION
```
This will trigger the `build-apps` workflow, set the version, build & sign the apps, and generate release files.

View File

@ -4,7 +4,7 @@ Compared to other CAD software, getting Zoo Design Studio up and running is quic
## Windows
1. Download the [Zoo Design Studio installer](https://zoo.dev/modeling-app/download) for Windows and for your processor type.
1. Download the [Zoo Design Studio installer](https://zoo.dev/design-studio/download) for Windows and for your processor type.
2. Once downloaded, run the installer `Zoo Design Studio-{version}-{arch}-win.exe` which should take a few seconds.
@ -12,16 +12,16 @@ Compared to other CAD software, getting Zoo Design Studio up and running is quic
## macOS
1. Download the [Zoo Design Studio installer](https://zoo.dev/modeling-app/download) for macOS and for your processor type.
1. Download the [Zoo Design Studio installer](https://zoo.dev/design-studio/download) for macOS and for your processor type.
2. Once downloaded, open the disk image `Zoo Design Studio-{version}-{arch}-mac.dmg` and drag the applications to your `Applications` directory.
3. You can then open your `Applications` directory and double-click on `Zoo Design Studio` to open.
## Linux
## Linux
1. Download the [Zoo Design Studio installer](https://zoo.dev/modeling-app/download) for Linux and for your processor type.
1. Download the [Zoo Design Studio installer](https://zoo.dev/design-studio/download) for Linux and for your processor type.
2. Install the dependencies needed to run the [AppImage format](https://appimage.org/).
- On Ubuntu, install the FUSE library with these commands in a terminal.
@ -29,7 +29,7 @@ Compared to other CAD software, getting Zoo Design Studio up and running is quic
sudo apt update
sudo apt install libfuse2
```
- Optionally, follow [these steps](https://github.com/probonopd/go-appimage/blob/master/src/appimaged/README.md#initial-setup) to install `appimaged`. It is a daemon that makes interacting with AppImage files more seamless.
- Optionally, follow [these steps](https://github.com/probonopd/go-appimage/blob/master/src/appimaged/README.md#initial-setup) to install `appimaged`. It is a daemon that makes interacting with AppImage files more seamless.
- Once installed, copy the downloaded `Zoo Design Studio-{version}-{arch}-linux.AppImage` to the directory of your choice, for instance `~/Applications`.
- `appimaged` should automatically find it and make it executable. If not, run:

View File

@ -2,7 +2,7 @@
# Zoo Design Studio
[zoo.dev/modeling-app](https://zoo.dev/modeling-app)
[zoo.dev/design-studio](https://zoo.dev/design-studio)
A CAD application from the future, brought to you by the [Zoo team](https://zoo.dev).
@ -40,12 +40,8 @@ The 3D view in Design Studio is just a video stream from our hosted geometry eng
## Get Started
We recommend downloading the latest application binary from our [releases](https://github.com/KittyCAD/modeling-app/releases) page. If you don't see your platform or architecture supported there, please file an issue.
We recommend downloading the latest application binary from our [website](https://zoo.dev/design-studio/download). If you don't see your platform or architecture supported there, please file an issue. See the [installation guide](INSTALL.md) for additional instructions.
## Developing
Finally, if you'd like to run a development build or contribute to the project, please visit our [contributor guide](CONTRIBUTING.md) to get started.
## KCL
To contribute to the KittyCAD Language, see the [README](https://github.com/KittyCAD/modeling-app/tree/main/rust/kcl-lib) for KCL.
Finally, if you'd like to run a development build or contribute to the project, please visit our [contributor guide](CONTRIBUTING.md) to get started. To contribute to the KittyCAD Language, see the dedicated [readme](rust/kcl-lib/README.md) for KCL.

View File

@ -27,9 +27,6 @@ import increment from "util.kcl"
answer = increment(41)
```
Imported files _must_ be in the same project so that units are uniform across
modules. This means that it must be in the same directory.
Import statements must be at the top-level of a file. It is not allowed to have
an `import` statement inside a function or in the body of an ifelse.
@ -58,6 +55,9 @@ Imported symbols can be renamed for convenience or to avoid name collisions.
import increment as inc, decrement as dec from "util.kcl"
```
You can import files from the current directory or from subdirectories, but if importing from a
subdirectory you can only import `main.kcl`.
---
## Functions vs `clone`
@ -229,6 +229,19 @@ The final statement is what's important because it's the return value of the
entire module. The module is expected to return a single object that can be used
as a variable by the file that imports it.
The name of the file or subdirectory is used as the name of the variable within the importing program.
If you want to use a different name, you can do so by using the `as` keyword:
```kcl,norun
import "cube.kcl" // Introduces a new variable called `cube`.
import "cube.kcl" as block // Introduces a new variable called `block`.
import "cube/main.kcl" // Introduces a new variable called `cube`.
import "cube/main.kcl" as block // Introduces a new variable called `block`.
```
If the filename includes hyphens (`-`) or starts with an underscore (`_`), then you must specify a
variable name.
---
## Multiple instances of the same import

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -11,7 +11,8 @@ layout: manual
circle(
@sketch_or_surface: Sketch | Plane | Face,
center: Point2d,
radius: number(Length),
radius?: number(Length),
diameter?: number(Length),
tag?: tag,
): Sketch
```
@ -25,7 +26,8 @@ the provided (x, y) origin point.
|----------|------|-------------|----------|
| `sketch_or_surface` | [`Sketch`](/docs/kcl-std/types/std-types-Sketch) or [`Plane`](/docs/kcl-std/types/std-types-Plane) or [`Face`](/docs/kcl-std/types/std-types-Face) | Sketch to extend, or plane or surface to sketch on. | Yes |
| `center` | [`Point2d`](/docs/kcl-std/types/std-types-Point2d) | The center of the circle. | Yes |
| `radius` | [`number(Length)`](/docs/kcl-std/types/std-types-number) | The radius of the circle. | Yes |
| `radius` | [`number(Length)`](/docs/kcl-std/types/std-types-number) | The radius of the circle. Incompatible with `diameter`. | No |
| `diameter` | [`number(Length)`](/docs/kcl-std/types/std-types-number) | The diameter of the circle. Incompatible with `radius`. | No |
| [`tag`](/docs/kcl-std/types/std-types-tag) | [`tag`](/docs/kcl-std/types/std-types-tag) | Create a new tag which refers to this circle. | No |
### Returns
@ -51,7 +53,7 @@ exampleSketch = startSketchOn(XZ)
|> line(end = [0, 30])
|> line(end = [-30, 0])
|> close()
|> subtract2d(tool = circle(center = [0, 15], radius = 5))
|> subtract2d(tool = circle(center = [0, 15], diameter = 10))
example = extrude(exampleSketch, length = 5)
```

View File

@ -16,6 +16,8 @@ layout: manual
* [`helix`](/docs/kcl-std/functions/std-helix)
* [`offsetPlane`](/docs/kcl-std/functions/std-offsetPlane)
* [`patternLinear2d`](/docs/kcl-std/patternLinear2d)
* [**std::appearance**](/docs/kcl-std/modules/std-appearance)
* [`appearance::hexString`](/docs/kcl-std/functions/std-appearance-hexString)
* [**std::array**](/docs/kcl-std/modules/std-array)
* [`map`](/docs/kcl-std/functions/std-array-map)
* [`pop`](/docs/kcl-std/functions/std-array-pop)

View File

@ -0,0 +1,16 @@
---
title: "appearance"
subtitle: "Module in std"
excerpt: ""
layout: manual
---
## Functions and constants
* [`appearance::hexString`](/docs/kcl-std/functions/std-appearance-hexString)

View File

@ -15,6 +15,7 @@ You might also want the [KCL language reference](/docs/kcl-lang) or the [KCL gui
## Modules
* [`appearance::appearance`](/docs/kcl-std/modules/std-appearance)
* [`array`](/docs/kcl-std/modules/std-array)
* [`math`](/docs/kcl-std/modules/std-math)
* [`sketch`](/docs/kcl-std/modules/std-sketch)

View File

@ -26,7 +26,7 @@ patternLinear3d(
| `solids` | [`[Solid]`](/docs/kcl-std/types/std-types-Solid) | The solid(s) to duplicate | Yes |
| `instances` | [`number`](/docs/kcl-std/types/std-types-number) | The number of total instances. Must be greater than or equal to 1. This includes the original entity. For example, if instances is 2, there will be two copies -- the original, and one new copy. If instances is 1, this has no effect. | Yes |
| `distance` | [`number`](/docs/kcl-std/types/std-types-number) | Distance between each repetition. Also known as 'spacing'. | Yes |
| `axis` | [`Point3d`](/docs/kcl-std/types/std-types-Point3d) | The axis of the pattern. A 2D vector. | Yes |
| `axis` | [`Point3d`](/docs/kcl-std/types/std-types-Point3d) | The axis of the pattern. A 3D vector. | Yes |
| `useOriginal` | [`bool`](/docs/kcl-std/types/std-types-bool) | If the target was sketched on an extrusion, setting this will use the original sketch as the target, not the entire joined solid. Defaults to false. | No |
### Returns

File diff suppressed because it is too large Load Diff

View File

@ -78,11 +78,10 @@ extrude001 = extrude(sketch001, length = 5)`
// Delete a character to break the KCL
await editor.openPane()
await editor.scrollToText('bracketLeg1Sketch, length = thickness)')
await page
.getByText('extrude(bracketLeg1Sketch, length = thickness)')
.click()
await page.keyboard.press('Backspace')
await editor.scrollToText('extrude(%, length = width)')
await page.getByText('extrude(%, length = width)').click()
await page.keyboard.press(')')
// Ensure that a badge appears on the button
await expect(codePaneButtonHolder).toContainText('notification')
@ -99,16 +98,11 @@ extrude001 = extrude(sketch001, length = 5)`
await page.waitForTimeout(500)
// Ensure that a badge appears on the button
await expect(codePaneButtonHolder).toContainText('notification')
// Ensure we have no errors in the gutter.
await expect(page.locator('.cm-lint-marker-error')).not.toBeVisible()
// Open the code pane
await editor.openPane()
// Go to our problematic code again (missing closing paren!)
await editor.scrollToText('extrude(bracketLeg1Sketch, length = thickness')
// Go to our problematic code again
await editor.scrollToText('extrude(%, length = w')
// Ensure that a badge appears on the button
await expect(codePaneButtonHolder).toContainText('notification')

View File

@ -45,15 +45,16 @@ test.describe('Command bar tests', () => {
await cmdBar.expectState({
stage: 'arguments',
commandName: 'Extrude',
currentArgKey: 'length',
currentArgValue: '5',
currentArgKey: 'sketches',
currentArgValue: '',
headerArguments: {
Profiles: '1 profile',
Profiles: '',
Length: '',
},
highlightedHeaderArg: 'length',
highlightedHeaderArg: 'Profiles',
})
await cmdBar.progressCmdBar()
await cmdBar.progressCmdBar()
await cmdBar.expectState({
stage: 'review',
commandName: 'Extrude',
@ -684,4 +685,33 @@ c = 3 + a`
highlightedHeaderArg: 'value',
})
})
test('Text-to-CAD command can be closed with escape while in prompt', async ({
page,
homePage,
cmdBar,
}) => {
await homePage.expectState({
projectCards: [],
sortBy: 'last-modified-desc',
})
await homePage.textToCadBtn.click()
await cmdBar.expectState({
stage: 'arguments',
commandName: 'Text-to-CAD Create',
currentArgKey: 'prompt',
currentArgValue: '',
headerArguments: {
Method: 'New project',
NewProjectName: 'untitled',
Prompt: '',
},
highlightedHeaderArg: 'prompt',
})
await page.keyboard.press('Escape')
await cmdBar.toBeClosed()
await cmdBar.expectState({
stage: 'commandBarClosed',
})
})
})

View File

@ -1001,7 +1001,7 @@ a1 = startSketchOn(offsetPlane(XY, offset = 10))
await expect(page.locator('.cm-content')).toHaveText(
`@settings(defaultLengthUnit = in)
sketch001 = startSketchOn(XZ)
|> startProfile(%, at = [3.14, 12])
|> startProfile(%, at = [0, 12])
|> xLine(%, length = 5) // lin`.replaceAll('\n', '')
)
@ -1076,7 +1076,7 @@ sketch001 = startSketchOn(XZ)
await expect(page.locator('.cm-content')).toHaveText(
`@settings(defaultLengthUnit = in)
sketch001 = startSketchOn(XZ)
|> startProfile(%, at = [3.14, 12])
|> startProfile(%, at = [0, 12])
|> xLine(%, length = 5) // lin`.replaceAll('\n', '')
)
})
@ -1134,6 +1134,7 @@ sketch001 = startSketchOn(XZ)
// Wait for the selection to register (TODO: we need a definitive way to wait for this)
await page.waitForTimeout(200)
await toolbar.extrudeButton.click()
await cmdBar.progressCmdBar()
await cmdBar.expectState({
stage: 'arguments',
currentArgKey: 'length',
@ -1355,9 +1356,7 @@ sketch001 = startSketchOn(XZ)
const u = await getUtils(page)
const projectLink = page.getByRole('link', { name: 'cube' })
const gizmo = page.locator('[aria-label*=gizmo]')
const resetCameraButton = page.getByRole('button', {
name: 'Reset view',
})
const resetCameraButton = page.getByRole('button', { name: 'Reset view' })
const locationToHaveColor = async (
position: { x: number; y: number },
color: [number, number, number]
@ -1591,4 +1590,38 @@ sketch001 = startSketchOn(XZ)
await expect(page.getByTestId('center-rectangle')).toBeVisible()
})
})
test('syntax errors still show when reopening KCL pane', async ({
page,
homePage,
scene,
cmdBar,
}) => {
const u = await getUtils(page)
await page.setBodyDimensions({ width: 1200, height: 500 })
await homePage.goToModelingScene()
// Wait for connection, this is especially important for this test, because safeParse is invoked when
// connection is established which would interfere with the test if it happened during later steps.
await scene.connectionEstablished()
await scene.settled(cmdBar)
// Code with no error
await u.codeLocator.fill(`x = 7`)
await page.waitForTimeout(200) // allow some time for the error to show potentially
await expect(page.locator('.cm-lint-marker-error')).toHaveCount(0)
// Code with error
await u.codeLocator.fill(`x 7`)
await expect(page.locator('.cm-lint-marker-error')).toHaveCount(1)
// Close and reopen KCL code panel
await u.closeKclCodePanel()
await expect(page.locator('.cm-lint-marker-error')).toHaveCount(0) // error disappears on close
await u.openKclCodePanel()
// Verify error is still visible
await expect(page.locator('.cm-lint-marker-error')).toHaveCount(1)
})
})

View File

@ -238,6 +238,26 @@ test.describe('when using the file tree to', () => {
}
)
test(
`create new folders and that doesn't trigger a navigation`,
{ tag: ['@electron', '@macos', '@windows'] },
async ({ page, homePage, scene, toolbar, cmdBar }) => {
await homePage.goToModelingScene()
await scene.settled(cmdBar)
await toolbar.openPane('files')
const { createNewFolder } = await getUtils(page, test)
await createNewFolder('folder')
await createNewFolder('folder.kcl')
await test.step(`Postcondition: folders are created and we didn't navigate`, async () => {
await toolbar.expectFileTreeState(['folder', 'folder.kcl', 'main.kcl'])
await expect(toolbar.fileName).toHaveText('main.kcl')
})
}
)
test(
'deleting all files recreates a default main.kcl with no code',
{ tag: '@electron' },

View File

@ -105,14 +105,19 @@ export class CmdBarFixture {
expectState = async (expected: CmdBarSerialised) => {
return expect.poll(() => this._serialiseCmdBar()).toEqual(expected)
}
/** The method will use buttons OR press enter randomly to progress the cmdbar,
* this could have unexpected results depending on what's focused
*
* TODO: This method assumes the user has a valid input to the current stage,
/**
* This method is used to progress the command bar to the next step, defaulting to clicking the next button.
* Optionally, with the `shouldUseKeyboard` parameter, it will hit `Enter` to progress.
* * TODO: This method assumes the user has a valid input to the current stage,
* and assumes we are past the `pickCommand` step.
*/
progressCmdBar = async (shouldFuzzProgressMethod = true) => {
progressCmdBar = async (shouldUseKeyboard = false) => {
await this.page.waitForTimeout(2000)
if (shouldUseKeyboard) {
await this.page.keyboard.press('Enter')
return
}
const arrowButton = this.page.getByRole('button', {
name: 'arrow right Continue',
})
@ -308,6 +313,11 @@ export class CmdBarFixture {
await expect(this.cmdBarElement).toBeVisible({ timeout: 10_000 })
}
async toBeClosed() {
// Check that the command bar is closed
await expect(this.cmdBarElement).not.toBeVisible({ timeout: 10_000 })
}
async expectArgValue(value: string) {
// Check the placeholder project name exists
const actualArgument = await this.cmdBarElement

View File

@ -26,6 +26,7 @@ export class HomePageFixture {
sortByNameBtn!: Locator
appHeader!: Locator
tutorialBtn!: Locator
textToCadBtn!: Locator
constructor(page: Page) {
this.page = page
@ -47,6 +48,7 @@ export class HomePageFixture {
this.sortByNameBtn = this.page.getByTestId('home-sort-by-name')
this.appHeader = this.page.getByTestId('app-header')
this.tutorialBtn = this.page.getByTestId('home-tutorial-button')
this.textToCadBtn = this.page.getByTestId('home-text-to-cad')
}
private _serialiseSortBy = async (): Promise<

View File

@ -61,6 +61,7 @@ class MyAPIReporter implements Reporter {
const payload = {
// Required information
project: 'https://github.com/KittyCAD/modeling-app',
suite: process.env.CI_SUITE || 'e2e',
branch: process.env.GITHUB_HEAD_REF || process.env.GITHUB_REF_NAME || '',
commit: process.env.CI_COMMIT_SHA || process.env.GITHUB_SHA || '',
test: test.titlePath().slice(2).join(' '),

View File

@ -70,22 +70,28 @@ test.describe('Point-and-click assemblies tests', () => {
await test.step('Setup parts and expect empty assembly scene', async () => {
const projectName = 'assembly'
await context.folderSetupFn(async (dir) => {
const bracketDir = path.join(dir, projectName)
await fsp.mkdir(bracketDir, { recursive: true })
const projDir = path.join(dir, projectName)
const nestedProjDir = path.join(dir, projectName, 'nested', 'twice')
await fsp.mkdir(projDir, { recursive: true })
await fsp.mkdir(nestedProjDir, { recursive: true })
await Promise.all([
fsp.copyFile(
executorInputPath('cylinder.kcl'),
path.join(bracketDir, 'cylinder.kcl')
path.join(projDir, 'cylinder.kcl')
),
fsp.copyFile(
executorInputPath('cylinder.kcl'),
path.join(nestedProjDir, 'main.kcl')
),
fsp.copyFile(
executorInputPath('e2e-can-sketch-on-chamfer.kcl'),
path.join(bracketDir, 'bracket.kcl')
path.join(projDir, 'bracket.kcl')
),
fsp.copyFile(
testsInputPath('cube.step'),
path.join(bracketDir, 'cube.step')
path.join(projDir, 'cube.step')
),
fsp.writeFile(path.join(bracketDir, 'main.kcl'), ''),
fsp.writeFile(path.join(projDir, 'main.kcl'), ''),
])
})
await page.setBodyDimensions({ width: 1000, height: 500 })
@ -167,6 +173,25 @@ test.describe('Point-and-click assemblies tests', () => {
await expect(
page.getByText('This file is already imported')
).toBeVisible()
await cmdBar.closeCmdBar()
})
await test.step('Insert a nested kcl part', async () => {
await insertPartIntoAssembly(
'nested/twice/main.kcl',
'main',
toolbar,
cmdBar,
page
)
await toolbar.openPane('code')
await page.waitForTimeout(10000)
await editor.expectEditor.toContain(
`
import "nested/twice/main.kcl" as main
`,
{ shouldNormalise: true }
)
})
}
)

View File

@ -74,6 +74,15 @@ test.describe('Point-and-click tests', () => {
await test.step('do extrude flow and check extrude code is added to editor', async () => {
await toolbar.extrudeButton.click()
await cmdBar.expectState({
stage: 'arguments',
currentArgKey: 'sketches',
currentArgValue: '',
headerArguments: { Profiles: '', Length: '' },
highlightedHeaderArg: 'Profiles',
commandName: 'Extrude',
})
await cmdBar.progressCmdBar()
await cmdBar.expectState({
stage: 'arguments',
currentArgKey: 'length',
@ -1645,6 +1654,15 @@ sketch002 = startSketchOn(plane001)
await test.step(`Go through the command bar flow with preselected sketches`, async () => {
await toolbar.loftButton.click()
await cmdBar.expectState({
stage: 'arguments',
currentArgKey: 'sketches',
currentArgValue: '',
headerArguments: { Profiles: '' },
highlightedHeaderArg: 'Profiles',
commandName: 'Loft',
})
await cmdBar.progressCmdBar()
await cmdBar.expectState({
stage: 'review',
headerArguments: { Profiles: '2 profiles' },
@ -1855,7 +1873,11 @@ sketch002 = startSketchOn(XZ)
},
stage: 'review',
})
await cmdBar.progressCmdBar()
// Confirm we can submit from the review step with just `Enter`
await cmdBar.progressCmdBar(true)
await cmdBar.expectState({
stage: 'commandBarClosed',
})
})
await test.step(`Confirm code is added to the editor, scene has changed`, async () => {
@ -1995,7 +2017,7 @@ profile001 = ${circleCode}`
},
stage: 'review',
})
await cmdBar.progressCmdBar()
await cmdBar.progressCmdBar(true)
await editor.expectEditor.toContain(sweepDeclaration)
})
@ -2088,6 +2110,18 @@ extrude001 = extrude(sketch001, length = -12)
await test.step(`Apply fillet to the preselected edge`, async () => {
await page.waitForTimeout(100)
await toolbar.filletButton.click()
await cmdBar.expectState({
commandName: 'Fillet',
highlightedHeaderArg: 'selection',
currentArgKey: 'selection',
currentArgValue: '',
headerArguments: {
Selection: '',
Radius: '',
},
stage: 'arguments',
})
await cmdBar.progressCmdBar()
await cmdBar.expectState({
commandName: 'Fillet',
highlightedHeaderArg: 'radius',
@ -2617,6 +2651,18 @@ extrude001 = extrude(profile001, length = 5)
await test.step(`Apply fillet`, async () => {
await page.waitForTimeout(100)
await toolbar.filletButton.click()
await cmdBar.expectState({
commandName: 'Fillet',
highlightedHeaderArg: 'selection',
currentArgKey: 'selection',
currentArgValue: '',
headerArguments: {
Selection: '',
Radius: '',
},
stage: 'arguments',
})
await cmdBar.progressCmdBar()
await cmdBar.expectState({
commandName: 'Fillet',
highlightedHeaderArg: 'radius',
@ -2722,6 +2768,19 @@ extrude001 = extrude(sketch001, length = -12)
await test.step(`Apply chamfer to the preselected edge`, async () => {
await page.waitForTimeout(100)
await toolbar.chamferButton.click()
await cmdBar.expectState({
commandName: 'Chamfer',
highlightedHeaderArg: 'selection',
currentArgKey: 'selection',
currentArgValue: '',
headerArguments: {
Selection: '',
Length: '',
},
stage: 'arguments',
})
await cmdBar.progressCmdBar()
await page.waitForTimeout(1000)
await cmdBar.expectState({
commandName: 'Chamfer',
highlightedHeaderArg: 'length',
@ -3205,6 +3264,8 @@ extrude001 = extrude(sketch001, length = 30)
await test.step(`Go through the command bar flow with a preselected face (cap)`, async () => {
await toolbar.shellButton.click()
await cmdBar.progressCmdBar()
await page.waitForTimeout(500)
await cmdBar.progressCmdBar()
await cmdBar.expectState({
stage: 'review',
headerArguments: {
@ -3638,13 +3699,12 @@ tag=$rectangleSegmentC002,
// revolve
await editor.scrollToText(codeToSelection)
await page.getByText(codeToSelection).click()
// Wait for the selection to register (TODO: we need a definitive way to wait for this)
await page.waitForTimeout(200)
await toolbar.revolveButton.click()
await cmdBar.progressCmdBar()
await cmdBar.progressCmdBar()
await cmdBar.progressCmdBar()
await cmdBar.progressCmdBar()
await cmdBar.progressCmdBar()
const newCodeToFind = `revolve001 = revolve(sketch002, angle = 360, axis = X)`
expect(editor.expectEditor.toContain(newCodeToFind)).toBeTruthy()
@ -4573,6 +4633,18 @@ path001 = startProfile(sketch001, at = [0, 0])
await test.step('Go through command bar flow', async () => {
await toolbar.extrudeButton.click()
await cmdBar.expectState({
stage: 'arguments',
currentArgKey: 'sketches',
currentArgValue: '',
headerArguments: {
Profiles: '',
Length: '',
},
highlightedHeaderArg: 'Profiles',
commandName: 'Extrude',
})
await cmdBar.progressCmdBar()
await cmdBar.expectState({
stage: 'arguments',
currentArgKey: 'length',
@ -4655,6 +4727,19 @@ path001 = startProfile(sketch001, at = [0, 0])
await test.step('Go through command bar flow', async () => {
await toolbar.sweepButton.click()
await cmdBar.expectState({
stage: 'arguments',
currentArgKey: 'sketches',
currentArgValue: '',
headerArguments: {
Profiles: '',
Path: '',
Sectional: '',
},
highlightedHeaderArg: 'Profiles',
commandName: 'Sweep',
})
await cmdBar.progressCmdBar()
await cmdBar.expectState({
stage: 'arguments',
currentArgKey: 'path',
@ -4739,6 +4824,19 @@ path001 = startProfile(sketch001, at = [0, 0])
await test.step('Go through command bar flow', async () => {
await toolbar.closePane('code')
await toolbar.revolveButton.click()
await cmdBar.expectState({
stage: 'arguments',
currentArgKey: 'sketches',
currentArgValue: '',
headerArguments: {
Profiles: '',
AxisOrEdge: '',
Angle: '',
},
highlightedHeaderArg: 'Profiles',
commandName: 'Revolve',
})
await cmdBar.progressCmdBar()
await cmdBar.expectState({
stage: 'arguments',
currentArgKey: 'axisOrEdge',

View File

@ -11,6 +11,7 @@ import {
getPlaywrightDownloadDir,
getUtils,
isOutOfViewInScrollContainer,
runningOnWindows,
} from '@e2e/playwright/test-utils'
import { expect, test } from '@e2e/playwright/zoo-test'
@ -1979,7 +1980,6 @@ test(
}
)
// Flaky
test(
'Original project name persist after onboarding',
{ tag: '@electron' },
@ -2064,3 +2064,55 @@ test(
})
}
)
test(
'import from nested directory',
{ tag: ['@electron', '@windows', '@macos'] },
async ({ scene, cmdBar, context, page }) => {
await context.folderSetupFn(async (dir) => {
const bracketDir = path.join(dir, 'bracket')
await fsp.mkdir(bracketDir, { recursive: true })
const nestedDir = path.join(bracketDir, 'nested')
await fsp.mkdir(nestedDir, { recursive: true })
await fsp.copyFile(
executorInputPath('cylinder-inches.kcl'),
path.join(nestedDir, 'main.kcl')
)
await fsp.writeFile(
path.join(bracketDir, 'main.kcl'),
runningOnWindows()
? `import 'nested\\main.kcl' as thing\n\nthing`
: `import 'nested/main.kcl' as thing\n\nthing`
)
})
await page.setBodyDimensions({ width: 1200, height: 500 })
const u = await getUtils(page)
const pointOnModel = { x: 630, y: 280 }
await test.step('Opening the bracket project should load the stream', async () => {
// expect to see the text bracket
await expect(page.getByText('bracket')).toBeVisible()
await page.getByText('bracket').click()
await scene.settled(cmdBar)
await expect(
page.getByRole('button', { name: 'Start Sketch' })
).toBeEnabled({
timeout: 20_000,
})
// gray at this pixel means the stream has loaded in the most
// user way we can verify it (pixel color)
await expect
.poll(() => u.getGreatestPixDiff(pointOnModel, [125, 125, 125]), {
timeout: 10_000,
})
.toBeLessThan(15)
})
}
)

View File

@ -1016,6 +1016,7 @@ profile001 = startProfile(sketch001, at = [${roundOff(scale * 69.6)}, ${roundOff
// sketch selection should already have been made.
// otherwise the cmdbar would be waiting for a selection.
await cmdBar.progressCmdBar()
await cmdBar.expectState({
stage: 'arguments',
currentArgKey: 'length',

Binary file not shown.

Before

Width:  |  Height:  |  Size: 133 KiB

After

Width:  |  Height:  |  Size: 133 KiB

View File

@ -557,6 +557,14 @@ export async function getUtils(page: Page, test_?: typeof test) {
})
},
createNewFolder: async (name: string) => {
return test?.step(`Create a folder named ${name}`, async () => {
await page.getByTestId('create-folder-button').click()
await page.getByTestId('tree-input-field').fill(name)
await page.keyboard.press('Enter')
})
},
cloneFile: async (name: string) => {
return test?.step(`Cloning file '${name}'`, async () => {
await page

View File

@ -103,6 +103,8 @@ test.describe('Testing loading external models', () => {
file: 'ball-bearing' + FILE_EXT,
title: 'Ball Bearing',
file1: 'ball-bearing-1' + FILE_EXT,
folderName: 'ball-bearing',
folderName1: 'ball-bearing-1',
}
const projectCard = page.getByRole('link', { name: 'bracket' })
const overwriteWarning = page.getByText(
@ -154,8 +156,10 @@ test.describe('Testing loading external models', () => {
await test.step(`Ensure we made and opened a new file`, async () => {
await editor.expectEditor.toContain('// ' + sampleOne.title)
await expect(newlyCreatedFile(sampleOne.file)).toBeVisible()
await expect(projectMenuButton).toContainText(sampleOne.file)
await expect(
page.getByTestId('file-tree-item').getByText(sampleOne.folderName)
).toBeVisible()
await expect(projectMenuButton).toContainText('main.kcl')
})
await test.step(`Load a KCL sample with the command palette`, async () => {
@ -169,8 +173,10 @@ test.describe('Testing loading external models', () => {
await test.step(`Ensure we made and opened a new file with a unique name`, async () => {
await editor.expectEditor.toContain('// ' + sampleOne.title)
await expect(newlyCreatedFile(sampleOne.file1)).toBeVisible()
await expect(projectMenuButton).toContainText(sampleOne.file1)
await expect(
page.getByTestId('file-tree-item').getByText(sampleOne.folderName1)
).toBeVisible()
await expect(projectMenuButton).toContainText('main.kcl')
})
}
)

View File

@ -1,5 +1,3 @@
import fs from 'fs'
import { join } from 'path'
import type { Page } from '@playwright/test'
import { createProject, getUtils } from '@e2e/playwright/test-utils'
@ -403,106 +401,6 @@ test.describe('Text-to-CAD tests', () => {
await expect(page.getByText(promptWithNewline)).toBeVisible()
})
// This will be fine once greg makes prompt at top of file deterministic
test('can do many at once and get many prompts back, and interact with many', async ({
page,
homePage,
cmdBar,
}) => {
// Let this test run longer since we've seen it timeout.
test.setTimeout(180_000)
const u = await getUtils(page)
await page.setBodyDimensions({ width: 1000, height: 500 })
await homePage.goToModelingScene()
await u.waitForPageLoad()
await sendPromptFromCommandBarAndSetExistingProject(
page,
'a 2x4 lego',
cmdBar
)
await sendPromptFromCommandBarAndSetExistingProject(
page,
'a 2x8 lego',
cmdBar
)
await sendPromptFromCommandBarAndSetExistingProject(
page,
'a 2x10 lego',
cmdBar
)
// Find the toast.
// Look out for the toast message
const submittingToastMessage = page.getByText(
`Submitting to Text-to-CAD API...`
)
await expect(submittingToastMessage.first()).toBeVisible()
const generatingToastMessage = page.getByText(
`Generating parametric model...`
)
await expect(generatingToastMessage.first()).toBeVisible({
timeout: 10_000,
})
const successToastMessage = page.getByText(`Text-to-CAD successful`)
// We should have three success toasts.
await expect(successToastMessage).toHaveCount(3, { timeout: 25_000 })
await expect(page.getByText(`a 2x4 lego`)).toBeVisible()
await expect(page.getByText(`a 2x8 lego`)).toBeVisible()
await expect(page.getByText(`a 2x10 lego`)).toBeVisible()
// Ensure if you reject one, the others stay.
const rejectButton = page.getByRole('button', { name: 'Reject' })
await expect(rejectButton.first()).toBeVisible()
// Click the reject button on the first toast.
await rejectButton.first().click()
// The first toast should disappear, but not the others.
await expect(page.getByText(`a 2x10 lego`)).not.toBeVisible()
await expect(page.getByText(`a 2x8 lego`)).toBeVisible()
await expect(page.getByText(`a 2x4 lego`)).toBeVisible()
// Ensure you can copy the code for one of the models remaining.
const copyToClipboardButton = page.getByRole('button', {
name: 'Accept',
})
await expect(copyToClipboardButton.first()).toBeVisible()
// Click the button.
await copyToClipboardButton.first().click()
// Do NOT do AI tests like this: "Expect the code to be pasted."
// Reason: AI tests are NONDETERMINISTIC. Thus we need to be as most
// general as we can for the assertion.
// We can use Kolmogorov complexity as a measurement of the
// "probably most minimal version of this program" to have a lower
// bound to work with. It is completely by feel because there are
// no proofs that any program is its smallest self.
const code2x8 = await page.locator('.cm-content').innerText()
await expect(code2x8.length).toBeGreaterThan(249)
// Ensure the final toast remains.
await expect(page.getByText(`a 2x10 lego`)).not.toBeVisible()
await expect(page.getByText(`Prompt: "a 2x8 lego`)).not.toBeVisible()
await expect(page.getByText(`a 2x4 lego`)).toBeVisible()
// Ensure you can copy the code for the final model.
await expect(copyToClipboardButton).toBeVisible()
// Click the button.
await copyToClipboardButton.click()
// Expect the code to be pasted.
const code2x4 = await page.locator('.cm-content').innerText()
await expect(code2x4.length).toBeGreaterThan(249)
})
test('can do many at once with errors, clicking dismiss error does not dismiss all', async ({
page,
homePage,
@ -675,82 +573,6 @@ async function sendPromptFromCommandBarAndSetExistingProject(
})
}
test(
'Text-to-CAD functionality',
{ tag: '@electron' },
async ({ context, page, cmdBar }, testInfo) => {
const projectName = 'project-000'
const prompt = 'lego 2x4'
const textToCadFileName = 'lego-2x4.kcl'
const { dir } = await context.folderSetupFn(async () => {})
const fileExists = () =>
fs.existsSync(join(dir, projectName, textToCadFileName))
const { openFilePanel, openKclCodePanel, waitForPageLoad } = await getUtils(
page,
test
)
await page.setBodyDimensions({ width: 1200, height: 500 })
// Locators
const projectMenuButton = page
.getByTestId('project-sidebar-toggle')
.filter({ hasText: projectName })
const textToCadFileButton = page.getByRole('listitem').filter({
has: page.getByRole('button', { name: textToCadFileName }),
})
const textToCadComment = page.getByText(
`// Generated by Text-to-CAD: ${prompt}`
)
// Create and navigate to the project
await createProject({ name: 'project-000', page })
// Wait for Start Sketch otherwise you will not have access Text-to-CAD command
await waitForPageLoad()
await openFilePanel()
await openKclCodePanel()
await test.step(`Test file creation`, async () => {
await sendPromptFromCommandBarAndSetExistingProject(
page,
prompt,
cmdBar,
projectName
)
// File is considered created if it shows up in the Project Files pane
await expect(textToCadFileButton).toBeVisible({ timeout: 20_000 })
expect(fileExists()).toBeTruthy()
})
await test.step(`Test file navigation`, async () => {
await expect(projectMenuButton).toContainText('main.kcl')
await textToCadFileButton.click()
// File can be navigated and loaded assuming a specific KCL comment is loaded into the KCL code pane
await expect(textToCadComment).toBeVisible({ timeout: 20_000 })
await expect(projectMenuButton).toContainText(textToCadFileName)
})
await test.step(`Test file deletion on rejection`, async () => {
const rejectButton = page.getByRole('button', { name: 'Reject' })
// A file is created and can be navigated to while this prompt is still opened
// Click the "Reject" button within the prompt and it will delete the file.
await rejectButton.click()
const submittingToastMessage = page.getByText(
`Successfully deleted file "lego-2x4.kcl"`
)
await expect(submittingToastMessage).toBeVisible()
expect(fileExists()).toBeFalsy()
// Confirm we've navigated back to the main.kcl file after deletion
await expect(projectMenuButton).toContainText('main.kcl')
})
}
)
/**
* Below there are twelve (12) tests for testing the navigation and file creation
* logic around text to cad. The Text to CAD command is now globally available
@ -984,12 +806,12 @@ test.describe('Mocked Text-to-CAD API tests', { tag: ['@skipWin'] }, () => {
)
await expect(page.getByTestId('app-header-file-name')).toBeVisible()
await expect(page.getByTestId('app-header-file-name')).toContainText(
'2x2x2-cube.kcl'
'main.kcl'
)
await u.openFilePanel()
await expect(
page.getByTestId('file-tree-item').getByText('2x2x2-cube.kcl')
page.getByTestId('file-tree-item').getByText('2x2x2-cube')
).toBeVisible()
}
)
@ -1184,13 +1006,13 @@ test.describe('Mocked Text-to-CAD API tests', { tag: ['@skipWin'] }, () => {
)
await expect(page.getByTestId('app-header-file-name')).toBeVisible()
await expect(page.getByTestId('app-header-file-name')).toContainText(
'2x2x2-cube.kcl'
'main.kcl'
)
// Check file is created
await u.openFilePanel()
await expect(
page.getByTestId('file-tree-item').getByText('2x2x2-cube.kcl')
page.getByTestId('file-tree-item').getByText('2x2x2-cube')
).toBeVisible()
}
)
@ -1476,13 +1298,13 @@ test.describe('Mocked Text-to-CAD API tests', { tag: ['@skipWin'] }, () => {
)
await expect(page.getByTestId('app-header-file-name')).toBeVisible()
await expect(page.getByTestId('app-header-file-name')).toContainText(
'2x2x2-cube.kcl'
'main.kcl'
)
// Check file is created
await u.openFilePanel()
await expect(
page.getByTestId('file-tree-item').getByText('2x2x2-cube.kcl')
page.getByTestId('file-tree-item').getByText('2x2x2-cube')
).toBeVisible()
await expect(
page.getByTestId('file-tree-item').getByText('main.kcl')

View File

@ -573,6 +573,7 @@ profile001 = startProfile(sketch002, at = [-12.34, 12.34])
await expect(page.getByTestId('command-bar')).toBeVisible()
await page.waitForTimeout(100)
await cmdBar.progressCmdBar()
await cmdBar.progressCmdBar()
await expect(page.getByText('Confirm Extrude')).toBeVisible()
await cmdBar.progressCmdBar()

View File

@ -16,7 +16,6 @@
<link rel="apple-touch-icon" href="/logo192.png" />
<link rel="manifest" href="/manifest.json" />
<link rel="stylesheet" href="./inter/inter.css" />
<link rel="stylesheet" href="https://use.typekit.net/zzv8rvm.css" />
<script
defer
data-domain="app.zoo.dev"

1
package-lock.json generated
View File

@ -2492,6 +2492,7 @@
},
"node_modules/@clack/prompts/node_modules/is-unicode-supported": {
"version": "1.3.0",
"extraneous": true,
"inBundle": true,
"license": "MIT",
"engines": {

View File

@ -27,7 +27,7 @@ if len(modified_release_body) > max_length:
# Message to send to Discord
data = {
"content": textwrap.dedent(f'''
**{release_version}** is now available! Check out the latest features and improvements here: <https://zoo.dev/modeling-app/download>
**{release_version}** is now available! Check out the latest features and improvements here: <https://zoo.dev/design-studio>
{modified_release_body}
'''),

View File

@ -143,10 +143,14 @@ When you submit a PR to add or modify KCL samples, images will be generated and
[![spur-reduction-gearset](screenshots/spur-reduction-gearset.png)](spur-reduction-gearset/main.kcl)
#### [surgical-drill-guide](surgical-drill-guide/main.kcl) ([screenshot](screenshots/surgical-drill-guide.png))
[![surgical-drill-guide](screenshots/surgical-drill-guide.png)](surgical-drill-guide/main.kcl)
#### [telemetry-antenna](telemetry-antenna/main.kcl) ([screenshot](screenshots/telemetry-antenna.png))
[![telemetry-antenna](screenshots/telemetry-antenna.png)](telemetry-antenna/main.kcl)
#### [thermal-block-insert](thermal-block-insert/main.kcl) ([screenshot](screenshots/thermal-block-insert.png))
[![thermal-block-insert](screenshots/thermal-block-insert.png)](thermal-block-insert/main.kcl)
#### [tooling-nest-block](tooling-nest-block/main.kcl) ([screenshot](screenshots/tooling-nest-block.png))
[![tooling-nest-block](screenshots/tooling-nest-block.png)](tooling-nest-block/main.kcl)
#### [truss-structure](truss-structure/main.kcl) ([screenshot](screenshots/truss-structure.png))
[![truss-structure](screenshots/truss-structure.png)](truss-structure/main.kcl)
#### [utility-sink](utility-sink/main.kcl) ([screenshot](screenshots/utility-sink.png))
[![utility-sink](screenshots/utility-sink.png)](utility-sink/main.kcl)
#### [walkie-talkie](walkie-talkie/main.kcl) ([screenshot](screenshots/walkie-talkie.png))

View File

@ -1,3 +1,4 @@
// Brake Rotor
// A 320mm vented brake disc (rotor), with straight vanes, 30mm thick. The disc bell should accommodate 5 M12 wheel studs on a 114.3mm pitch circle diameter.

View File

@ -78,8 +78,8 @@
"file": "main.kcl",
"pathFromProjectDirectoryToFirstFile": "brake-rotor/main.kcl",
"multipleFiles": false,
"title": "A 320mm vented brake disc (rotor), with straight vanes, 30mm thick. The disc bell should accommodate 5 M12 wheel studs on a 114.3mm pitch circle diameter.",
"description": "",
"title": "Brake Rotor",
"description": "A 320mm vented brake disc (rotor), with straight vanes, 30mm thick. The disc bell should accommodate 5 M12 wheel studs on a 114.3mm pitch circle diameter.",
"files": [
"main.kcl"
]
@ -632,6 +632,16 @@
"main.kcl"
]
},
{
"file": "main.kcl",
"pathFromProjectDirectoryToFirstFile": "telemetry-antenna/main.kcl",
"multipleFiles": false,
"title": "Aircraft telemetry antenna plate",
"description": "Consists of a circular base plate 3 inches in diameter and 0.08 inches thick, with a tapered monopole antenna mounted at the top with a base diameter of 0.65 inches and height of 1.36 inches. Also consists of a mounting base and connector at the bottom of the plate. The plate also has 6 countersunk holes at a defined pitch circle diameter.",
"files": [
"main.kcl"
]
},
{
"file": "main.kcl",
"pathFromProjectDirectoryToFirstFile": "thermal-block-insert/main.kcl",
@ -652,6 +662,16 @@
"main.kcl"
]
},
{
"file": "main.kcl",
"pathFromProjectDirectoryToFirstFile": "truss-structure/main.kcl",
"multipleFiles": false,
"title": "Truss Structure",
"description": "A truss structure is a framework composed of triangular units made from straight members connected at joints, often called nodes. Trusses are widely used in architecture, civil engineering, and construction for their ability to support large loads with minimal material.",
"files": [
"main.kcl"
]
},
{
"file": "main.kcl",
"pathFromProjectDirectoryToFirstFile": "utility-sink/main.kcl",

View File

@ -72,25 +72,25 @@ leftSpacerShape = boxModuleFn(width = leftSpacerWidth)
// Module for power switch including front plate and red rocker button
switchPosition = leftSpacerPosition + leftSpacerWidth / 2 + moduleWidth / 2
swtichWidth = moduleWidth
switchWidth = moduleWidth
// Switch Body
switchBody = boxModuleFn(width = moduleWidth)
// Switch Plate
swtichPlateWidth = 20
switchPlateWidth = 20
switchPlateHeight = 30
switchPlateThickness = 3
switchPlateShape = startSketchOn(switchBody, face = END)
|> startProfile(
%,
at = [
-swtichPlateWidth / 2,
-switchPlateWidth / 2,
-switchPlateHeight / 2
],
)
|> yLine(length = switchPlateHeight)
|> xLine(length = swtichPlateWidth)
|> xLine(length = switchPlateWidth)
|> yLine(length = -switchPlateHeight)
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|> close()
@ -104,8 +104,8 @@ switchPlateBody = extrude(switchPlateShape, length = switchPlateThickness)
// Switch Button
switchButtonHeight = 26
swtichButtonWidth = 15
switchButtonShape = startSketchOn(offsetPlane(-YZ, offset = -swtichButtonWidth / 2))
switchButtonWidth = 15
switchButtonShape = startSketchOn(offsetPlane(-YZ, offset = -switchButtonWidth / 2))
|> startProfile(
%,
at = [
@ -121,7 +121,7 @@ switchButtonShape = startSketchOn(offsetPlane(-YZ, offset = -swtichButtonWidth /
])
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|> close()
switchButtonBody = extrude(switchButtonShape, length = swtichButtonWidth)
switchButtonBody = extrude(switchButtonShape, length = switchButtonWidth)
|> translate(
%,
x = switchPosition,
@ -132,7 +132,7 @@ switchButtonBody = extrude(switchButtonShape, length = swtichButtonWidth)
// Spacer between switch and plug modules for layout alignment
secondSpacerWidth = moduleWidth / 2
secondSpacerPosition = switchPosition + swtichWidth / 2 + secondSpacerWidth / 2
secondSpacerPosition = switchPosition + switchWidth / 2 + secondSpacerWidth / 2
secondSpacerBody = boxModuleFn(width = secondSpacerWidth)
|> translate(
%,

View File

@ -33,14 +33,9 @@ stemLoftProfile2 = startSketchOn(offsetPlane(XY, offset = 75))
// Draw the third profile for the lofted femur
p3Z = 110
p3A = 25
plane003 = {
origin = [0, 0.0, p3Z],
xAxis = [cos(p3A), 0, sin(p3A)],
yAxis = [0.0, 1.0, 0.0]
}
l3 = 32
r3 = 4
stemLoftProfile3 = startSketchOn(plane003)
stemLoftProfile3 = startSketchOn(XY)
|> startProfile(at = [-15.5, -l3 / 2])
|> yLine(length = l3, tag = $seg03)
|> tangentialArc(angle = -120, radius = r3)
@ -49,18 +44,14 @@ stemLoftProfile3 = startSketchOn(plane003)
|> angledLine(angle = 30, length = -segLen(seg03))
|> tangentialArc(endAbsolute = [profileStartX(%), profileStartY(%)])
|> close()
|> translate(z = p3Z)
|> rotate(pitch = -p3A)
// Draw the fourth profile for the lofted femur
p4Z = 130
p4A = 36.5
plane004 = {
origin = [0, 0.0, p4Z],
xAxis = [cos(p4A), 0, sin(p4A)],
yAxis = [0.0, 1.0, 0.0]
}
l4 = 16
r4 = 5
stemLoftProfile4 = startSketchOn(plane004)
stemLoftProfile4 = startSketchOn(XY)
|> startProfile(at = [-23, -l4 / 2])
|> yLine(length = l4, tag = $seg04)
|> tangentialArc(angle = -120, radius = r4)
@ -69,18 +60,14 @@ stemLoftProfile4 = startSketchOn(plane004)
|> angledLine(angle = 30, length = -segLen(seg04))
|> tangentialArc(endAbsolute = [profileStartX(%), profileStartY(%)])
|> close()
|> translate(z = p4Z)
|> rotate(pitch = -p4A)
// Draw the first profile for the femoral stem
p5Z = 140
p5A = 36.5
plane005 = {
origin = [0, 0.0, p5Z],
xAxis = [cos(p5A), 0, sin(p5A)],
yAxis = [0.0, 1.0, 0.0]
}
l5 = 1.6
r5 = 1.6
stemLoftProfile5 = startSketchOn(plane005)
stemLoftProfile5 = startSketchOn(XY)
|> startProfile(at = [-19.5, -l5 / 2])
|> yLine(length = l5, tag = $seg05)
|> tangentialArc(angle = -120, radius = r5)
@ -89,18 +76,14 @@ stemLoftProfile5 = startSketchOn(plane005)
|> angledLine(angle = 30, length = -segLen(seg05))
|> tangentialArc(endAbsolute = [profileStartX(%), profileStartY(%)])
|> close()
|> translate(z = p5Z)
|> rotate(pitch = -p5A)
// Draw the second profile for the femoral stem
p6Z = 145
p6A = 36.5
plane006 = {
origin = [0, 0.0, p6Z],
xAxis = [cos(p6A), 0, sin(p6A)],
yAxis = [0.0, 1.0, 0.0]
}
l6 = 1
r6 = 3
stemLoftProfile6 = startSketchOn(plane006)
stemLoftProfile6 = startSketchOn(XY)
|> startProfile(at = [-23.4, -l6 / 2])
|> yLine(length = l6, tag = $seg06)
|> tangentialArc(angle = -120, radius = r6)
@ -109,27 +92,24 @@ stemLoftProfile6 = startSketchOn(plane006)
|> angledLine(angle = 30, length = -segLen(seg06))
|> tangentialArc(endAbsolute = [profileStartX(%), profileStartY(%)])
|> close()
// Draw the third profile for the femoral stem
stemTab = clone(stemLoftProfile6)
|> extrude(%, length = 6)
|> translate(z = p6Z)
|> rotate(pitch = -p6A)
// Loft the femur using all profiles in sequence
femur = loft([
stemLoftProfile1,
stemLoftProfile2,
stemLoftProfile3,
stemLoftProfile4
])
// Loft the femoral stem
femoralStem = loft([
clone(stemLoftProfile4),
stemLoftProfile5,
stemLoftProfile6
clone(stemLoftProfile6)
])
// Draw the third profile for the femoral stem
stemTab = stemLoftProfile6
|> extrude(length = 6)
// Revolve a hollow socket to represent the femoral head
femoralHead = startSketchOn(XZ)
|> startProfile(at = [4, 0])

Binary file not shown.

Before

Width:  |  Height:  |  Size: 82 KiB

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

View File

@ -53,8 +53,8 @@ baseSlab = boxFn(plane = XY, width = slabWidth, height = -baseThickness)
|> appearance(%, color = "#dbd7d2")
// Create ground platform beneath the base
goundSize = 50
groundBody = boxFn(plane = offsetPlane(XY, offset = -baseThickness), width = goundSize, height = -5)
groundSize = 50
groundBody = boxFn(plane = offsetPlane(XY, offset = -baseThickness), width = groundSize, height = -5)
|> appearance(%, color = "#3a3631")
// Create a single slab with handrail height to be reused with pattern

View File

@ -0,0 +1,63 @@
// Aircraft telemetry antenna plate
// Consists of a circular base plate 3 inches in diameter and 0.08 inches thick, with a tapered monopole antenna mounted at the top with a base diameter of 0.65 inches and height of 1.36 inches. Also consists of a mounting base and connector at the bottom of the plate. The plate also has 6 countersunk holes at a defined pitch circle diameter.
// Set units
@settings(defaultLengthUnit = in)
// Define parameters
plateThickness = 0.08
plateDia = 3
antennaBaseDia = 0.65
antennaAngle = 95
antennaHeight = 1.36
seatingDia = 0.625
totalHeight = 2.14
boltDiameter = .196
boltPitchCircleDiameter = 2.5
// 2D cross-sectional profile of the part that will later be revolved
antennaCrossSectionSketch = startSketchOn(YZ)
antennaCrossSectionProfile = startProfile(antennaCrossSectionSketch, at = [plateDia / 2, 0])
|> yLine(length = plateThickness)
|> xLine(length = -(plateDia - antennaBaseDia) / 2, tag = $seg03)
|> angledLine(angle = antennaAngle, length = 1.1, tag = $seg01)
|> tangentialArc(endAbsolute = [0.025, antennaHeight])
|> xLine(endAbsolute = 0, tag = $seg02)
|> yLine(length = -totalHeight)
|> xLine(length = .25)
|> yLine(length = .05)
|> angledLine(angle = 45, length = 0.025)
|> yLine(length = .125)
|> angledLine(angle = 135, length = 0.025)
|> yLine(length = .125)
|> xLine(length = .025)
|> yLine(length = .025)
|> xLine(endAbsolute = seatingDia / 2)
|> yLine(endAbsolute = -0.25)
|> xLine(endAbsolute = 0.6)
|> yLine(endAbsolute = 0)
|> close()
// Revolution about y-axis of earlier profile
antennaCrossSectionRevolve = revolve(antennaCrossSectionProfile, angle = 360, axis = Y)
// Function to create a countersunk hole
fn countersink(@holePosition) {
startSketchOn(antennaCrossSectionRevolve, face = seg03)
|> circle(center = holePosition, radius = boltDiameter / 2, tag = $hole01)
|> extrude(length = -plateThickness)
|> chamfer(length = 0.04, tags = [hole01])
return { }
}
// PCD converted to radius for positioning the holes
r = boltPitchCircleDiameter / 2
// 6 countersunk holes using the countersink function
countersink([r, 0]) // 0 °
countersink([r * 0.5, r * 0.8660254]) // 60 °
countersink([-r * 0.5, r * 0.8660254]) // 120 °
countersink([-r, 0]) // 180 °
countersink([-r * 0.5, -r * 0.8660254]) // 240 °
countersink([r * 0.5, -r * 0.8660254]) // 300 °

View File

@ -0,0 +1,142 @@
// Truss Structure
// A truss structure is a framework composed of triangular units made from straight members connected at joints, often called nodes. Trusses are widely used in architecture, civil engineering, and construction for their ability to support large loads with minimal material.
@settings(defaultLengthUnit = in)
// Define parameters
thickness = 4
totalLength = 180
totalWidth = 120
totalHeight = 120
legHeight = 48
topTrussAngle = 25
beamWidth = 4
beamLength = 2
sparAngle = 30
nFrames = 3
crossBeamLength = 82
// Sketch the top frame
topFrameSketch = startSketchOn(YZ)
profile001 = startProfile(topFrameSketch, at = [totalWidth / 2, 0])
|> xLine(length = -totalWidth, tag = $bottomFace)
|> yLine(length = 12)
|> angledLine(angle = topTrussAngle, endAbsoluteX = 0, tag = $tag001)
|> angledLine(angle = -topTrussAngle, endAbsoluteX = totalWidth / 2, tag = $tag002)
|> close()
// Create two holes in the top frame sketch to create the center beam
profile002 = startProfile(topFrameSketch, at = [totalWidth / 2 - thickness, thickness])
|> xLine(endAbsolute = thickness / 2)
|> yLine(endAbsolute = segEndY(tag001) - thickness)
|> angledLine(endAbsoluteX = profileStartX(%), angle = -topTrussAngle)
|> close(%)
profile003 = startProfile(topFrameSketch, at = [-totalWidth / 2 + thickness, thickness])
|> xLine(endAbsolute = -thickness / 2)
|> yLine(endAbsolute = segEndY(tag001) - thickness)
|> angledLine(endAbsoluteX = profileStartX(%), angle = 180 + topTrussAngle)
|> close(%)
profile004 = subtract2d(profile001, tool = profile002)
subtract2d(profile001, tool = profile003)
// Extrude the sketch to make the top frame
topFrame = extrude(profile001, length = beamLength)
// Spar 1
sketch002 = startSketchOn(offsetPlane(YZ, offset = .1))
profile006 = startProfile(sketch002, at = [thickness / 2 - 1, 14])
|> angledLine(angle = sparAngle, length = 25)
|> angledLine(angle = -topTrussAngle, length = 5)
|> angledLine(angle = 180 + sparAngle, endAbsoluteX = profileStartX(%))
|> close(%)
spar001 = extrude(profile006, length = 1.8)
// Spar2
profile007 = startProfile(sketch002, at = [-thickness / 2 + 1, 14])
|> angledLine(angle = 180 - sparAngle, length = 25)
|> angledLine(angle = 180 + topTrussAngle, length = 5)
|> angledLine(angle = -sparAngle, endAbsoluteX = profileStartX(%))
|> close(%)
spar002 = extrude(profile007, length = 1.8)
// Combine the top frame with the intermediate support beams
newFrame = topFrame + spar001 + spar002
// Create the two legs on the frame
leg001Sketch = startSketchOn(offsetPlane(XY, offset = .1))
legProfile001 = startProfile(leg001Sketch, at = [0, -totalWidth / 2])
|> xLine(%, length = beamLength - .1)
|> yLine(%, length = beamWidth - 1)
|> xLine(%, endAbsolute = profileStartX(%))
|> close(%)
legProfile002 = startProfile(leg001Sketch, at = [0, totalWidth / 2])
|> xLine(%, length = beamLength - .1)
|> yLine(%, length = -(beamWidth - 1))
|> xLine(%, endAbsolute = profileStartX(%))
|> close(%)
leg001 = extrude(legProfile001, length = -legHeight - .1)
leg002 = extrude(legProfile002, length = -legHeight - .1)
// Combine the top frame with the legs and pattern
fullFrame = newFrame + leg001 + leg002
|> patternLinear3d(
%,
instances = nFrames,
distance = crossBeamLength + beamLength,
axis = [-1, 0, 0],
)
// Create the center cross beam
centerCrossBeamSketch = startSketchOn(YZ)
profile005 = startProfile(centerCrossBeamSketch, at = [0, segEndY(tag001) - 1])
|> angledLine(%, angle = -topTrussAngle, length = beamWidth * 3 / 8)
|> yLine(length = -beamWidth * 3 / 8)
|> angledLine(%, angle = 180 - topTrussAngle, length = beamWidth * 3 / 8)
|> angledLine(%, angle = 180 + topTrussAngle, length = beamWidth * 3 / 8)
|> yLine(length = beamWidth * 3 / 8)
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|> close()
// Extrude the center cross beam and pattern to every frame
centerCrossBeam = extrude(profile005, length = -crossBeamLength)
|> patternLinear3d(
%,
instances = nFrames - 1,
distance = crossBeamLength + beamLength,
axis = [-1, 0, 0],
)
// Create the two side cross beams
sideCrossBeamSketch = startSketchOn(-YZ)
profile008 = startProfile(
sideCrossBeamSketch,
at = [
-totalWidth / 2 + 0.5,
segEndY(tag002) - .5
],
)
|> yLine(length = -beamLength)
|> xLine(length = 3 / 4 * beamWidth)
|> yLine(length = beamLength)
|> close()
profile009 = startProfile(sideCrossBeamSketch, at = [totalWidth / 2, segEndY(tag002) - .5])
|> yLine(length = -beamLength)
|> xLine(%, length = -3 / 4 * beamWidth)
|> yLine(%, length = beamLength)
|> close(%)
// Extrude the side cross beams and pattern to every frame.
extrude([profile008, profile009], length = crossBeamLength)
|> patternLinear3d(
%,
instances = nFrames - 1,
distance = crossBeamLength + beamLength,
axis = [-1, 0, 0],
)

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.1 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 16 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 13 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 13 KiB

20
rust/Cargo.lock generated
View File

@ -1815,7 +1815,7 @@ dependencies = [
[[package]]
name = "kcl-bumper"
version = "0.1.75"
version = "0.1.77"
dependencies = [
"anyhow",
"clap",
@ -1826,7 +1826,7 @@ dependencies = [
[[package]]
name = "kcl-derive-docs"
version = "0.1.75"
version = "0.1.77"
dependencies = [
"Inflector",
"anyhow",
@ -1845,7 +1845,7 @@ dependencies = [
[[package]]
name = "kcl-directory-test-macro"
version = "0.1.75"
version = "0.1.77"
dependencies = [
"convert_case",
"proc-macro2",
@ -1855,7 +1855,7 @@ dependencies = [
[[package]]
name = "kcl-language-server"
version = "0.2.75"
version = "0.2.77"
dependencies = [
"anyhow",
"clap",
@ -1876,7 +1876,7 @@ dependencies = [
[[package]]
name = "kcl-language-server-release"
version = "0.1.75"
version = "0.1.77"
dependencies = [
"anyhow",
"clap",
@ -1896,7 +1896,7 @@ dependencies = [
[[package]]
name = "kcl-lib"
version = "0.2.75"
version = "0.2.77"
dependencies = [
"anyhow",
"approx 0.5.1",
@ -1973,7 +1973,7 @@ dependencies = [
[[package]]
name = "kcl-python-bindings"
version = "0.3.75"
version = "0.3.77"
dependencies = [
"anyhow",
"kcl-lib",
@ -1988,7 +1988,7 @@ dependencies = [
[[package]]
name = "kcl-test-server"
version = "0.1.75"
version = "0.1.77"
dependencies = [
"anyhow",
"hyper 0.14.32",
@ -2001,7 +2001,7 @@ dependencies = [
[[package]]
name = "kcl-to-core"
version = "0.1.75"
version = "0.1.77"
dependencies = [
"anyhow",
"async-trait",
@ -2015,7 +2015,7 @@ dependencies = [
[[package]]
name = "kcl-wasm-lib"
version = "0.1.75"
version = "0.1.77"
dependencies = [
"anyhow",
"bson",

View File

@ -36,20 +36,20 @@ new-sim-test test_name render_to_png="true":
# Run a KCL deterministic simulation test case and accept output.
overwrite-sim-test-sample test_name:
EXPECTORATE=overwrite TWENTY_TWENTY=overwrite {{cita}} {{kcl_lib_flags}} --no-quiet -- simulation_tests::kcl_samples::parse_{{test_name}}
EXPECTORATE=overwrite TWENTY_TWENTY=overwrite {{cita}} {{kcl_lib_flags}} --no-quiet -- simulation_tests::kcl_samples::unparse_{{test_name}}
EXPECTORATE=overwrite TWENTY_TWENTY=overwrite {{cita}} {{kcl_lib_flags}} --no-quiet -- simulation_tests::kcl_samples::kcl_test_execute_{{test_name}}
EXPECTORATE=overwrite TWENTY_TWENTY=overwrite {{cita}} {{kcl_lib_flags}} --no-quiet -- simulation_tests::kcl_samples::test_after_engine
ZOO_SIM_UPDATE=always EXPECTORATE=overwrite TWENTY_TWENTY=overwrite {{cita}} {{kcl_lib_flags}} --no-quiet -- simulation_tests::kcl_samples::parse_{{test_name}}
ZOO_SIM_UPDATE=always EXPECTORATE=overwrite TWENTY_TWENTY=overwrite {{cita}} {{kcl_lib_flags}} --no-quiet -- simulation_tests::kcl_samples::unparse_{{test_name}}
ZOO_SIM_UPDATE=always EXPECTORATE=overwrite TWENTY_TWENTY=overwrite {{cita}} {{kcl_lib_flags}} --no-quiet -- simulation_tests::kcl_samples::kcl_test_execute_{{test_name}}
ZOO_SIM_UPDATE=always EXPECTORATE=overwrite TWENTY_TWENTY=overwrite {{cita}} {{kcl_lib_flags}} --no-quiet -- simulation_tests::kcl_samples::test_after_engine
overwrite-sim-test test_name:
EXPECTORATE=overwrite TWENTY_TWENTY=overwrite {{cita}} {{kcl_lib_flags}} --no-quiet -- simulation_tests::{{test_name}}::parse
EXPECTORATE=overwrite TWENTY_TWENTY=overwrite {{cita}} {{kcl_lib_flags}} --no-quiet -- simulation_tests::{{test_name}}::unparse
EXPECTORATE=overwrite TWENTY_TWENTY=overwrite {{cita}} {{kcl_lib_flags}} --no-quiet -- simulation_tests::{{test_name}}::kcl_test_execute
[ {{test_name}} != "kcl_samples" ] || EXPECTORATE=overwrite TWENTY_TWENTY=overwrite {{cita}} {{kcl_lib_flags}} --no-quiet -- simulation_tests::{{test_name}}::test_after_engine
ZOO_SIM_UPDATE=always EXPECTORATE=overwrite TWENTY_TWENTY=overwrite {{cita}} {{kcl_lib_flags}} --no-quiet -- simulation_tests::{{test_name}}::parse
ZOO_SIM_UPDATE=always EXPECTORATE=overwrite TWENTY_TWENTY=overwrite {{cita}} {{kcl_lib_flags}} --no-quiet -- simulation_tests::{{test_name}}::unparse
ZOO_SIM_UPDATE=always EXPECTORATE=overwrite TWENTY_TWENTY=overwrite {{cita}} {{kcl_lib_flags}} --no-quiet -- simulation_tests::{{test_name}}::kcl_test_execute
[ {{test_name}} != "kcl_samples" ] || ZOO_SIM_UPDATE=always EXPECTORATE=overwrite TWENTY_TWENTY=overwrite {{cita}} {{kcl_lib_flags}} --no-quiet -- simulation_tests::{{test_name}}::test_after_engine
# Regenerate all the simulation test output.
redo-sim-tests:
EXPECTORATE=overwrite TWENTY_TWENTY=overwrite {{cita}} {{kcl_lib_flags}} --no-quiet -- simulation_tests
ZOO_SIM_UPDATE=always EXPECTORATE=overwrite TWENTY_TWENTY=overwrite {{cita}} {{kcl_lib_flags}} --no-quiet -- simulation_tests
test:
cargo install cargo-nextest

View File

@ -1,7 +1,7 @@
[package]
name = "kcl-bumper"
version = "0.1.75"
version = "0.1.77"
edition = "2021"
repository = "https://github.com/KittyCAD/modeling-api"
rust-version = "1.76"

View File

@ -1,7 +1,7 @@
[package]
name = "kcl-derive-docs"
description = "A tool for generating documentation from Rust derive macros"
version = "0.1.75"
version = "0.1.77"
edition = "2021"
license = "MIT"
repository = "https://github.com/KittyCAD/modeling-app"

View File

@ -0,0 +1,142 @@
use proc_macro2::Span;
use quote::{quote, ToTokens};
pub fn do_for_each_example_test(item: proc_macro2::TokenStream) -> proc_macro2::TokenStream {
let item: syn::ItemFn = syn::parse2(item.clone()).unwrap();
let mut result = proc_macro2::TokenStream::new();
for name in TEST_NAMES {
let mut item = item.clone();
item.sig.ident = syn::Ident::new(
&format!("{}_{}", item.sig.ident, name.replace('-', "_")),
Span::call_site(),
);
let name = name.to_owned();
let stmts = &item.block.stmts;
let block = quote! {
{
const NAME: &str = #name;
#(#stmts)*
}
};
item.block = Box::new(syn::parse2(block).unwrap());
result.extend(Some(item.into_token_stream()));
}
result
}
pub fn do_for_all_example_test(item: proc_macro2::TokenStream) -> proc_macro2::TokenStream {
let mut item: syn::ItemFn = syn::parse2(item).unwrap();
let len = TEST_NAMES.len();
let stmts = &item.block.stmts;
let test_names = TEST_NAMES.iter().map(|n| n.to_owned());
let block = quote! {
{
const TEST_NAMES: [&str; #len] = [#(#test_names,)*];
#(#stmts)*
}
};
item.block = Box::new(syn::parse2(block).unwrap());
item.into_token_stream()
}
pub const TEST_NAMES: &[&str] = &[
"std-appearance-hexString-0",
"std-appearance-hexString-1",
"std-appearance-hexString-2",
"std-array-map-0",
"std-array-map-1",
"std-array-pop-0",
"std-array-push-0",
"std-array-reduce-0",
"std-array-reduce-1",
"std-array-reduce-2",
"std-clone-0",
"std-clone-1",
"std-clone-2",
"std-clone-3",
"std-clone-4",
"std-clone-5",
"std-clone-6",
"std-clone-7",
"std-clone-8",
"std-clone-9",
"std-helix-0",
"std-helix-1",
"std-helix-2",
"std-helix-3",
"std-math-abs-0",
"std-math-acos-0",
"std-math-asin-0",
"std-math-atan-0",
"std-math-atan2-0",
"std-math-ceil-0",
"std-math-cos-0",
"std-math-floor-0",
"std-math-ln-0",
"std-math-legLen-0",
"std-math-legAngX-0",
"std-math-legAngY-0",
"std-math-log-0",
"std-math-log10-0",
"std-math-log2-0",
"std-math-max-0",
"std-math-min-0",
"std-math-polar-0",
"std-math-pow-0",
"std-math-rem-0",
"std-math-round-0",
"std-math-sin-0",
"std-math-sqrt-0",
"std-math-tan-0",
"std-offsetPlane-0",
"std-offsetPlane-1",
"std-offsetPlane-2",
"std-offsetPlane-3",
"std-offsetPlane-4",
"std-sketch-circle-0",
"std-sketch-circle-1",
"std-sketch-patternTransform2d-0",
"std-sketch-revolve-0",
"std-sketch-revolve-1",
"std-sketch-revolve-10",
"std-sketch-revolve-11",
"std-sketch-revolve-12",
"std-sketch-revolve-2",
"std-sketch-revolve-3",
"std-sketch-revolve-4",
"std-sketch-revolve-5",
"std-sketch-revolve-6",
"std-sketch-revolve-7",
"std-sketch-revolve-8",
"std-sketch-revolve-9",
"std-solid-chamfer-0",
"std-solid-chamfer-1",
"std-solid-fillet-0",
"std-solid-fillet-1",
"std-solid-hollow-0",
"std-solid-hollow-1",
"std-solid-hollow-2",
"std-solid-patternTransform-0",
"std-solid-patternTransform-1",
"std-solid-patternTransform-2",
"std-solid-patternTransform-3",
"std-solid-patternTransform-4",
"std-solid-patternTransform-5",
"std-solid-shell-0",
"std-solid-shell-1",
"std-solid-shell-2",
"std-solid-shell-3",
"std-solid-shell-4",
"std-solid-shell-5",
"std-solid-shell-6",
"std-transform-mirror2d-0",
"std-transform-mirror2d-1",
"std-transform-mirror2d-2",
"std-transform-mirror2d-3",
"std-transform-mirror2d-4",
"std-units-toDegrees-0",
"std-units-toRadians-0",
];

View File

@ -2,16 +2,16 @@
// automated enforcement.
#![allow(clippy::style)]
mod example_tests;
#[cfg(test)]
mod tests;
mod unbox;
use std::{collections::HashMap, fs};
use std::collections::HashMap;
use convert_case::Casing;
use inflector::{cases::camelcase::to_camel_case, Inflector};
use once_cell::sync::Lazy;
use proc_macro2::Span;
use quote::{format_ident, quote, quote_spanned, ToTokens};
use regex::Regex;
use serde::Deserialize;
@ -28,8 +28,13 @@ pub fn stdlib(attr: proc_macro::TokenStream, item: proc_macro::TokenStream) -> p
}
#[proc_macro_attribute]
pub fn for_each_std_mod(_attr: proc_macro::TokenStream, item: proc_macro::TokenStream) -> proc_macro::TokenStream {
do_for_each_std_mod(item.into()).into()
pub fn for_each_example_test(_attr: proc_macro::TokenStream, item: proc_macro::TokenStream) -> proc_macro::TokenStream {
example_tests::do_for_each_example_test(item.into()).into()
}
#[proc_macro_attribute]
pub fn for_all_example_test(_attr: proc_macro::TokenStream, item: proc_macro::TokenStream) -> proc_macro::TokenStream {
example_tests::do_for_all_example_test(item.into()).into()
}
/// Describes an argument of a stdlib function.
@ -42,6 +47,14 @@ struct ArgMetadata {
/// Does not do anything if the argument is already required.
#[serde(default)]
include_in_snippet: bool,
/// The snippet should suggest this value for the arg.
#[serde(default)]
snippet_value: Option<String>,
/// The snippet should suggest this value for the arg.
#[serde(default)]
snippet_value_array: Option<Vec<String>>,
}
#[derive(Deserialize, Debug)]
@ -69,11 +82,6 @@ struct StdlibMetadata {
#[serde(default)]
feature_tree_operation: bool,
/// If true, expects keyword arguments.
/// If false, expects positional arguments.
#[serde(default)]
keywords: bool,
/// If true, the first argument is unlabeled.
/// If false, all arguments require labels.
#[serde(default)]
@ -92,34 +100,6 @@ fn do_stdlib(
do_stdlib_inner(metadata, attr, item)
}
fn do_for_each_std_mod(item: proc_macro2::TokenStream) -> proc_macro2::TokenStream {
let item: syn::ItemFn = syn::parse2(item.clone()).unwrap();
let mut result = proc_macro2::TokenStream::new();
for name in fs::read_dir("kcl-lib/std").unwrap().filter_map(|e| {
let e = e.unwrap();
let filename = e.file_name();
filename.to_str().unwrap().strip_suffix(".kcl").map(str::to_owned)
}) {
for i in 0..10_usize {
let mut item = item.clone();
item.sig.ident = syn::Ident::new(&format!("{}_{}_shard_{i}", item.sig.ident, name), Span::call_site());
let stmts = &item.block.stmts;
let block = quote! {
{
const STD_MOD_NAME: &str = #name;
const SHARD: usize = #i;
const SHARD_COUNT: usize = 10;
#(#stmts)*
}
};
item.block = Box::new(syn::parse2(block).unwrap());
result.extend(Some(item.into_token_stream()));
}
}
result
}
fn do_output(res: Result<(proc_macro2::TokenStream, Vec<Error>), Error>) -> proc_macro::TokenStream {
match res {
Err(err) => err.to_compile_error().into(),
@ -307,12 +287,6 @@ fn do_stdlib_inner(
quote! { false }
};
let uses_keyword_arguments = if metadata.keywords {
quote! { true }
} else {
quote! { false }
};
let docs_crate = get_crate(None);
// When the user attaches this proc macro to a function with the wrong type
@ -341,6 +315,10 @@ fn do_stdlib_inner(
}
.trim_start_matches('_')
.to_string();
// These aren't really KCL args, they're just state that each stdlib function's impl needs.
if arg_name == "exec_state" || arg_name == "args" {
continue;
}
let ty = match arg {
syn::FnArg::Receiver(pat) => pat.ty.as_ref().into_token_stream(),
@ -351,27 +329,24 @@ fn do_stdlib_inner(
let ty_string = rust_type_to_openapi_type(&ty_string);
let required = !ty_ident.to_string().starts_with("Option <");
let arg_meta = metadata.args.get(&arg_name);
let description = if let Some(s) = arg_meta.map(|arg| &arg.docs) {
quote! { #s }
} else if metadata.keywords && ty_string != "Args" && ty_string != "ExecState" {
errors.push(Error::new_spanned(
&arg,
"Argument was not documented in the args block",
));
let Some(arg_meta) = metadata.args.get(&arg_name) else {
errors.push(Error::new_spanned(arg, format!("arg {arg_name} not found")));
continue;
} else {
quote! { String::new() }
};
let include_in_snippet = required || arg_meta.map(|arg| arg.include_in_snippet).unwrap_or_default();
let description = arg_meta.docs.clone();
let include_in_snippet = required || arg_meta.include_in_snippet;
let snippet_value = arg_meta.snippet_value.clone();
let snippet_value_array = arg_meta.snippet_value_array.clone();
if snippet_value.is_some() && snippet_value_array.is_some() {
errors.push(Error::new_spanned(arg, format!("arg {arg_name} has set both snippet_value and snippet_value array, but at most one of these may be set. Please delete one of them.")));
}
let label_required = !(i == 0 && metadata.unlabeled_first);
let camel_case_arg_name = to_camel_case(&arg_name);
if ty_string != "ExecState" && ty_string != "Args" {
let schema = quote! {
generator.root_schema_for::<#ty_ident>()
};
arg_types.push(quote! {
#docs_crate::StdLibFnArg {
let q0 = quote! {
name: #camel_case_arg_name.to_string(),
type_: #ty_string.to_string(),
schema: #schema,
@ -379,6 +354,32 @@ fn do_stdlib_inner(
label_required: #label_required,
description: #description.to_string(),
include_in_snippet: #include_in_snippet,
};
let q1 = if let Some(snippet_value) = snippet_value {
quote! {
snippet_value: Some(#snippet_value.to_owned()),
}
} else {
quote! {
snippet_value: None,
}
};
let q2 = if let Some(snippet_value_array) = snippet_value_array {
quote! {
snippet_value_array: Some(vec![
#(#snippet_value_array.to_owned()),*
]),
}
} else {
quote! {
snippet_value_array: None,
}
};
arg_types.push(quote! {
#docs_crate::StdLibFnArg {
#q0
#q1
#q2
}
});
}
@ -442,6 +443,8 @@ fn do_stdlib_inner(
label_required: true,
description: String::new(),
include_in_snippet: true,
snippet_value: None,
snippet_value_array: None,
})
}
} else {
@ -508,10 +511,6 @@ fn do_stdlib_inner(
vec![#(#tags),*]
}
fn keyword_arguments(&self) -> bool {
#uses_keyword_arguments
}
fn args(&self, inline_subschemas: bool) -> Vec<#docs_crate::StdLibFnArg> {
let mut settings = schemars::gen::SchemaSettings::openapi3();
// We set this to false so we can recurse them later.

View File

@ -40,6 +40,9 @@ fn test_args_with_refs() {
let (item, mut errors) = do_stdlib(
quote! {
name = "someFn",
args = {
data = { docs = "The data for this function"},
},
},
quote! {
/// Docs
@ -65,6 +68,9 @@ fn test_args_with_lifetime() {
let (item, mut errors) = do_stdlib(
quote! {
name = "someFn",
args = {
data = { docs = "Arg for the function" },
}
},
quote! {
/// Docs
@ -117,7 +123,8 @@ fn test_stdlib_line_to() {
quote! {
name = "lineTo",
args = {
sketch = { docs = "the sketch you're adding the line to" }
data = { docs = "the sketch you're adding the line to" },
sketch = { docs = "the sketch you're adding the line to" },
}
},
quote! {

View File

@ -91,10 +91,6 @@ impl crate::docs::StdLibFn for SomeFn {
vec![]
}
fn keyword_arguments(&self) -> bool {
false
}
fn args(&self, inline_subschemas: bool) -> Vec<crate::docs::StdLibFnArg> {
let mut settings = schemars::gen::SchemaSettings::openapi3();
settings.inline_subschemas = inline_subschemas;
@ -105,8 +101,10 @@ impl crate::docs::StdLibFn for SomeFn {
schema: generator.root_schema_for::<Foo>(),
required: true,
label_required: true,
description: String::new().to_string(),
description: "Arg for the function".to_string(),
include_in_snippet: true,
snippet_value: None,
snippet_value_array: None,
}]
}
@ -123,6 +121,8 @@ impl crate::docs::StdLibFn for SomeFn {
label_required: true,
description: String::new(),
include_in_snippet: true,
snippet_value: None,
snippet_value_array: None,
})
}

View File

@ -91,10 +91,6 @@ impl crate::docs::StdLibFn for SomeFn {
vec![]
}
fn keyword_arguments(&self) -> bool {
false
}
fn args(&self, inline_subschemas: bool) -> Vec<crate::docs::StdLibFnArg> {
let mut settings = schemars::gen::SchemaSettings::openapi3();
settings.inline_subschemas = inline_subschemas;
@ -105,8 +101,10 @@ impl crate::docs::StdLibFn for SomeFn {
schema: generator.root_schema_for::<str>(),
required: true,
label_required: true,
description: String::new().to_string(),
description: "The data for this function".to_string(),
include_in_snippet: true,
snippet_value: None,
snippet_value_array: None,
}]
}
@ -123,6 +121,8 @@ impl crate::docs::StdLibFn for SomeFn {
label_required: true,
description: String::new(),
include_in_snippet: true,
snippet_value: None,
snippet_value_array: None,
})
}

View File

@ -92,23 +92,11 @@ impl crate::docs::StdLibFn for Show {
vec![]
}
fn keyword_arguments(&self) -> bool {
false
}
fn args(&self, inline_subschemas: bool) -> Vec<crate::docs::StdLibFnArg> {
let mut settings = schemars::gen::SchemaSettings::openapi3();
settings.inline_subschemas = inline_subschemas;
let mut generator = schemars::gen::SchemaGenerator::new(settings);
vec![crate::docs::StdLibFnArg {
name: "args".to_string(),
type_: "[number]".to_string(),
schema: generator.root_schema_for::<[f64; 2usize]>(),
required: true,
label_required: true,
description: String::new().to_string(),
include_in_snippet: true,
}]
vec![]
}
fn return_value(&self, inline_subschemas: bool) -> Option<crate::docs::StdLibFnArg> {
@ -124,6 +112,8 @@ impl crate::docs::StdLibFn for Show {
label_required: true,
description: String::new(),
include_in_snippet: true,
snippet_value: None,
snippet_value_array: None,
})
}

View File

@ -92,23 +92,11 @@ impl crate::docs::StdLibFn for Show {
vec![]
}
fn keyword_arguments(&self) -> bool {
false
}
fn args(&self, inline_subschemas: bool) -> Vec<crate::docs::StdLibFnArg> {
let mut settings = schemars::gen::SchemaSettings::openapi3();
settings.inline_subschemas = inline_subschemas;
let mut generator = schemars::gen::SchemaGenerator::new(settings);
vec![crate::docs::StdLibFnArg {
name: "args".to_string(),
type_: "number".to_string(),
schema: generator.root_schema_for::<f64>(),
required: true,
label_required: true,
description: String::new().to_string(),
include_in_snippet: true,
}]
vec![]
}
fn return_value(&self, inline_subschemas: bool) -> Option<crate::docs::StdLibFnArg> {
@ -124,6 +112,8 @@ impl crate::docs::StdLibFn for Show {
label_required: true,
description: String::new(),
include_in_snippet: true,
snippet_value: None,
snippet_value_array: None,
})
}

View File

@ -93,23 +93,11 @@ impl crate::docs::StdLibFn for MyFunc {
vec![]
}
fn keyword_arguments(&self) -> bool {
false
}
fn args(&self, inline_subschemas: bool) -> Vec<crate::docs::StdLibFnArg> {
let mut settings = schemars::gen::SchemaSettings::openapi3();
settings.inline_subschemas = inline_subschemas;
let mut generator = schemars::gen::SchemaGenerator::new(settings);
vec![crate::docs::StdLibFnArg {
name: "args".to_string(),
type_: "kittycad::types::InputFormat".to_string(),
schema: generator.root_schema_for::<Option<kittycad::types::InputFormat>>(),
required: false,
label_required: true,
description: String::new().to_string(),
include_in_snippet: false,
}]
vec![]
}
fn return_value(&self, inline_subschemas: bool) -> Option<crate::docs::StdLibFnArg> {
@ -125,6 +113,8 @@ impl crate::docs::StdLibFn for MyFunc {
label_required: true,
description: String::new(),
include_in_snippet: true,
snippet_value: None,
snippet_value_array: None,
})
}

View File

@ -93,10 +93,6 @@ impl crate::docs::StdLibFn for LineTo {
vec![]
}
fn keyword_arguments(&self) -> bool {
false
}
fn args(&self, inline_subschemas: bool) -> Vec<crate::docs::StdLibFnArg> {
let mut settings = schemars::gen::SchemaSettings::openapi3();
settings.inline_subschemas = inline_subschemas;
@ -108,8 +104,10 @@ impl crate::docs::StdLibFn for LineTo {
schema: generator.root_schema_for::<LineToData>(),
required: true,
label_required: true,
description: String::new().to_string(),
description: "the sketch you're adding the line to".to_string(),
include_in_snippet: true,
snippet_value: None,
snippet_value_array: None,
},
crate::docs::StdLibFnArg {
name: "sketch".to_string(),
@ -119,6 +117,8 @@ impl crate::docs::StdLibFn for LineTo {
label_required: true,
description: "the sketch you're adding the line to".to_string(),
include_in_snippet: true,
snippet_value: None,
snippet_value_array: None,
},
]
}
@ -136,6 +136,8 @@ impl crate::docs::StdLibFn for LineTo {
label_required: true,
description: String::new(),
include_in_snippet: true,
snippet_value: None,
snippet_value_array: None,
})
}

View File

@ -92,23 +92,11 @@ impl crate::docs::StdLibFn for Min {
vec![]
}
fn keyword_arguments(&self) -> bool {
false
}
fn args(&self, inline_subschemas: bool) -> Vec<crate::docs::StdLibFnArg> {
let mut settings = schemars::gen::SchemaSettings::openapi3();
settings.inline_subschemas = inline_subschemas;
let mut generator = schemars::gen::SchemaGenerator::new(settings);
vec![crate::docs::StdLibFnArg {
name: "args".to_string(),
type_: "[number]".to_string(),
schema: generator.root_schema_for::<Vec<f64>>(),
required: true,
label_required: true,
description: String::new().to_string(),
include_in_snippet: true,
}]
vec![]
}
fn return_value(&self, inline_subschemas: bool) -> Option<crate::docs::StdLibFnArg> {
@ -124,6 +112,8 @@ impl crate::docs::StdLibFn for Min {
label_required: true,
description: String::new(),
include_in_snippet: true,
snippet_value: None,
snippet_value_array: None,
})
}

View File

@ -92,23 +92,11 @@ impl crate::docs::StdLibFn for Show {
vec![]
}
fn keyword_arguments(&self) -> bool {
false
}
fn args(&self, inline_subschemas: bool) -> Vec<crate::docs::StdLibFnArg> {
let mut settings = schemars::gen::SchemaSettings::openapi3();
settings.inline_subschemas = inline_subschemas;
let mut generator = schemars::gen::SchemaGenerator::new(settings);
vec![crate::docs::StdLibFnArg {
name: "args".to_string(),
type_: "number".to_string(),
schema: generator.root_schema_for::<Option<f64>>(),
required: false,
label_required: true,
description: String::new().to_string(),
include_in_snippet: false,
}]
vec![]
}
fn return_value(&self, inline_subschemas: bool) -> Option<crate::docs::StdLibFnArg> {
@ -124,6 +112,8 @@ impl crate::docs::StdLibFn for Show {
label_required: true,
description: String::new(),
include_in_snippet: true,
snippet_value: None,
snippet_value_array: None,
})
}

View File

@ -92,23 +92,11 @@ impl crate::docs::StdLibFn for Import {
vec![]
}
fn keyword_arguments(&self) -> bool {
false
}
fn args(&self, inline_subschemas: bool) -> Vec<crate::docs::StdLibFnArg> {
let mut settings = schemars::gen::SchemaSettings::openapi3();
settings.inline_subschemas = inline_subschemas;
let mut generator = schemars::gen::SchemaGenerator::new(settings);
vec![crate::docs::StdLibFnArg {
name: "args".to_string(),
type_: "kittycad::types::InputFormat".to_string(),
schema: generator.root_schema_for::<Option<kittycad::types::InputFormat>>(),
required: false,
label_required: true,
description: String::new().to_string(),
include_in_snippet: false,
}]
vec![]
}
fn return_value(&self, inline_subschemas: bool) -> Option<crate::docs::StdLibFnArg> {
@ -124,6 +112,8 @@ impl crate::docs::StdLibFn for Import {
label_required: true,
description: String::new(),
include_in_snippet: true,
snippet_value: None,
snippet_value_array: None,
})
}

View File

@ -92,23 +92,11 @@ impl crate::docs::StdLibFn for Import {
vec![]
}
fn keyword_arguments(&self) -> bool {
false
}
fn args(&self, inline_subschemas: bool) -> Vec<crate::docs::StdLibFnArg> {
let mut settings = schemars::gen::SchemaSettings::openapi3();
settings.inline_subschemas = inline_subschemas;
let mut generator = schemars::gen::SchemaGenerator::new(settings);
vec![crate::docs::StdLibFnArg {
name: "args".to_string(),
type_: "kittycad::types::InputFormat".to_string(),
schema: generator.root_schema_for::<Option<kittycad::types::InputFormat>>(),
required: false,
label_required: true,
description: String::new().to_string(),
include_in_snippet: false,
}]
vec![]
}
fn return_value(&self, inline_subschemas: bool) -> Option<crate::docs::StdLibFnArg> {
@ -124,6 +112,8 @@ impl crate::docs::StdLibFn for Import {
label_required: true,
description: String::new(),
include_in_snippet: true,
snippet_value: None,
snippet_value_array: None,
})
}

View File

@ -92,23 +92,11 @@ impl crate::docs::StdLibFn for Import {
vec![]
}
fn keyword_arguments(&self) -> bool {
false
}
fn args(&self, inline_subschemas: bool) -> Vec<crate::docs::StdLibFnArg> {
let mut settings = schemars::gen::SchemaSettings::openapi3();
settings.inline_subschemas = inline_subschemas;
let mut generator = schemars::gen::SchemaGenerator::new(settings);
vec![crate::docs::StdLibFnArg {
name: "args".to_string(),
type_: "kittycad::types::InputFormat".to_string(),
schema: generator.root_schema_for::<Option<kittycad::types::InputFormat>>(),
required: false,
label_required: true,
description: String::new().to_string(),
include_in_snippet: false,
}]
vec![]
}
fn return_value(&self, inline_subschemas: bool) -> Option<crate::docs::StdLibFnArg> {
@ -124,6 +112,8 @@ impl crate::docs::StdLibFn for Import {
label_required: true,
description: String::new(),
include_in_snippet: true,
snippet_value: None,
snippet_value_array: None,
})
}

View File

@ -92,23 +92,11 @@ impl crate::docs::StdLibFn for Show {
vec![]
}
fn keyword_arguments(&self) -> bool {
false
}
fn args(&self, inline_subschemas: bool) -> Vec<crate::docs::StdLibFnArg> {
let mut settings = schemars::gen::SchemaSettings::openapi3();
settings.inline_subschemas = inline_subschemas;
let mut generator = schemars::gen::SchemaGenerator::new(settings);
vec![crate::docs::StdLibFnArg {
name: "args".to_string(),
type_: "[number]".to_string(),
schema: generator.root_schema_for::<Vec<f64>>(),
required: true,
label_required: true,
description: String::new().to_string(),
include_in_snippet: true,
}]
vec![]
}
fn return_value(&self, inline_subschemas: bool) -> Option<crate::docs::StdLibFnArg> {
@ -124,6 +112,8 @@ impl crate::docs::StdLibFn for Show {
label_required: true,
description: String::new(),
include_in_snippet: true,
snippet_value: None,
snippet_value_array: None,
})
}

View File

@ -91,10 +91,6 @@ impl crate::docs::StdLibFn for SomeFunction {
vec![]
}
fn keyword_arguments(&self) -> bool {
false
}
fn args(&self, inline_subschemas: bool) -> Vec<crate::docs::StdLibFnArg> {
let mut settings = schemars::gen::SchemaSettings::openapi3();
settings.inline_subschemas = inline_subschemas;
@ -115,6 +111,8 @@ impl crate::docs::StdLibFn for SomeFunction {
label_required: true,
description: String::new(),
include_in_snippet: true,
snippet_value: None,
snippet_value_array: None,
})
}

View File

@ -1,7 +1,7 @@
[package]
name = "kcl-directory-test-macro"
description = "A tool for generating tests from a directory of kcl files"
version = "0.1.75"
version = "0.1.77"
edition = "2021"
license = "MIT"
repository = "https://github.com/KittyCAD/modeling-app"

View File

@ -1,6 +1,6 @@
[package]
name = "kcl-language-server-release"
version = "0.1.75"
version = "0.1.77"
edition = "2021"
authors = ["KittyCAD Inc <kcl@kittycad.io>"]
publish = false

View File

@ -2,7 +2,7 @@
name = "kcl-language-server"
description = "A language server for KCL."
authors = ["KittyCAD Inc <kcl@kittycad.io>"]
version = "0.2.75"
version = "0.2.77"
edition = "2021"
license = "MIT"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -1,7 +1,7 @@
[package]
name = "kcl-lib"
description = "KittyCAD Language implementation and tools"
version = "0.2.75"
version = "0.2.77"
edition = "2021"
license = "MIT"
repository = "https://github.com/KittyCAD/modeling-app"

View File

@ -10,7 +10,9 @@ use tower_lsp::lsp_types::{
use crate::{
execution::annotations,
parsing::{
ast::types::{Annotation, ImportSelector, ItemVisibility, Node, NonCodeValue, VariableKind},
ast::types::{
Annotation, Expr, ImportSelector, ItemVisibility, LiteralValue, Node, NonCodeValue, VariableKind,
},
token::NumericSuffix,
},
ModuleId,
@ -293,17 +295,6 @@ impl DocData {
}
}
#[cfg(test)]
fn examples(&self) -> impl Iterator<Item = &String> {
match self {
DocData::Fn(f) => f.examples.iter(),
DocData::Const(c) => c.examples.iter(),
DocData::Ty(t) => t.examples.iter(),
DocData::Mod(_) => unimplemented!(),
}
.filter_map(|(s, p)| (!p.norun).then_some(s))
}
fn expect_mod(&self) -> &ModData {
match self {
DocData::Mod(m) => m,
@ -694,6 +685,8 @@ pub struct ArgData {
/// This is helpful if the type is really basic, like "number" -- that won't tell the user much about
/// how this argument is meant to be used.
pub docs: Option<String>,
/// If given, LSP should use these as completion items.
pub snippet_array: Option<Vec<String>>,
}
impl fmt::Display for ArgData {
@ -721,6 +714,7 @@ pub enum ArgKind {
impl ArgData {
fn from_ast(arg: &crate::parsing::ast::types::Parameter) -> Self {
let mut result = ArgData {
snippet_array: Default::default(),
name: arg.identifier.name.clone(),
ty: arg.type_.as_ref().map(|t| t.to_string()),
docs: None,
@ -749,6 +743,30 @@ impl ArgData {
p.value
);
}
} else if p.key.name == "snippetArray" {
let Expr::ArrayExpression(arr) = &p.value else {
panic!(
"Invalid value for `snippetArray`, expected array literal, found {:?}",
p.value
);
};
let mut items = Vec::new();
for s in &arr.elements {
let Expr::Literal(lit) = s else {
panic!(
"Invalid value in `snippetArray`, all items must be string literals but found {:?}",
s
);
};
let LiteralValue::String(litstr) = &lit.inner.value else {
panic!(
"Invalid value in `snippetArray`, all items must be string literals but found {:?}",
s
);
};
items.push(litstr.to_owned());
}
result.snippet_array = Some(items);
}
}
}
@ -770,6 +788,19 @@ impl ArgData {
} else {
format!("{} = ", self.name)
};
if let Some(vals) = &self.snippet_array {
let mut snippet = label.to_owned();
snippet.push('[');
let n = vals.len();
for (i, val) in vals.iter().enumerate() {
snippet.push_str(&format!("${{{}:{}}}", index + i, val));
if i != n - 1 {
snippet.push_str(", ");
}
}
snippet.push(']');
return Some((index + n - 1, snippet));
}
match self.ty.as_deref() {
Some(s) if s.starts_with("number") => Some((index, format!(r#"{label}${{{}:3.14}}"#, index))),
Some("Point2d") => Some((
@ -1185,7 +1216,7 @@ impl ApplyMeta for ArgData {
#[cfg(test)]
mod test {
use kcl_derive_docs::for_each_std_mod;
use kcl_derive_docs::{for_all_example_test, for_each_example_test};
use super::*;
@ -1223,51 +1254,81 @@ mod test {
);
}
#[for_each_std_mod]
#[for_all_example_test]
#[tokio::test(flavor = "multi_thread")]
async fn missing_test_examples() {
fn check_mod(m: &ModData) {
for d in m.children.values() {
let DocData::Fn(f) = d else {
continue;
};
for i in 0..f.examples.len() {
let name = format!("{}-{i}", f.qual_name.replace("::", "-"));
assert!(TEST_NAMES.contains(&&*name), "Missing test for example \"{name}\", maybe need to update kcl-derive-docs/src/example_tests.rs?")
}
}
}
let data = walk_prelude();
check_mod(&data);
for m in data.children.values() {
if let DocData::Mod(m) = m {
check_mod(m);
}
}
}
#[for_each_example_test]
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_examples() {
let std = walk_prelude();
let mut errs = Vec::new();
let data = if STD_MOD_NAME == "prelude" {
let names = NAME.split('-');
let mut mods: Vec<_> = names.collect();
let number = mods.pop().unwrap();
let number: usize = number.parse().unwrap();
let name = mods.pop().unwrap();
let mut qualname = mods.join("::");
qualname.push_str("::");
qualname.push_str(name);
let data = if mods.len() == 1 {
&std
} else {
std.children
.get(&format!("M:std::{STD_MOD_NAME}"))
.unwrap()
.expect_mod()
std.children.get(&format!("M:std::{}", mods[1])).unwrap().expect_mod()
};
let mut count = 0;
for d in data.children.values() {
if let DocData::Mod(_) = d {
let Some(DocData::Fn(d)) = data.children.get(&format!("I:{qualname}")) else {
panic!("Could not find data for {NAME} (missing a child entry for {qualname}), maybe need to update kcl-derive-docs/src/example_tests.rs?");
};
for (i, eg) in d.examples.iter().enumerate() {
if i != number {
continue;
}
for (i, eg) in d.examples().enumerate() {
count += 1;
if count % SHARD_COUNT != SHARD {
continue;
let result = match crate::test_server::execute_and_snapshot(&eg.0, None).await {
Err(crate::errors::ExecError::Kcl(e)) => {
panic!("Error testing example {}{i}: {}", d.name, e.error.message());
}
let result = match crate::test_server::execute_and_snapshot(eg, None).await {
Err(crate::errors::ExecError::Kcl(e)) => {
errs.push(format!("Error testing example {}{i}: {}", d.name(), e.error.message()));
continue;
}
Err(other_err) => panic!("{}", other_err),
Ok(img) => img,
};
twenty_twenty::assert_image(
format!("tests/outputs/serial_test_example_{}{i}.png", d.example_name()),
&result,
0.99,
);
Err(other_err) => panic!("{}", other_err),
Ok(img) => img,
};
if eg.1.norun {
return;
}
twenty_twenty::assert_image(
format!(
"tests/outputs/serial_test_example_fn_{}{i}.png",
qualname.replace("::", "-")
),
&result,
0.99,
);
return;
}
if !errs.is_empty() {
panic!("{}", errs.join("\n\n"));
}
panic!("Could not find data for {NAME} (no example {number}), maybe need to update kcl-derive-docs/src/example_tests.rs?");
}
}

View File

@ -78,8 +78,6 @@ pub struct StdLibFnData {
pub description: String,
/// The tags of the function.
pub tags: Vec<String>,
/// If this function uses keyword arguments, or positional arguments.
pub keyword_arguments: bool,
/// The args of the function.
pub args: Vec<StdLibFnArg>,
/// The return value of the function.
@ -111,6 +109,13 @@ pub struct StdLibFnArg {
/// Include this in completion snippets?
#[serde(default, skip_serializing_if = "is_false")]
pub include_in_snippet: bool,
/// Snippet should suggest this value for the argument.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub snippet_value: Option<String>,
/// Snippet should suggest this value for the argument.
/// The suggested value should be an array, with these elements.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub snippet_value_array: Option<Vec<String>>,
/// Additional information that could be used instead of the type's description.
/// This is helpful if the type is really basic, like "u32" -- that won't tell the user much about
/// how this argument is meant to be used.
@ -165,6 +170,21 @@ impl StdLibFnArg {
} else {
""
};
if let Some(vals) = &self.snippet_value_array {
let mut snippet = label.to_owned();
snippet.push('[');
for (i, val) in vals.iter().enumerate() {
snippet.push_str(&format!("${{{}:{}}}", index + i, val));
if i != vals.len() - 1 {
snippet.push_str(", ");
}
}
snippet.push(']');
return Ok(Some((index + vals.len() - 1, snippet)));
}
if let Some(val) = &self.snippet_value {
return Ok(Some((index, format!("{label}${{{}:{}}}", index, val))));
}
if (self.type_ == "Sketch"
|| self.type_ == "[Sketch]"
|| self.type_ == "Geometry"
@ -450,9 +470,6 @@ pub trait StdLibFn: std::fmt::Debug + Send + Sync {
/// The description of the function.
fn description(&self) -> String;
/// Does this use keyword arguments, or positional?
fn keyword_arguments(&self) -> bool;
/// The tags of the function.
fn tags(&self) -> Vec<String>;
@ -487,7 +504,6 @@ pub trait StdLibFn: std::fmt::Debug + Send + Sync {
summary: self.summary(),
description: self.description(),
tags: self.tags(),
keyword_arguments: self.keyword_arguments(),
args: self.args(false),
return_value: self.return_value(false),
unpublished: self.unpublished(),
@ -571,7 +587,7 @@ pub trait StdLibFn: std::fmt::Debug + Send + Sync {
} else if self.name() == "subtract2D" {
return Ok("subtract2d(${0:%}, tool = ${1:%})".to_string());
}
let in_keyword_fn = self.keyword_arguments();
let in_keyword_fn = true;
let mut args = Vec::new();
let mut index = 0;
for arg in self.args(true).iter() {
@ -988,6 +1004,13 @@ mod tests {
assert_eq!(snippet, r#"startSketchOn(${0:XY})"#);
}
#[test]
fn get_autocomplete_snippet_start_profile() {
let start_sketch_on_fn: Box<dyn StdLibFn> = Box::new(crate::std::sketch::StartProfile);
let snippet = start_sketch_on_fn.to_autocomplete_snippet().unwrap();
assert_eq!(snippet, r#"startProfile(${0:%}, at = [${1:0}, ${2:0}])"#);
}
#[test]
fn get_autocomplete_snippet_pattern_circular_3d() {
// We test this one specifically because it has ints and floats and strings.
@ -995,7 +1018,7 @@ mod tests {
let snippet = pattern_fn.to_autocomplete_snippet().unwrap();
assert_eq!(
snippet,
r#"patternCircular3d(${0:%}, instances = ${1:10}, axis = [${2:3.14}, ${3:3.14}, ${4:3.14}], center = [${5:3.14}, ${6:3.14}, ${7:3.14}])"#
r#"patternCircular3d(${0:%}, instances = ${1:10}, axis = [${2:1}, ${3:0}, ${4:0}], center = [${5:0}, ${6:0}, ${7:0}])"#
);
}
@ -1017,8 +1040,8 @@ mod tests {
};
let snippet = circle_fn.to_autocomplete_snippet();
assert_eq!(
snippet,
r#"circle(center = [${0:3.14}, ${1:3.14}], radius = ${2:3.14})"#
snippet, r#"circle(center = [${0:0}, ${1:0}], diameter = ${2:3.14})"#,
"actual = left, expected = right"
);
}
@ -1048,7 +1071,7 @@ mod tests {
let snippet = pattern_fn.to_autocomplete_snippet().unwrap();
assert_eq!(
snippet,
r#"patternLinear2d(${0:%}, instances = ${1:10}, distance = ${2:3.14}, axis = [${3:3.14}, ${4:3.14}])"#
r#"patternLinear2d(${0:%}, instances = ${1:10}, distance = ${2:3.14}, axis = [${3:1}, ${4:0}])"#
);
}

View File

@ -20,6 +20,14 @@ use crate::{
#[cfg(test)]
mod mermaid_tests;
macro_rules! internal_error {
($range:expr, $($rest:tt)*) => {{
let message = format!($($rest)*);
debug_assert!(false, "{}", &message);
return Err(KclError::Internal(KclErrorDetails::new(message, vec![$range])));
}};
}
/// A command that may create or update artifacts on the TS side. Because
/// engine commands are batched, we don't have the response yet when these are
/// created.
@ -992,7 +1000,10 @@ fn artifacts_to_update(
let path_id = ArtifactId::new(match cmd {
ModelingCmd::ClosePath(c) => c.path_id,
ModelingCmd::ExtendPath(e) => e.path.into(),
_ => unreachable!(),
_ => internal_error!(
range,
"Close or extend path command variant not handled: id={id:?}, cmd={cmd:?}"
),
});
let mut return_arr = Vec::new();
return_arr.push(Artifact::Segment(Segment {
@ -1023,6 +1034,69 @@ fn artifacts_to_update(
}
return Ok(return_arr);
}
ModelingCmd::EntityMirror(kcmc::EntityMirror {
ids: original_path_ids, ..
})
| ModelingCmd::EntityMirrorAcrossEdge(kcmc::EntityMirrorAcrossEdge {
ids: original_path_ids, ..
}) => {
let face_edge_infos = match response {
OkModelingCmdResponse::EntityMirror(resp) => &resp.entity_face_edge_ids,
OkModelingCmdResponse::EntityMirrorAcrossEdge(resp) => &resp.entity_face_edge_ids,
_ => internal_error!(
range,
"Mirror response variant not handled: id={id:?}, cmd={cmd:?}, response={response:?}"
),
};
if original_path_ids.len() != face_edge_infos.len() {
internal_error!(range, "EntityMirror or EntityMirrorAcrossEdge response has different number face edge info than original mirrored paths: id={id:?}, cmd={cmd:?}, response={response:?}");
}
let mut return_arr = Vec::new();
for (face_edge_info, original_path_id) in face_edge_infos.iter().zip(original_path_ids) {
let original_path_id = ArtifactId::new(*original_path_id);
let path_id = ArtifactId::new(face_edge_info.object_id);
// The path may be an existing path that was extended or a new
// path.
let mut path = if let Some(Artifact::Path(path)) = artifacts.get(&path_id) {
// Existing path.
path.clone()
} else {
// It's a new path. We need the original path to get some
// of its info.
let Some(Artifact::Path(original_path)) = artifacts.get(&original_path_id) else {
// We couldn't find the original path. This is a bug.
internal_error!(range, "Couldn't find original path for mirror2d: original_path_id={original_path_id:?}, cmd={cmd:?}");
};
Path {
id: path_id,
plane_id: original_path.plane_id,
seg_ids: Vec::new(),
sweep_id: None,
solid2d_id: None,
code_ref: code_ref.clone(),
composite_solid_id: None,
}
};
face_edge_info.edges.iter().for_each(|edge_id| {
let edge_id = ArtifactId::new(*edge_id);
return_arr.push(Artifact::Segment(Segment {
id: edge_id,
path_id: path.id,
surface_id: None,
edge_ids: Vec::new(),
edge_cut_id: None,
code_ref: code_ref.clone(),
common_surface_ids: Vec::new(),
}));
// Add the edge ID to the path.
path.seg_ids.push(edge_id);
});
return_arr.push(Artifact::Path(path));
}
return Ok(return_arr);
}
ModelingCmd::Extrude(kcmc::Extrude { target, .. })
| ModelingCmd::Revolve(kcmc::Revolve { target, .. })
| ModelingCmd::RevolveAboutEdge(kcmc::RevolveAboutEdge { target, .. })
@ -1032,7 +1106,7 @@ fn artifacts_to_update(
ModelingCmd::Revolve(_) => SweepSubType::Revolve,
ModelingCmd::RevolveAboutEdge(_) => SweepSubType::RevolveAboutEdge,
ModelingCmd::Sweep(_) => SweepSubType::Sweep,
_ => unreachable!(),
_ => internal_error!(range, "Sweep-like command variant not handled: id={id:?}, cmd={cmd:?}",),
};
let mut return_arr = Vec::new();
let target = ArtifactId::from(target);
@ -1297,7 +1371,13 @@ fn artifacts_to_update(
let edge_id = if let Some(edge_id) = cmd.edge_id {
ArtifactId::new(edge_id)
} else {
cmd.edge_ids.first().unwrap().into()
let Some(edge_id) = cmd.edge_ids.first() else {
internal_error!(
range,
"Solid3dFilletEdge command has no edge ID: id={id:?}, cmd={cmd:?}"
);
};
edge_id.into()
};
return_arr.push(Artifact::EdgeCut(EdgeCut {
id,
@ -1366,7 +1446,10 @@ fn artifacts_to_update(
let solid_ids = union.solid_ids.iter().copied().map(ArtifactId::new).collect::<Vec<_>>();
(CompositeSolidSubType::Union, solid_ids, Vec::new())
}
_ => unreachable!(),
_ => internal_error!(
range,
"Boolean or composite command variant not handled: id={id:?}, cmd={cmd:?}"
),
};
let mut new_solid_ids = vec![id];

View File

@ -86,7 +86,7 @@ impl ExecutorContext {
) -> Result<(Option<KclValue>, EnvironmentRef, Vec<String>), KclError> {
crate::log::log(format!("enter module {path} {}", exec_state.stack()));
let mut local_state = ModuleState::new(path.std_path(), exec_state.stack().memory.clone(), Some(module_id));
let mut local_state = ModuleState::new(path.clone(), exec_state.stack().memory.clone(), Some(module_id));
if !preserve_mem {
std::mem::swap(&mut exec_state.mod_local, &mut local_state);
}
@ -139,8 +139,13 @@ impl ExecutorContext {
let source_range = SourceRange::from(import_stmt);
let attrs = &import_stmt.outer_attrs;
let module_path = ModulePath::from_import_path(
&import_stmt.path,
&self.settings.project_directory,
&exec_state.mod_local.path,
)?;
let module_id = self
.open_module(&import_stmt.path, attrs, exec_state, source_range)
.open_module(&import_stmt.path, attrs, &module_path, exec_state, source_range)
.await?;
match &import_stmt.selector {
@ -281,7 +286,14 @@ impl ExecutorContext {
// Track exports.
if let ItemVisibility::Export = variable_declaration.visibility {
exec_state.mod_local.module_exports.push(var_name);
if matches!(body_type, BodyType::Root) {
exec_state.mod_local.module_exports.push(var_name);
} else {
exec_state.err(CompilationError::err(
variable_declaration.as_source_range(),
"Exports are only supported at the top-level of a file. Remove `export` or move it to the top-level.",
));
}
}
// Variable declaration can be the return value of a module.
last_expr = matches!(body_type, BodyType::Root).then_some(value);
@ -291,9 +303,9 @@ impl ExecutorContext {
let impl_kind = annotations::get_impl(&ty.outer_attrs, metadata.source_range)?.unwrap_or_default();
match impl_kind {
annotations::Impl::Rust => {
let std_path = match &exec_state.mod_local.std_path {
Some(p) => p,
None => {
let std_path = match &exec_state.mod_local.path {
ModulePath::Std { value } => value,
ModulePath::Local { .. } | ModulePath::Main => {
return Err(KclError::Semantic(KclErrorDetails::new(
"User-defined types are not yet supported.".to_owned(),
vec![metadata.source_range],
@ -413,16 +425,15 @@ impl ExecutorContext {
&self,
path: &ImportPath,
attrs: &[Node<Annotation>],
resolved_path: &ModulePath,
exec_state: &mut ExecState,
source_range: SourceRange,
) -> Result<ModuleId, KclError> {
let resolved_path = ModulePath::from_import_path(path, &self.settings.project_directory);
match path {
ImportPath::Kcl { .. } => {
exec_state.global.mod_loader.cycle_check(&resolved_path, source_range)?;
exec_state.global.mod_loader.cycle_check(resolved_path, source_range)?;
if let Some(id) = exec_state.id_for_module(&resolved_path) {
if let Some(id) = exec_state.id_for_module(resolved_path) {
return Ok(id);
}
@ -433,12 +444,12 @@ impl ExecutorContext {
exec_state.add_id_to_source(id, source.clone());
// TODO handle parsing errors properly
let parsed = crate::parsing::parse_str(&source.source, id).parse_errs_as_err()?;
exec_state.add_module(id, resolved_path, ModuleRepr::Kcl(parsed, None));
exec_state.add_module(id, resolved_path.clone(), ModuleRepr::Kcl(parsed, None));
Ok(id)
}
ImportPath::Foreign { .. } => {
if let Some(id) = exec_state.id_for_module(&resolved_path) {
if let Some(id) = exec_state.id_for_module(resolved_path) {
return Ok(id);
}
@ -448,11 +459,11 @@ impl ExecutorContext {
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, None));
exec_state.add_module(id, resolved_path.clone(), ModuleRepr::Foreign(geom, None));
Ok(id)
}
ImportPath::Std { .. } => {
if let Some(id) = exec_state.id_for_module(&resolved_path) {
if let Some(id) = exec_state.id_for_module(resolved_path) {
return Ok(id);
}
@ -464,7 +475,7 @@ impl ExecutorContext {
let parsed = crate::parsing::parse_str(&source.source, id)
.parse_errs_as_err()
.unwrap();
exec_state.add_module(id, resolved_path, ModuleRepr::Kcl(parsed, None));
exec_state.add_module(id, resolved_path.clone(), ModuleRepr::Kcl(parsed, None));
Ok(id)
}
}
@ -625,7 +636,7 @@ impl ExecutorContext {
.unwrap_or(false);
if rust_impl {
if let Some(std_path) = &exec_state.mod_local.std_path {
if let ModulePath::Std { value: std_path } = &exec_state.mod_local.path {
let (func, props) = crate::std::std_fn(std_path, statement_kind.expect_name());
KclValue::Function {
value: FunctionSource::Std {
@ -722,23 +733,7 @@ fn apply_ascription(
let ty = RuntimeType::from_parsed(ty.inner.clone(), exec_state, value.into())
.map_err(|e| KclError::Semantic(e.into()))?;
let mut value = value.clone();
// If the number has unknown units but the user is explicitly specifying them, treat the value as having had it's units erased,
// rather than forcing the user to explicitly erase them.
if let KclValue::Number { value: n, meta, .. } = &value {
if let RuntimeType::Primitive(PrimitiveType::Number(num)) = &ty {
if num.is_fully_specified() {
value = KclValue::Number {
ty: NumericType::Any,
value: *n,
meta: meta.clone(),
};
}
}
}
value.coerce(&ty, exec_state).map_err(|_| {
value.coerce(&ty, false, exec_state).map_err(|_| {
let suggestion = if ty == RuntimeType::length() {
", you might try coercing to a fully specified numeric type such as `number(mm)`"
} else if ty == RuntimeType::angle() {
@ -748,7 +743,7 @@ fn apply_ascription(
};
KclError::Semantic(KclErrorDetails::new(
format!(
"could not coerce {} value to type {ty}{suggestion}",
"could not coerce value of type {} to type {ty}{suggestion}",
value.human_friendly_type()
),
vec![source_range],
@ -1624,8 +1619,8 @@ arr1 = [42]: [number(cm)]
assert_eq!(*ty, RuntimeType::known_length(UnitLen::Cm));
// Compare, ignoring meta.
if let KclValue::Number { value, ty, .. } = &value[0] {
// Converted from mm to cm.
assert_eq!(*value, 4.2);
// It should not convert units.
assert_eq!(*value, 42.0);
assert_eq!(*ty, NumericType::Known(UnitType::Length(UnitLen::Cm)));
} else {
panic!("Expected a number; found {:?}", value[0]);
@ -1641,7 +1636,7 @@ a = 42: string
let err = result.unwrap_err();
assert!(
err.to_string()
.contains("could not coerce number(default units) value to type string"),
.contains("could not coerce value of type number(default units) to type string"),
"Expected error but found {err:?}"
);
@ -1652,7 +1647,7 @@ a = 42: Plane
let err = result.unwrap_err();
assert!(
err.to_string()
.contains("could not coerce number(default units) value to type Plane"),
.contains("could not coerce value of type number(default units) to type Plane"),
"Expected error but found {err:?}"
);
@ -1662,8 +1657,9 @@ arr = [0]: [string]
let result = parse_execute(program).await;
let err = result.unwrap_err();
assert!(
err.to_string()
.contains("could not coerce [any; 1] value to type [string]"),
err.to_string().contains(
"could not coerce value of type array of number(default units) with 1 value to type [string]"
),
"Expected error but found {err:?}"
);
@ -1674,7 +1670,7 @@ mixedArr = [0, "a"]: [number(mm)]
let err = result.unwrap_err();
assert!(
err.to_string()
.contains("could not coerce [any; 2] value to type [number(mm)]"),
.contains("could not coerce value of type array of number(default units), string with 2 values to type [number(mm)]"),
"Expected error but found {err:?}"
);
}

View File

@ -606,6 +606,7 @@ fn type_check_params_kw(
.value
.coerce(
&RuntimeType::from_parsed(ty.clone(), exec_state, arg.source_range).map_err(|e| KclError::Semantic(e.into()))?,
true,
exec_state,
)
.map_err(|e| {
@ -680,6 +681,7 @@ fn type_check_params_kw(
.coerce(
&RuntimeType::from_parsed(ty.clone(), exec_state, arg.1.source_range)
.map_err(|e| KclError::Semantic(e.into()))?,
true,
exec_state,
)
.map_err(|_| {
@ -797,7 +799,7 @@ fn coerce_result_type(
if let RuntimeType::Array(inner, ArrayLen::NonEmpty) = &ty {
ty = RuntimeType::Union(vec![(**inner).clone(), ty]);
}
let val = val.coerce(&ty, exec_state).map_err(|_| {
let val = val.coerce(&ty, true, exec_state).map_err(|_| {
KclError::Semantic(KclErrorDetails::new(
format!(
"This function requires its result to be of type `{}`, but found {}",

View File

@ -281,8 +281,34 @@ impl KclValue {
/// Human readable type name used in error messages. Should not be relied
/// on for program logic.
pub(crate) fn human_friendly_type(&self) -> String {
if let Some(t) = self.principal_type() {
return t.to_string();
self.inner_human_friendly_type(1)
}
fn inner_human_friendly_type(&self, max_depth: usize) -> String {
if let Some(pt) = self.principal_type() {
if max_depth > 0 {
// The principal type of an array uses the array's element type,
// which is oftentimes `any`, and that's not a helpful message. So
// we show the actual elements.
if let Some(elements) = self.as_array() {
// If it's empty, we want to show the type of the array.
if !elements.is_empty() {
// A max of 3 is good because it's common to use 3D points.
let max = 3;
let len = elements.len();
let ellipsis = if len > max { ", ..." } else { "" };
let element_label = if len == 1 { "value" } else { "values" };
let element_tys = elements
.iter()
.take(max)
.map(|elem| elem.inner_human_friendly_type(max_depth - 1))
.collect::<Vec<_>>()
.join(", ");
return format!("array of {element_tys}{ellipsis} with {len} {element_label}");
}
}
}
return pt.to_string();
}
match self {
KclValue::Uuid { .. } => "Unique ID (uuid)",
@ -644,3 +670,88 @@ impl From<GeometryWithImportedGeometry> for KclValue {
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_human_friendly_type() {
let len = KclValue::Number {
value: 1.0,
ty: NumericType::Known(UnitType::Length(UnitLen::Unknown)),
meta: vec![],
};
assert_eq!(len.human_friendly_type(), "number(Length)".to_string());
let unknown = KclValue::Number {
value: 1.0,
ty: NumericType::Unknown,
meta: vec![],
};
assert_eq!(unknown.human_friendly_type(), "number(unknown units)".to_string());
let mm = KclValue::Number {
value: 1.0,
ty: NumericType::Known(UnitType::Length(UnitLen::Mm)),
meta: vec![],
};
assert_eq!(mm.human_friendly_type(), "number(mm)".to_string());
let array1_mm = KclValue::HomArray {
value: vec![mm.clone()],
ty: RuntimeType::any(),
};
assert_eq!(
array1_mm.human_friendly_type(),
"array of number(mm) with 1 value".to_string()
);
let array2_mm = KclValue::HomArray {
value: vec![mm.clone(), mm.clone()],
ty: RuntimeType::any(),
};
assert_eq!(
array2_mm.human_friendly_type(),
"array of number(mm), number(mm) with 2 values".to_string()
);
let array3_mm = KclValue::HomArray {
value: vec![mm.clone(), mm.clone(), mm.clone()],
ty: RuntimeType::any(),
};
assert_eq!(
array3_mm.human_friendly_type(),
"array of number(mm), number(mm), number(mm) with 3 values".to_string()
);
let inches = KclValue::Number {
value: 1.0,
ty: NumericType::Known(UnitType::Length(UnitLen::Inches)),
meta: vec![],
};
let array4 = KclValue::HomArray {
value: vec![mm.clone(), mm.clone(), inches.clone(), mm.clone()],
ty: RuntimeType::any(),
};
assert_eq!(
array4.human_friendly_type(),
"array of number(mm), number(mm), number(in), ... with 4 values".to_string()
);
let empty_array = KclValue::HomArray {
value: vec![],
ty: RuntimeType::any(),
};
assert_eq!(empty_array.human_friendly_type(), "[any; 0]".to_string());
let array_nested = KclValue::HomArray {
value: vec![array2_mm.clone()],
ty: RuntimeType::any(),
};
assert_eq!(
array_nested.human_friendly_type(),
"array of [any; 2] with 1 value".to_string()
);
}
}

View File

@ -1044,6 +1044,7 @@ impl ExecutorContext {
let root_imports = crate::walk::import_universe(
self,
&ModulePath::Main,
&ModuleRepr::Kcl(program.ast.clone(), None),
&mut universe,
exec_state,
@ -1211,15 +1212,10 @@ impl ExecutorContext {
/// SAFETY: the current thread must have sole access to the memory referenced in exec_state.
async fn eval_prelude(&self, exec_state: &mut ExecState, source_range: SourceRange) -> Result<(), KclError> {
if exec_state.stack().memory.requires_std() {
let path = vec!["std".to_owned(), "prelude".to_owned()];
let resolved_path = ModulePath::from_std_import_path(&path)?;
let id = self
.open_module(
&ImportPath::Std {
path: vec!["std".to_owned(), "prelude".to_owned()],
},
&[],
exec_state,
source_range,
)
.open_module(&ImportPath::Std { path }, &[], &resolved_path, exec_state, source_range)
.await?;
let (module_memory, _) = self.exec_module_for_items(id, exec_state, source_range).await?;

View File

@ -85,14 +85,14 @@ pub(super) struct ModuleState {
/// Settings specified from annotations.
pub settings: MetaSettings,
pub(super) explicit_length_units: bool,
pub(super) std_path: Option<String>,
pub(super) path: ModulePath,
}
impl ExecState {
pub fn new(exec_context: &super::ExecutorContext) -> Self {
ExecState {
global: GlobalState::new(&exec_context.settings),
mod_local: ModuleState::new(None, ProgramMemory::new(), Default::default()),
mod_local: ModuleState::new(ModulePath::Main, ProgramMemory::new(), Default::default()),
exec_context: Some(exec_context.clone()),
}
}
@ -102,7 +102,7 @@ impl ExecState {
*self = ExecState {
global,
mod_local: ModuleState::new(None, ProgramMemory::new(), Default::default()),
mod_local: ModuleState::new(self.mod_local.path.clone(), ProgramMemory::new(), Default::default()),
exec_context: Some(exec_context.clone()),
};
}
@ -337,14 +337,14 @@ impl GlobalState {
}
impl ModuleState {
pub(super) fn new(std_path: Option<String>, memory: Arc<ProgramMemory>, module_id: Option<ModuleId>) -> Self {
pub(super) fn new(path: ModulePath, memory: Arc<ProgramMemory>, module_id: Option<ModuleId>) -> Self {
ModuleState {
id_generator: IdGenerator::new(module_id),
stack: memory.new_stack(),
pipe_value: Default::default(),
module_exports: Default::default(),
explicit_length_units: false,
std_path,
path,
settings: MetaSettings {
default_length_units: Default::default(),
default_angle_units: Default::default(),

View File

@ -35,31 +35,28 @@ impl Default for TypedPath {
impl From<&String> for TypedPath {
fn from(path: &String) -> Self {
#[cfg(target_arch = "wasm32")]
{
TypedPath(typed_path::TypedPath::derive(path).to_path_buf())
}
#[cfg(not(target_arch = "wasm32"))]
{
TypedPath(std::path::PathBuf::from(path))
}
TypedPath::new(path)
}
}
impl From<&str> for TypedPath {
fn from(path: &str) -> Self {
TypedPath::new(path)
}
}
impl TypedPath {
pub fn new(path: &str) -> Self {
#[cfg(target_arch = "wasm32")]
{
TypedPath(typed_path::TypedPath::derive(path).to_path_buf())
}
#[cfg(not(target_arch = "wasm32"))]
{
TypedPath(std::path::PathBuf::from(path))
TypedPath(normalise_import(path))
}
}
}
impl TypedPath {
pub fn extension(&self) -> Option<&str> {
#[cfg(target_arch = "wasm32")]
{
@ -85,6 +82,17 @@ impl TypedPath {
}
}
pub fn join_typed(&self, path: &TypedPath) -> Self {
#[cfg(target_arch = "wasm32")]
{
TypedPath(self.0.join(path.0.to_path()))
}
#[cfg(not(target_arch = "wasm32"))]
{
TypedPath(self.0.join(&path.0))
}
}
pub fn parent(&self) -> Option<Self> {
#[cfg(target_arch = "wasm32")]
{
@ -206,3 +214,19 @@ impl schemars::JsonSchema for TypedPath {
gen.subschema_for::<std::path::PathBuf>()
}
}
/// Turn `nested\foo\bar\main.kcl` or `nested/foo/bar/main.kcl`
/// into a PathBuf that works on the host OS.
///
/// * Does **not** touch `..` or symlinks call `canonicalize()` if you need that.
/// * Returns an owned `PathBuf` only when normalisation was required.
fn normalise_import<S: AsRef<str>>(raw: S) -> std::path::PathBuf {
let s = raw.as_ref();
// On Unix we need to swap `\` → `/`. On Windows we leave it alone.
// (Windows happily consumes `/`)
if cfg!(unix) && s.contains('\\') {
std::path::PathBuf::from(s.replace('\\', "/"))
} else {
std::path::Path::new(s).to_path_buf()
}
}

View File

@ -1039,19 +1039,25 @@ impl KclValue {
/// - result.principal_type().unwrap().subtype(ty)
///
/// If self.principal_type() == ty then result == self
pub fn coerce(&self, ty: &RuntimeType, exec_state: &mut ExecState) -> Result<KclValue, CoercionError> {
pub fn coerce(
&self,
ty: &RuntimeType,
convert_units: bool,
exec_state: &mut ExecState,
) -> Result<KclValue, CoercionError> {
match ty {
RuntimeType::Primitive(ty) => self.coerce_to_primitive_type(ty, exec_state),
RuntimeType::Array(ty, len) => self.coerce_to_array_type(ty, *len, exec_state, false),
RuntimeType::Tuple(tys) => self.coerce_to_tuple_type(tys, exec_state),
RuntimeType::Union(tys) => self.coerce_to_union_type(tys, exec_state),
RuntimeType::Object(tys) => self.coerce_to_object_type(tys, exec_state),
RuntimeType::Primitive(ty) => self.coerce_to_primitive_type(ty, convert_units, exec_state),
RuntimeType::Array(ty, len) => self.coerce_to_array_type(ty, convert_units, *len, exec_state, false),
RuntimeType::Tuple(tys) => self.coerce_to_tuple_type(tys, convert_units, exec_state),
RuntimeType::Union(tys) => self.coerce_to_union_type(tys, convert_units, exec_state),
RuntimeType::Object(tys) => self.coerce_to_object_type(tys, convert_units, exec_state),
}
}
fn coerce_to_primitive_type(
&self,
ty: &PrimitiveType,
convert_units: bool,
exec_state: &mut ExecState,
) -> Result<KclValue, CoercionError> {
let value = match self {
@ -1060,7 +1066,29 @@ impl KclValue {
};
match ty {
PrimitiveType::Any => Ok(value.clone()),
PrimitiveType::Number(ty) => ty.coerce(value),
PrimitiveType::Number(ty) => {
if convert_units {
return ty.coerce(value);
}
// Instead of converting units, reinterpret the number as having
// different units.
//
// If the user is explicitly specifying units, treat the value
// as having had its units erased, rather than forcing the user
// to explicitly erase them.
if let KclValue::Number { value: n, meta, .. } = &value {
if ty.is_fully_specified() {
let value = KclValue::Number {
ty: NumericType::Any,
value: *n,
meta: meta.clone(),
};
return ty.coerce(&value);
}
}
ty.coerce(value)
}
PrimitiveType::String => match value {
KclValue::String { .. } => Ok(value.clone()),
_ => Err(self.into()),
@ -1153,10 +1181,22 @@ impl KclValue {
}
let origin = values.get("origin").ok_or(self.into()).and_then(|p| {
p.coerce_to_array_type(&RuntimeType::length(), ArrayLen::Known(2), exec_state, true)
p.coerce_to_array_type(
&RuntimeType::length(),
convert_units,
ArrayLen::Known(2),
exec_state,
true,
)
})?;
let direction = values.get("direction").ok_or(self.into()).and_then(|p| {
p.coerce_to_array_type(&RuntimeType::length(), ArrayLen::Known(2), exec_state, true)
p.coerce_to_array_type(
&RuntimeType::length(),
convert_units,
ArrayLen::Known(2),
exec_state,
true,
)
})?;
Ok(KclValue::Object {
@ -1181,10 +1221,22 @@ impl KclValue {
}
let origin = values.get("origin").ok_or(self.into()).and_then(|p| {
p.coerce_to_array_type(&RuntimeType::length(), ArrayLen::Known(3), exec_state, true)
p.coerce_to_array_type(
&RuntimeType::length(),
convert_units,
ArrayLen::Known(3),
exec_state,
true,
)
})?;
let direction = values.get("direction").ok_or(self.into()).and_then(|p| {
p.coerce_to_array_type(&RuntimeType::length(), ArrayLen::Known(3), exec_state, true)
p.coerce_to_array_type(
&RuntimeType::length(),
convert_units,
ArrayLen::Known(3),
exec_state,
true,
)
})?;
Ok(KclValue::Object {
@ -1221,6 +1273,7 @@ impl KclValue {
fn coerce_to_array_type(
&self,
ty: &RuntimeType,
convert_units: bool,
len: ArrayLen,
exec_state: &mut ExecState,
allow_shrink: bool,
@ -1249,7 +1302,7 @@ impl KclValue {
let value_result = value
.iter()
.take(satisfied_len)
.map(|v| v.coerce(ty, exec_state))
.map(|v| v.coerce(ty, convert_units, exec_state))
.collect::<Result<Vec<_>, _>>();
if let Ok(value) = value_result {
@ -1264,10 +1317,10 @@ impl KclValue {
if let KclValue::HomArray { value: inner_value, .. } = item {
// Flatten elements.
for item in inner_value {
values.push(item.coerce(ty, exec_state)?);
values.push(item.coerce(ty, convert_units, exec_state)?);
}
} else {
values.push(item.coerce(ty, exec_state)?);
values.push(item.coerce(ty, convert_units, exec_state)?);
}
}
@ -1297,7 +1350,7 @@ impl KclValue {
.ok_or(CoercionError::from(self))?;
let value = value
.iter()
.map(|item| item.coerce(ty, exec_state))
.map(|item| item.coerce(ty, convert_units, exec_state))
.take(len)
.collect::<Result<Vec<_>, _>>()?;
@ -1308,19 +1361,24 @@ impl KclValue {
ty: ty.clone(),
}),
_ if len.satisfied(1, false).is_some() => Ok(KclValue::HomArray {
value: vec![self.coerce(ty, exec_state)?],
value: vec![self.coerce(ty, convert_units, exec_state)?],
ty: ty.clone(),
}),
_ => Err(self.into()),
}
}
fn coerce_to_tuple_type(&self, tys: &[RuntimeType], exec_state: &mut ExecState) -> Result<KclValue, CoercionError> {
fn coerce_to_tuple_type(
&self,
tys: &[RuntimeType],
convert_units: bool,
exec_state: &mut ExecState,
) -> Result<KclValue, CoercionError> {
match self {
KclValue::Tuple { value, .. } | KclValue::HomArray { value, .. } if value.len() == tys.len() => {
let mut result = Vec::new();
for (i, t) in tys.iter().enumerate() {
result.push(value[i].coerce(t, exec_state)?);
result.push(value[i].coerce(t, convert_units, exec_state)?);
}
Ok(KclValue::Tuple {
@ -1340,9 +1398,14 @@ impl KclValue {
}
}
fn coerce_to_union_type(&self, tys: &[RuntimeType], exec_state: &mut ExecState) -> Result<KclValue, CoercionError> {
fn coerce_to_union_type(
&self,
tys: &[RuntimeType],
convert_units: bool,
exec_state: &mut ExecState,
) -> Result<KclValue, CoercionError> {
for t in tys {
if let Ok(v) = self.coerce(t, exec_state) {
if let Ok(v) = self.coerce(t, convert_units, exec_state) {
return Ok(v);
}
}
@ -1353,6 +1416,7 @@ impl KclValue {
fn coerce_to_object_type(
&self,
tys: &[(String, RuntimeType)],
_convert_units: bool,
_exec_state: &mut ExecState,
) -> Result<KclValue, CoercionError> {
match self {
@ -1461,7 +1525,7 @@ mod test {
exec_state: &mut ExecState,
) {
let is_subtype = value == expected_value;
assert_eq!(&value.coerce(super_type, exec_state).unwrap(), expected_value);
assert_eq!(&value.coerce(super_type, true, exec_state).unwrap(), expected_value);
assert_eq!(
is_subtype,
value.principal_type().is_some() && value.principal_type().unwrap().subtype(super_type),
@ -1509,10 +1573,10 @@ mod test {
);
// Coercing an empty tuple or array to an array of length 1
// should fail.
v.coerce(&aty1, &mut exec_state).unwrap_err();
v.coerce(&aty1, true, &mut exec_state).unwrap_err();
// Coercing an empty tuple or array to an array that's
// non-empty should fail.
v.coerce(&aty0, &mut exec_state).unwrap_err();
v.coerce(&aty0, true, &mut exec_state).unwrap_err();
}
_ => {
assert_coerce_results(
@ -1560,7 +1624,7 @@ mod test {
for v in &values[1..] {
// Not a subtype
v.coerce(&RuntimeType::Primitive(PrimitiveType::Boolean), &mut exec_state)
v.coerce(&RuntimeType::Primitive(PrimitiveType::Boolean), true, &mut exec_state)
.unwrap_err();
}
}
@ -1595,8 +1659,8 @@ mod test {
},
&mut exec_state,
);
none.coerce(&aty1, &mut exec_state).unwrap_err();
none.coerce(&aty1p, &mut exec_state).unwrap_err();
none.coerce(&aty1, true, &mut exec_state).unwrap_err();
none.coerce(&aty1p, true, &mut exec_state).unwrap_err();
let tty = RuntimeType::Tuple(vec![]);
let tty1 = RuntimeType::Tuple(vec![RuntimeType::solid()]);
@ -1609,7 +1673,7 @@ mod test {
},
&mut exec_state,
);
none.coerce(&tty1, &mut exec_state).unwrap_err();
none.coerce(&tty1, true, &mut exec_state).unwrap_err();
let oty = RuntimeType::Object(vec![]);
assert_coerce_results(
@ -1678,7 +1742,7 @@ mod test {
assert_coerce_results(&obj2, &ty0, &obj2, &mut exec_state);
let ty1 = RuntimeType::Object(vec![("foo".to_owned(), RuntimeType::Primitive(PrimitiveType::Boolean))]);
obj0.coerce(&ty1, &mut exec_state).unwrap_err();
obj0.coerce(&ty1, true, &mut exec_state).unwrap_err();
assert_coerce_results(&obj1, &ty1, &obj1, &mut exec_state);
assert_coerce_results(&obj2, &ty1, &obj2, &mut exec_state);
@ -1690,19 +1754,19 @@ mod test {
),
("foo".to_owned(), RuntimeType::Primitive(PrimitiveType::Boolean)),
]);
obj0.coerce(&ty2, &mut exec_state).unwrap_err();
obj1.coerce(&ty2, &mut exec_state).unwrap_err();
obj0.coerce(&ty2, true, &mut exec_state).unwrap_err();
obj1.coerce(&ty2, true, &mut exec_state).unwrap_err();
assert_coerce_results(&obj2, &ty2, &obj2, &mut exec_state);
// field not present
let tyq = RuntimeType::Object(vec![("qux".to_owned(), RuntimeType::Primitive(PrimitiveType::Boolean))]);
obj0.coerce(&tyq, &mut exec_state).unwrap_err();
obj1.coerce(&tyq, &mut exec_state).unwrap_err();
obj2.coerce(&tyq, &mut exec_state).unwrap_err();
obj0.coerce(&tyq, true, &mut exec_state).unwrap_err();
obj1.coerce(&tyq, true, &mut exec_state).unwrap_err();
obj2.coerce(&tyq, true, &mut exec_state).unwrap_err();
// field with different type
let ty1 = RuntimeType::Object(vec![("bar".to_owned(), RuntimeType::Primitive(PrimitiveType::Boolean))]);
obj2.coerce(&ty1, &mut exec_state).unwrap_err();
obj2.coerce(&ty1, true, &mut exec_state).unwrap_err();
}
#[tokio::test(flavor = "multi_thread")]
@ -1780,8 +1844,8 @@ mod test {
assert_coerce_results(&hom_arr, &tyh, &hom_arr, &mut exec_state);
assert_coerce_results(&mixed1, &tym1, &mixed1, &mut exec_state);
assert_coerce_results(&mixed2, &tym2, &mixed2, &mut exec_state);
mixed1.coerce(&tym2, &mut exec_state).unwrap_err();
mixed2.coerce(&tym1, &mut exec_state).unwrap_err();
mixed1.coerce(&tym2, true, &mut exec_state).unwrap_err();
mixed2.coerce(&tym1, true, &mut exec_state).unwrap_err();
// Length subtyping
let tyhn = RuntimeType::Array(
@ -1798,15 +1862,15 @@ mod test {
);
assert_coerce_results(&hom_arr, &tyhn, &hom_arr, &mut exec_state);
assert_coerce_results(&hom_arr, &tyh1, &hom_arr, &mut exec_state);
hom_arr.coerce(&tyh3, &mut exec_state).unwrap_err();
hom_arr.coerce(&tyh3, true, &mut exec_state).unwrap_err();
let hom_arr0 = KclValue::HomArray {
value: vec![],
ty: RuntimeType::Primitive(PrimitiveType::Number(NumericType::count())),
};
assert_coerce_results(&hom_arr0, &tyhn, &hom_arr0, &mut exec_state);
hom_arr0.coerce(&tyh1, &mut exec_state).unwrap_err();
hom_arr0.coerce(&tyh3, &mut exec_state).unwrap_err();
hom_arr0.coerce(&tyh1, true, &mut exec_state).unwrap_err();
hom_arr0.coerce(&tyh3, true, &mut exec_state).unwrap_err();
// Covariance
// let tyh = RuntimeType::Array(Box::new(RuntimeType::Primitive(PrimitiveType::Number(NumericType::Any))), ArrayLen::Known(4));
@ -1846,16 +1910,16 @@ mod test {
assert_coerce_results(&mixed1, &tyhn, &hom_arr_2, &mut exec_state);
assert_coerce_results(&mixed1, &tyh1, &hom_arr_2, &mut exec_state);
assert_coerce_results(&mixed0, &tyhn, &hom_arr0, &mut exec_state);
mixed0.coerce(&tyh, &mut exec_state).unwrap_err();
mixed0.coerce(&tyh1, &mut exec_state).unwrap_err();
mixed0.coerce(&tyh, true, &mut exec_state).unwrap_err();
mixed0.coerce(&tyh1, true, &mut exec_state).unwrap_err();
// Homogehous to mixed
assert_coerce_results(&hom_arr_2, &tym1, &mixed1, &mut exec_state);
hom_arr.coerce(&tym1, &mut exec_state).unwrap_err();
hom_arr_2.coerce(&tym2, &mut exec_state).unwrap_err();
hom_arr.coerce(&tym1, true, &mut exec_state).unwrap_err();
hom_arr_2.coerce(&tym2, true, &mut exec_state).unwrap_err();
mixed0.coerce(&tym1, &mut exec_state).unwrap_err();
mixed0.coerce(&tym2, &mut exec_state).unwrap_err();
mixed0.coerce(&tym1, true, &mut exec_state).unwrap_err();
mixed0.coerce(&tym2, true, &mut exec_state).unwrap_err();
}
#[tokio::test(flavor = "multi_thread")]
@ -1905,8 +1969,8 @@ mod test {
RuntimeType::Primitive(PrimitiveType::Boolean),
RuntimeType::Primitive(PrimitiveType::String),
]);
count.coerce(&tyb, &mut exec_state).unwrap_err();
count.coerce(&tyb2, &mut exec_state).unwrap_err();
count.coerce(&tyb, true, &mut exec_state).unwrap_err();
count.coerce(&tyb2, true, &mut exec_state).unwrap_err();
}
#[tokio::test(flavor = "multi_thread")]
@ -2021,7 +2085,7 @@ mod test {
assert_coerce_results(&a2d, &ty2d, &a2d, &mut exec_state);
assert_coerce_results(&a3d, &ty3d, &a3d, &mut exec_state);
assert_coerce_results(&a3d, &ty2d, &a2d, &mut exec_state);
a2d.coerce(&ty3d, &mut exec_state).unwrap_err();
a2d.coerce(&ty3d, true, &mut exec_state).unwrap_err();
}
#[tokio::test(flavor = "multi_thread")]
@ -2084,6 +2148,7 @@ mod test {
angle: UnitAngle::default()
}
.into(),
true,
&mut exec_state
)
.unwrap(),
@ -2091,22 +2156,30 @@ mod test {
);
// No coercion
count.coerce(&NumericType::mm().into(), &mut exec_state).unwrap_err();
mm.coerce(&NumericType::count().into(), &mut exec_state).unwrap_err();
unknown.coerce(&NumericType::mm().into(), &mut exec_state).unwrap_err();
count
.coerce(&NumericType::mm().into(), true, &mut exec_state)
.unwrap_err();
mm.coerce(&NumericType::count().into(), true, &mut exec_state)
.unwrap_err();
unknown
.coerce(&NumericType::default().into(), &mut exec_state)
.coerce(&NumericType::mm().into(), true, &mut exec_state)
.unwrap_err();
unknown
.coerce(&NumericType::default().into(), true, &mut exec_state)
.unwrap_err();
count.coerce(&NumericType::Unknown.into(), &mut exec_state).unwrap_err();
mm.coerce(&NumericType::Unknown.into(), &mut exec_state).unwrap_err();
count
.coerce(&NumericType::Unknown.into(), true, &mut exec_state)
.unwrap_err();
mm.coerce(&NumericType::Unknown.into(), true, &mut exec_state)
.unwrap_err();
default
.coerce(&NumericType::Unknown.into(), &mut exec_state)
.coerce(&NumericType::Unknown.into(), true, &mut exec_state)
.unwrap_err();
assert_eq!(
inches
.coerce(&NumericType::mm().into(), &mut exec_state)
.coerce(&NumericType::mm().into(), true, &mut exec_state)
.unwrap()
.as_f64()
.unwrap()
@ -2116,6 +2189,7 @@ mod test {
assert_eq!(
rads.coerce(
&NumericType::Known(UnitType::Angle(UnitAngle::Degrees)).into(),
true,
&mut exec_state
)
.unwrap()
@ -2126,7 +2200,7 @@ mod test {
);
assert_eq!(
inches
.coerce(&NumericType::default().into(), &mut exec_state)
.coerce(&NumericType::default().into(), true, &mut exec_state)
.unwrap()
.as_f64()
.unwrap()
@ -2134,7 +2208,7 @@ mod test {
1.0
);
assert_eq!(
rads.coerce(&NumericType::default().into(), &mut exec_state)
rads.coerce(&NumericType::default().into(), true, &mut exec_state)
.unwrap()
.as_f64()
.unwrap()

View File

@ -1189,6 +1189,7 @@ impl LanguageServer for Backend {
}
async fn completion(&self, params: CompletionParams) -> RpcResult<Option<CompletionResponse>> {
// ADAM: This is the entrypoint.
let mut completions = vec![CompletionItem {
label: PIPE_OPERATOR.to_string(),
label_details: None,
@ -1686,31 +1687,29 @@ pub fn get_arg_maps_from_stdlib(
let combined = stdlib.combined();
for internal_fn in combined.values() {
if internal_fn.keyword_arguments() {
let arg_map: HashMap<String, String> = internal_fn
.args(false)
.into_iter()
.map(|data| {
let mut tip = "```\n".to_owned();
tip.push_str(&data.name.clone());
if !data.required {
tip.push('?');
}
if !data.type_.is_empty() {
tip.push_str(": ");
tip.push_str(&data.type_);
}
tip.push_str("\n```");
if !data.description.is_empty() {
tip.push_str("\n\n");
tip.push_str(&data.description);
}
(data.name, tip)
})
.collect();
if !arg_map.is_empty() {
result.insert(internal_fn.name(), arg_map);
}
let arg_map: HashMap<String, String> = internal_fn
.args(false)
.into_iter()
.map(|data| {
let mut tip = "```\n".to_owned();
tip.push_str(&data.name.clone());
if !data.required {
tip.push('?');
}
if !data.type_.is_empty() {
tip.push_str(": ");
tip.push_str(&data.type_);
}
tip.push_str("\n```");
if !data.description.is_empty() {
tip.push_str("\n\n");
tip.push_str(&data.description);
}
(data.name, tip)
})
.collect();
if !arg_map.is_empty() {
result.insert(internal_fn.name(), arg_map);
}
}

View File

@ -97,6 +97,7 @@ pub(crate) fn read_std(mod_name: &str) -> Option<&'static str> {
"units" => Some(include_str!("../std/units.kcl")),
"array" => Some(include_str!("../std/array.kcl")),
"sweep" => Some(include_str!("../std/sweep.kcl")),
"appearance" => Some(include_str!("../std/appearance.kcl")),
"transform" => Some(include_str!("../std/transform.kcl")),
_ => None,
}
@ -153,13 +154,6 @@ impl ModulePath {
}
}
pub(crate) fn std_path(&self) -> Option<String> {
match self {
ModulePath::Std { value: p } => Some(p.clone()),
_ => None,
}
}
pub(crate) async fn source(&self, fs: &FileManager, source_range: SourceRange) -> Result<ModuleSource, KclError> {
match self {
ModulePath::Local { value: p } => Ok(ModuleSource {
@ -181,25 +175,53 @@ impl ModulePath {
}
}
pub(crate) fn from_import_path(path: &ImportPath, project_directory: &Option<TypedPath>) -> Self {
pub(crate) fn from_import_path(
path: &ImportPath,
project_directory: &Option<TypedPath>,
import_from: &ModulePath,
) -> Result<Self, KclError> {
match path {
ImportPath::Kcl { filename: path } | ImportPath::Foreign { path } => {
let resolved_path = if let Some(project_dir) = project_directory {
project_dir.join(path)
} else {
TypedPath::from(path)
let resolved_path = match import_from {
ModulePath::Main => {
if let Some(project_dir) = project_directory {
project_dir.join_typed(path)
} else {
path.clone()
}
}
ModulePath::Local { value } => {
let import_from_dir = value.parent();
let base = import_from_dir.as_ref().or(project_directory.as_ref());
if let Some(dir) = base {
dir.join_typed(path)
} else {
path.clone()
}
}
ModulePath::Std { .. } => {
let message = format!("Cannot import a non-std KCL file from std: {path}.");
debug_assert!(false, "{}", &message);
return Err(KclError::Internal(KclErrorDetails::new(message, vec![])));
}
};
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 { value: path[1].clone() }
Ok(ModulePath::Local { value: resolved_path })
}
ImportPath::Std { path } => Self::from_std_import_path(path),
}
}
pub(crate) fn from_std_import_path(path: &[String]) -> Result<Self, KclError> {
// For now we only support importing from singly-nested modules inside std.
if path.len() != 2 || path[0] != "std" {
let message = format!("Invalid std import path: {path:?}.");
debug_assert!(false, "{}", &message);
return Err(KclError::Internal(KclErrorDetails::new(message, vec![])));
}
Ok(ModulePath::Std { value: path[1].clone() })
}
}
impl fmt::Display for ModulePath {

View File

@ -34,7 +34,7 @@ use crate::{
},
parsing::{ast::digest::Digest, token::NumericSuffix, PIPE_OPERATOR},
source_range::SourceRange,
ModuleId,
ModuleId, TypedPath,
};
mod condition;
@ -1741,8 +1741,8 @@ impl ImportSelector {
#[ts(export)]
#[serde(tag = "type")]
pub enum ImportPath {
Kcl { filename: String },
Foreign { path: String },
Kcl { filename: TypedPath },
Foreign { path: TypedPath },
Std { path: Vec<String> },
}
@ -1811,16 +1811,25 @@ impl ImportStatement {
match &self.path {
ImportPath::Kcl { filename: s } | ImportPath::Foreign { path: s } => {
let mut parts = s.split('.');
let path = parts.next()?;
let _ext = parts.next()?;
let rest = parts.next();
let name = s.to_string_lossy();
if name.ends_with("/main.kcl") || name.ends_with("\\main.kcl") {
let name = &name[..name.len() - 9];
let start = name.rfind(['/', '\\']).map(|s| s + 1).unwrap_or(0);
return Some(name[start..].to_owned());
}
if rest.is_some() {
let name = s.file_name().map(|f| f.to_string())?;
if name.contains('\\') || name.contains('/') {
return None;
}
path.rsplit(&['/', '\\']).next().map(str::to_owned)
// Remove the extension if it exists.
let extension = s.extension();
Some(if let Some(extension) = extension {
name.trim_end_matches(extension).trim_end_matches('.').to_string()
} else {
name
})
}
ImportPath::Std { path } => path.last().cloned(),
}
@ -4332,4 +4341,20 @@ startSketchOn(XY)
"#
);
}
#[test]
fn module_name() {
#[track_caller]
fn assert_mod_name(stmt: &str, name: &str) {
let tokens = crate::parsing::token::lex(stmt, ModuleId::default()).unwrap();
let stmt = crate::parsing::parser::import_stmt(&mut tokens.as_slice()).unwrap();
assert_eq!(stmt.module_name().unwrap(), name);
}
assert_mod_name("import 'foo.kcl'", "foo");
assert_mod_name("import 'foo.kcl' as bar", "bar");
assert_mod_name("import 'main.kcl'", "main");
assert_mod_name("import 'foo/main.kcl'", "foo");
assert_mod_name("import 'foo\\bar\\main.kcl'", "bar");
}
}

View File

@ -35,7 +35,7 @@ use crate::{
token::{Token, TokenSlice, TokenType},
PIPE_OPERATOR, PIPE_SUBSTITUTION_OPERATOR,
},
SourceRange, IMPORT_FILE_EXTENSIONS,
SourceRange, TypedPath, IMPORT_FILE_EXTENSIONS,
};
thread_local! {
@ -886,7 +886,7 @@ fn array_end_start(i: &mut TokenSlice) -> PResult<Node<ArrayRangeExpression>> {
ignore_whitespace(i);
let start_element = expression.parse_next(i)?;
ignore_whitespace(i);
double_period.parse_next(i)?;
let end_inclusive = alt((end_inclusive_range.map(|_| true), end_exclusive_range.map(|_| false))).parse_next(i)?;
ignore_whitespace(i);
let end_element = expression.parse_next(i)?;
ignore_whitespace(i);
@ -895,7 +895,7 @@ fn array_end_start(i: &mut TokenSlice) -> PResult<Node<ArrayRangeExpression>> {
ArrayRangeExpression {
start_element,
end_element,
end_inclusive: true,
end_inclusive,
digest: None,
},
start,
@ -1729,7 +1729,7 @@ fn glob(i: &mut TokenSlice) -> PResult<Token> {
.parse_next(i)
}
fn import_stmt(i: &mut TokenSlice) -> PResult<BoxNode<ImportStatement>> {
pub(super) fn import_stmt(i: &mut TokenSlice) -> PResult<BoxNode<ImportStatement>> {
let (visibility, visibility_token) = opt(terminated(item_visibility, whitespace))
.parse_next(i)?
.map_or((ItemVisibility::Default, None), |pair| (pair.0, Some(pair.1)));
@ -1862,18 +1862,50 @@ fn validate_path_string(path_string: String, var_name: bool, path_range: SourceR
let path = if path_string.ends_with(".kcl") {
if path_string
.chars()
.any(|c| !c.is_ascii_alphanumeric() && c != '_' && c != '-' && c != '.')
.any(|c| !c.is_ascii_alphanumeric() && c != '_' && c != '-' && c != '.' && c != '/' && c != '\\')
{
return Err(ErrMode::Cut(
CompilationError::fatal(
path_range,
"import path may only contain alphanumeric characters, underscore, hyphen, and period. KCL files in other directories are not yet supported.",
"import path may only contain alphanumeric characters, `_`, `-`, `.`, `/`, and `\\`.",
)
.into(),
));
}
ImportPath::Kcl { filename: path_string }
if path_string.starts_with("..") {
return Err(ErrMode::Cut(
CompilationError::fatal(
path_range,
"import path may not start with '..'. Cannot traverse to something outside the bounds of your project. If this path is inside your project please find a better way to reference it.",
)
.into(),
));
}
// Make sure they are not using an absolute path.
if path_string.starts_with('/') || path_string.starts_with('\\') {
return Err(ErrMode::Cut(
CompilationError::fatal(
path_range,
"import path may not start with '/' or '\\'. Cannot traverse to something outside the bounds of your project. If this path is inside your project please find a better way to reference it.",
)
.into(),
));
}
if (path_string.contains('/') || path_string.contains('\\'))
&& !(path_string.ends_with("/main.kcl") || path_string.ends_with("\\main.kcl"))
{
return Err(ErrMode::Cut(
CompilationError::fatal(path_range, "import path to a subdirectory must only refer to main.kcl.")
.into(),
));
}
ImportPath::Kcl {
filename: TypedPath::new(&path_string),
}
} else if path_string.starts_with("std::") {
ParseContext::warn(CompilationError::err(
path_range,
@ -1910,7 +1942,9 @@ fn validate_path_string(path_string: String, var_name: bool, path_range: SourceR
format!("unsupported import path format. KCL files can be imported from the current project, CAD files with the following formats are supported: {}", IMPORT_FILE_EXTENSIONS.join(", ")),
))
}
ImportPath::Foreign { path: path_string }
ImportPath::Foreign {
path: TypedPath::new(&path_string),
}
} else {
return Err(ErrMode::Cut(
CompilationError::fatal(
@ -2671,7 +2705,7 @@ fn period(i: &mut TokenSlice) -> PResult<()> {
Ok(())
}
fn double_period(i: &mut TokenSlice) -> PResult<Token> {
fn end_inclusive_range(i: &mut TokenSlice) -> PResult<Token> {
any.try_map(|token: Token| {
if matches!(token.token_type, TokenType::DoublePeriod) {
Ok(token)
@ -2690,6 +2724,21 @@ fn double_period(i: &mut TokenSlice) -> PResult<Token> {
.parse_next(i)
}
fn end_exclusive_range(i: &mut TokenSlice) -> PResult<Token> {
any.try_map(|token: Token| {
if matches!(token.token_type, TokenType::DoublePeriodLessThan) {
Ok(token)
} else {
Err(CompilationError::fatal(
token.as_source_range(),
format!("expected a '..<' but found {}", token.value.as_str()),
))
}
})
.context(expected("the ..< operator, used for array ranges like [0..<10]"))
.parse_next(i)
}
fn colon(i: &mut TokenSlice) -> PResult<Token> {
TokenType::Colon.parse_from(i)
}
@ -4534,9 +4583,24 @@ e
fn bad_imports() {
assert_err(
r#"import cube from "../cube.kcl""#,
"import path may only contain alphanumeric characters, underscore, hyphen, and period. KCL files in other directories are not yet supported.",
"import path may not start with '..'. Cannot traverse to something outside the bounds of your project. If this path is inside your project please find a better way to reference it.",
[17, 30],
);
assert_err(
r#"import cube from "/cube.kcl""#,
"import path may not start with '/' or '\\'. Cannot traverse to something outside the bounds of your project. If this path is inside your project please find a better way to reference it.",
[17, 28],
);
assert_err(
r#"import cube from "C:\cube.kcl""#,
"import path may only contain alphanumeric characters, `_`, `-`, `.`, `/`, and `\\`.",
[17, 30],
);
assert_err(
r#"import cube from "cube/cube.kcl""#,
"import path to a subdirectory must only refer to main.kcl.",
[17, 32],
);
assert_err(
r#"import * as foo from "dsfs""#,
"as is not the 'from' keyword",
@ -5295,7 +5359,6 @@ mod snapshot_tests {
);
snapshot_test!(aa, r#"sg = -scale"#);
snapshot_test!(ab, "line(endAbsolute = [0, -1])");
snapshot_test!(ac, "myArray = [0..10]");
snapshot_test!(
ad,
r#"
@ -5436,6 +5499,11 @@ my14 = 4 ^ 2 - 3 ^ 2 * 2
)"#
);
snapshot_test!(kw_function_in_binary_op, r#"val = f(x = 1) + 1"#);
snapshot_test!(
array_ranges,
r#"incl = [1..10]
excl = [0..<10]"#
);
}
#[allow(unused)]

View File

@ -0,0 +1,117 @@
---
source: kcl-lib/src/parsing/parser.rs
expression: actual
---
{
"body": [
{
"commentStart": 0,
"declaration": {
"commentStart": 0,
"end": 14,
"id": {
"commentStart": 0,
"end": 4,
"name": "incl",
"start": 0,
"type": "Identifier"
},
"init": {
"commentStart": 7,
"end": 14,
"endElement": {
"commentStart": 11,
"end": 13,
"raw": "10",
"start": 11,
"type": "Literal",
"type": "Literal",
"value": {
"value": 10.0,
"suffix": "None"
}
},
"endInclusive": true,
"start": 7,
"startElement": {
"commentStart": 8,
"end": 9,
"raw": "1",
"start": 8,
"type": "Literal",
"type": "Literal",
"value": {
"value": 1.0,
"suffix": "None"
}
},
"type": "ArrayRangeExpression",
"type": "ArrayRangeExpression"
},
"start": 0,
"type": "VariableDeclarator"
},
"end": 14,
"kind": "const",
"start": 0,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"commentStart": 23,
"declaration": {
"commentStart": 23,
"end": 38,
"id": {
"commentStart": 23,
"end": 27,
"name": "excl",
"start": 23,
"type": "Identifier"
},
"init": {
"commentStart": 30,
"end": 38,
"endElement": {
"commentStart": 35,
"end": 37,
"raw": "10",
"start": 35,
"type": "Literal",
"type": "Literal",
"value": {
"value": 10.0,
"suffix": "None"
}
},
"endInclusive": false,
"start": 30,
"startElement": {
"commentStart": 31,
"end": 32,
"raw": "0",
"start": 31,
"type": "Literal",
"type": "Literal",
"value": {
"value": 0.0,
"suffix": "None"
}
},
"type": "ArrayRangeExpression",
"type": "ArrayRangeExpression"
},
"start": 23,
"type": "VariableDeclarator"
},
"end": 38,
"kind": "const",
"start": 23,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
}
],
"commentStart": 0,
"end": 38,
"start": 0
}

View File

@ -369,6 +369,8 @@ pub enum TokenType {
Period,
/// A double period: `..`.
DoublePeriod,
/// A double period and a less than: `..<`.
DoublePeriodLessThan,
/// A line comment.
LineComment,
/// A block comment.
@ -410,6 +412,7 @@ impl TryFrom<TokenType> for SemanticTokenType {
| TokenType::DoubleColon
| TokenType::Period
| TokenType::DoublePeriod
| TokenType::DoublePeriodLessThan
| TokenType::Hash
| TokenType::Dollar
| TokenType::At

View File

@ -87,7 +87,7 @@ pub(super) fn token(i: &mut Input<'_>) -> PResult<Token> {
'0'..='9' => number,
';' => semi_colon,
':' => alt((double_colon, colon)),
'.' => alt((number, double_period, period)),
'.' => alt((number, double_period_less_than, double_period, period)),
'#' => hash,
'$' => dollar,
'!' => alt((operator, bang)),
@ -320,6 +320,16 @@ fn double_period(i: &mut Input<'_>) -> PResult<Token> {
))
}
fn double_period_less_than(i: &mut Input<'_>) -> PResult<Token> {
let (value, range) = "..<".with_span().parse_next(i)?;
Ok(Token::from_range(
range,
i.state.module_id,
TokenType::DoublePeriodLessThan,
value.to_string(),
))
}
/// Zero or more of either:
/// 1. Any character except " or \
/// 2. Any character preceded by \

View File

@ -26,6 +26,10 @@ struct Test {
input_dir: PathBuf,
/// Expected snapshot output files are in this directory.
output_dir: PathBuf,
/// True to skip asserting the artifact graph and only write it. The default
/// is false and to assert it.
#[cfg_attr(not(feature = "artifact-graph"), expect(dead_code))]
skip_assert_artifact_graph: bool,
}
pub(crate) const RENDERED_MODEL_NAME: &str = "rendered_model.png";
@ -37,6 +41,7 @@ impl Test {
entry_point: Path::new("tests").join(name).join("input.kcl"),
input_dir: Path::new("tests").join(name),
output_dir: Path::new("tests").join(name),
skip_assert_artifact_graph: false,
}
}
@ -299,21 +304,28 @@ fn assert_common_snapshots(
})
}));
let result3 = catch_unwind(AssertUnwindSafe(|| {
assert_snapshot(test, "Artifact graph flowchart", || {
let mut artifact_graph = artifact_graph.clone();
// Sort the map by artifact where we can.
artifact_graph.sort();
// If the user is explicitly writing, we always want to run so that they
// can save new expected output. There's no way to reliably determine
// if insta will write, as far as I can tell, so we use our own
// environment variable.
let is_writing = matches!(std::env::var("ZOO_SIM_UPDATE").as_deref(), Ok("always"));
if !test.skip_assert_artifact_graph || is_writing {
assert_snapshot(test, "Artifact graph flowchart", || {
let mut artifact_graph = artifact_graph.clone();
// Sort the map by artifact where we can.
artifact_graph.sort();
let flowchart = artifact_graph
.to_mermaid_flowchart()
.unwrap_or_else(|e| format!("Failed to convert artifact graph to flowchart: {e}"));
// Change the snapshot suffix so that it is rendered as a Markdown file
// in GitHub.
// Ignore the cpu cooler for now because its being a little bitch.
if test.name != "cpu-cooler" {
insta::assert_binary_snapshot!("artifact_graph_flowchart.md", flowchart.as_bytes().to_owned());
}
})
let flowchart = artifact_graph
.to_mermaid_flowchart()
.unwrap_or_else(|e| format!("Failed to convert artifact graph to flowchart: {e}"));
// Change the snapshot suffix so that it is rendered as a Markdown file
// in GitHub.
// Ignore the cpu cooler for now because its being a little bitch.
if test.name != "cpu-cooler" && test.name != "subtract_regression10" {
insta::assert_binary_snapshot!("artifact_graph_flowchart.md", flowchart.as_bytes().to_owned());
}
})
}
}));
result1.unwrap();
@ -384,6 +396,27 @@ mod any_type {
super::execute(TEST_NAME, false).await
}
}
mod error_with_point_shows_numeric_units {
const TEST_NAME: &str = "error_with_point_shows_numeric_units";
/// Test parsing KCL.
#[test]
fn parse() {
super::parse(TEST_NAME)
}
/// Test that parsing and unparsing KCL produces the original KCL input.
#[tokio::test(flavor = "multi_thread")]
async fn unparse() {
super::unparse(TEST_NAME).await
}
/// Test that KCL is executed correctly.
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_execute() {
super::execute(TEST_NAME, true).await
}
}
mod artifact_graph_example_code1 {
const TEST_NAME: &str = "artifact_graph_example_code1";
@ -996,6 +1029,27 @@ mod import_cycle1 {
super::execute(TEST_NAME, false).await
}
}
mod import_only_at_top_level {
const TEST_NAME: &str = "import_only_at_top_level";
/// Test parsing KCL.
#[test]
fn parse() {
super::parse(TEST_NAME)
}
/// Test that parsing and unparsing KCL produces the original KCL input.
#[tokio::test(flavor = "multi_thread")]
async fn unparse() {
super::unparse(TEST_NAME).await
}
/// Test that KCL is executed correctly.
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_execute() {
super::execute(TEST_NAME, false).await
}
}
mod import_function_not_sketch {
const TEST_NAME: &str = "import_function_not_sketch";
@ -1164,6 +1218,27 @@ mod import_foreign {
super::execute(TEST_NAME, false).await
}
}
mod export_var_only_at_top_level {
const TEST_NAME: &str = "export_var_only_at_top_level";
/// Test parsing KCL.
#[test]
fn parse() {
super::parse(TEST_NAME)
}
/// Test that parsing and unparsing KCL produces the original KCL input.
#[tokio::test(flavor = "multi_thread")]
async fn unparse() {
super::unparse(TEST_NAME).await
}
/// Test that KCL is executed correctly.
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_execute() {
super::execute(TEST_NAME, false).await
}
}
mod assembly_non_default_units {
const TEST_NAME: &str = "assembly_non_default_units";
@ -3276,3 +3351,108 @@ mod subtract_regression10 {
super::execute(TEST_NAME, true).await
}
}
mod nested_main_kcl {
const TEST_NAME: &str = "nested_main_kcl";
/// Test parsing KCL.
#[test]
fn parse() {
super::parse(TEST_NAME)
}
/// Test that parsing and unparsing KCL produces the original KCL input.
#[tokio::test(flavor = "multi_thread")]
async fn unparse() {
super::unparse(TEST_NAME).await
}
/// Test that KCL is executed correctly.
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_execute() {
super::execute(TEST_NAME, true).await
}
}
mod nested_windows_main_kcl {
const TEST_NAME: &str = "nested_windows_main_kcl";
/// Test parsing KCL.
#[test]
fn parse() {
super::parse(TEST_NAME)
}
/// Test that parsing and unparsing KCL produces the original KCL input.
#[tokio::test(flavor = "multi_thread")]
async fn unparse() {
super::unparse(TEST_NAME).await
}
/// Test that KCL is executed correctly.
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_execute() {
super::execute(TEST_NAME, true).await
}
}
mod nested_assembly {
const TEST_NAME: &str = "nested_assembly";
/// Test parsing KCL.
#[test]
fn parse() {
super::parse(TEST_NAME)
}
/// Test that parsing and unparsing KCL produces the original KCL input.
#[tokio::test(flavor = "multi_thread")]
async fn unparse() {
super::unparse(TEST_NAME).await
}
/// Test that KCL is executed correctly.
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_execute() {
super::execute(TEST_NAME, true).await
}
}
mod subtract_regression11 {
const TEST_NAME: &str = "subtract_regression11";
/// Test parsing KCL.
#[test]
fn parse() {
super::parse(TEST_NAME)
}
/// Test that parsing and unparsing KCL produces the original KCL input.
#[tokio::test(flavor = "multi_thread")]
async fn unparse() {
super::unparse(TEST_NAME).await
}
/// Test that KCL is executed correctly.
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_execute() {
super::execute(TEST_NAME, true).await
}
}
mod subtract_regression12 {
const TEST_NAME: &str = "subtract_regression12";
/// Test parsing KCL.
#[test]
fn parse() {
super::parse(TEST_NAME)
}
/// Test that parsing and unparsing KCL produces the original KCL input.
#[tokio::test(flavor = "multi_thread")]
async fn unparse() {
super::unparse(TEST_NAME).await
}
/// Test that KCL is executed correctly.
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_execute() {
super::execute(TEST_NAME, true).await
}
}

View File

@ -145,6 +145,8 @@ fn test(test_name: &str, entry_point: std::path::PathBuf) -> Test {
entry_point: entry_point.clone(),
input_dir: parent.to_path_buf(),
output_dir: relative_output_dir,
// Skip is temporary while we have non-deterministic output.
skip_assert_artifact_graph: true,
}
}

View File

@ -10,7 +10,10 @@ use rgba_simple::Hex;
use super::args::TyF64;
use crate::{
errors::{KclError, KclErrorDetails},
execution::{types::RuntimeType, ExecState, KclValue, SolidOrImportedGeometry},
execution::{
types::{ArrayLen, RuntimeType},
ExecState, KclValue, SolidOrImportedGeometry,
},
std::Args,
};
@ -18,6 +21,34 @@ lazy_static::lazy_static! {
static ref HEX_REGEX: Regex = Regex::new(r"^#[0-9a-fA-F]{6}$").unwrap();
}
/// Construct a color from its red, blue and green components.
pub async fn hex_string(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let rgb: [TyF64; 3] = args.get_unlabeled_kw_arg_typed(
"rgb",
&RuntimeType::Array(Box::new(RuntimeType::count()), ArrayLen::Known(3)),
exec_state,
)?;
// Make sure the color if set is valid.
if let Some(component) = rgb.iter().find(|component| component.n < 0.0 || component.n > 255.0) {
return Err(KclError::Semantic(KclErrorDetails::new(
format!("Colors are given between 0 and 255, so {} is invalid", component.n),
vec![args.source_range],
)));
}
inner_hex_string(rgb, exec_state, args).await
}
async fn inner_hex_string(rgb: [TyF64; 3], _: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let [r, g, b] = rgb.map(|n| n.n.floor() as u32);
let s = format!("#{r:02x}{g:02x}{b:02x}");
Ok(KclValue::String {
value: s,
meta: args.into(),
})
}
/// Set the appearance of a solid. This only works on solids, not sketches or individual paths.
pub async fn appearance(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let solids = args.get_unlabeled_kw_arg_typed(
@ -260,7 +291,6 @@ pub async fn appearance(exec_state: &mut ExecState, args: Args) -> Result<KclVal
/// ```
#[stdlib {
name = "appearance",
keywords = true,
unlabeled_first = true,
args = {
solids = { docs = "The solid(s) whose appearance is being set" },

View File

@ -177,7 +177,7 @@ impl Args {
)));
};
let arg = arg.value.coerce(ty, exec_state).map_err(|_| {
let arg = arg.value.coerce(ty, true, exec_state).map_err(|_| {
let actual_type = arg.value.principal_type();
let actual_type_name = actual_type
.as_ref()
@ -297,7 +297,7 @@ impl Args {
vec![self.source_range],
)))?;
let arg = arg.value.coerce(ty, exec_state).map_err(|_| {
let arg = arg.value.coerce(ty, true, exec_state).map_err(|_| {
let actual_type = arg.value.principal_type();
let actual_type_name = actual_type
.as_ref()

View File

@ -49,7 +49,6 @@ pub async fn assert(_exec_state: &mut ExecState, args: Args) -> Result<KclValue,
/// ```
#[stdlib{
name = "assertIs",
keywords = true,
unlabeled_first = true,
args = {
actual = { docs = "Value to check. If this is the boolean value true, assert passes. Otherwise it fails." },
@ -75,7 +74,6 @@ async fn inner_assert_is(actual: bool, error: Option<String>, args: &Args) -> Re
/// ```
#[stdlib {
name = "assert",
keywords = true,
unlabeled_first = true,
args = {
actual = { docs = "Value to check. It will be compared with one of the comparison arguments." },

View File

@ -106,7 +106,6 @@ pub async fn union(exec_state: &mut ExecState, args: Args) -> Result<KclValue, K
#[stdlib {
name = "union",
feature_tree_operation = true,
keywords = true,
unlabeled_first = true,
args = {
solids = {docs = "The solids to union."},
@ -232,7 +231,6 @@ pub async fn intersect(exec_state: &mut ExecState, args: Args) -> Result<KclValu
#[stdlib {
name = "intersect",
feature_tree_operation = true,
keywords = true,
unlabeled_first = true,
args = {
solids = {docs = "The solids to intersect."},
@ -352,7 +350,6 @@ pub async fn subtract(exec_state: &mut ExecState, args: Args) -> Result<KclValue
#[stdlib {
name = "subtract",
feature_tree_operation = true,
keywords = true,
unlabeled_first = true,
args = {
solids = {docs = "The solids to use as the base to subtract from."},

View File

@ -53,7 +53,6 @@ pub async fn get_opposite_edge(exec_state: &mut ExecState, args: Args) -> Result
/// ```
#[stdlib {
name = "getOppositeEdge",
keywords = true,
unlabeled_first = true,
args = {
edge = { docs = "The tag of the edge you want to find the opposite edge of." },
@ -137,7 +136,6 @@ pub async fn get_next_adjacent_edge(exec_state: &mut ExecState, args: Args) -> R
/// ```
#[stdlib {
name = "getNextAdjacentEdge",
keywords = true,
unlabeled_first = true,
args = {
edge = { docs = "The tag of the edge you want to find the next adjacent edge of." },
@ -230,7 +228,6 @@ pub async fn get_previous_adjacent_edge(exec_state: &mut ExecState, args: Args)
/// ```
#[stdlib {
name = "getPreviousAdjacentEdge",
keywords = true,
unlabeled_first = true,
args = {
edge = { docs = "The tag of the edge you want to find the previous adjacent edge of." },
@ -318,7 +315,6 @@ pub async fn get_common_edge(exec_state: &mut ExecState, args: Args) -> Result<K
#[stdlib {
name = "getCommonEdge",
feature_tree_operation = false,
keywords = true,
unlabeled_first = false,
args = {
faces = { docs = "The tags of the faces you want to find the common edge between" },

Some files were not shown because too many files have changed in this diff Show More