Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KCL: Change core sketch functions to use keyword args #4826

Open
wants to merge 111 commits into
base: main
Choose a base branch
from

Conversation

adamchalmers
Copy link
Collaborator

@adamchalmers adamchalmers commented Dec 17, 2024

Changes to KCL stdlib:

  • line(point, sketch, tag) and lineTo(point, sketch, tag) are combined into line(@sketch, end?, endAbsolute?, tag?)
  • close(sketch, tag?) is now close(@sketch, tag?)
  • extrude(length, sketch) is now extrude(@sketch, length)
  • Update all the docs everywhere

Part of #4600

Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main

The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:

line(([^=]*), %)
line(end = $1)

line((.), %, (.))
line(end = $1, tag = $2)

lineTo((.*), %)
line(endAbsolute = $1)

lineTo((.), %, (.))
line(endAbsolute = $1, tag = $2)

extrude((.*), %)
extrude(length = $1)

extrude(([^=]*), ([a-zA-Z0-9]+))
extrude($2, length = $1)

close(%, (.*))
close(tag = $1)

@adamchalmers adamchalmers requested review from jtran and nrc December 17, 2024 01:44
Copy link

qa-wolf bot commented Dec 17, 2024

QA Wolf here! As you write new code it's important that your test coverage is keeping up.
Click here to request test coverage for this PR!

Copy link

vercel bot commented Dec 17, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
modeling-app ✅ Ready (Inspect) Visit Preview Jan 30, 2025 10:21pm

@jtran
Copy link
Collaborator

jtran commented Dec 17, 2024

I skimmed this and it looks great so far.

Does it maintain backward compatibility? If not, the UI needs to generate the new code.

@adamchalmers adamchalmers force-pushed the achalmers/kw-fn-sketches branch from cbf0abb to 95b6476 Compare January 29, 2025 21:45
Copy link
Contributor

src/lib/exampleKcl.ts has been updated in this PR, please review and update the src/routes/onboarding, if needed.

Copy link
Contributor

src/lib/exampleKcl.ts has been updated in this PR, please review and update the src/routes/onboarding, if needed.

Copy link
Contributor

src/lib/exampleKcl.ts has been updated in this PR, please review and update the src/routes/onboarding, if needed.

Copy link
Contributor

src/lib/exampleKcl.ts has been updated in this PR, please review and update the src/routes/onboarding, if needed.

@jessfraz
Copy link
Contributor

just wanna make sure whatever regex you've been using to easily migrate files should be included in the changelog (cc @pierremtb ) and we should have instructions for discord users as well

@pierremtb
Copy link
Collaborator

@jessfraz shouldn't the regex be executed by a command in the app (as in some sort of auto migration)? I feel like having the user open up a terminal to batch replaces things is a little too much no?

@jessfraz
Copy link
Contributor

his thing doesnt work perfectly its more like a helper im just trying to help folks without increasing the burden on the pr to do it

src/lang/queryAst.ts Outdated Show resolved Hide resolved
@@ -110,6 +122,39 @@ function createCallWrapper(
tag?: Expr,
valueUsedInTransform?: number
): CreatedSketchExprResult {
if (Array.isArray(val)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use isArray() in src/lib/utils.ts.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Array.isArray is used 8 other places in this file, I would like to be consistent with the rest of the file. Follow-up PR could stop using that function.

src/lang/std/sketchcombos.ts Outdated Show resolved Hide resolved
src/lang/std/sketchcombos.ts Outdated Show resolved Hide resolved
Copy link
Contributor

src/lib/exampleKcl.ts has been updated in this PR, please review and update the src/routes/onboarding, if needed.

Copy link
Contributor

src/lib/exampleKcl.ts has been updated in this PR, please review and update the src/routes/onboarding, if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants