Skip to content

Comments

Multi-profile sweeps and more robust edit flows in point-and-click#6437

Merged
franknoirot merged 39 commits intomainfrom
pierremtb/issue6434-Extend-point-and-click-edit-flows-to-non-variable-sweep-declarations
May 6, 2025
Merged

Multi-profile sweeps and more robust edit flows in point-and-click#6437
franknoirot merged 39 commits intomainfrom
pierremtb/issue6434-Extend-point-and-click-edit-flows-to-non-variable-sweep-declarations

Conversation

@pierremtb
Copy link
Contributor

@pierremtb pierremtb commented Apr 22, 2025

Fixes #6434

This turned into a huge PR, sorry that wasn't the intent 😢

The goal of this refactor is to ensure a consistent order of operations across the different sweep calls and allow edit flows to be more robust to non-standard ways of creating these operations, namely:

  • support variable-assigned calls (already exisitng on main)
  • support standalone calls (not working on main, common in KCL Samples and AI-generated)
  • support in-pipe calls (not working on main, common in KCL Samples and AI-generated)

This includes the following codemods, and move their implementation in a modifyAst/addSweep.ts file along with utility functions:

  • Extrude
  • Revolve
  • Sweep
  • Loft (still no edit flow as it's selections only, but put into the mix for consistency)

This doesn't include Shell and others that have different argument flows and potentially need to be treated differently.

While I was building that, supporting multi-profile selections for this was straightforward to add so I took the chance to do it, since KCL supports it and it was an easy lift. This also ensures command bar argument to kcl argument naming consistency, biggest one being swapping selection for sketches.

Demo

Screenshare.-.2025-04-28.7_44_04.PM.mp4

@vercel
Copy link

vercel bot commented Apr 22, 2025

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

Name Status Preview Comments Updated (UTC)
modeling-app ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 6, 2025 9:46pm

@qa-wolf
Copy link

qa-wolf bot commented Apr 22, 2025

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!

@codecov
Copy link

codecov bot commented Apr 22, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.35%. Comparing base (4d2bc18) to head (5c766a2).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6437      +/-   ##
==========================================
- Coverage   85.36%   85.35%   -0.02%     
==========================================
  Files         107      108       +1     
  Lines       47219    47355     +136     
==========================================
+ Hits        40309    40420     +111     
- Misses       6910     6935      +25     
Flag Coverage Δ
rust 85.35% <ø> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

…dit-flows-to-non-variable-sweep-declarations
…dit-flows-to-non-variable-sweep-declarations
…dit-flows-to-non-variable-sweep-declarations
@pierremtb pierremtb marked this pull request as draft May 5, 2025 13:42
if (!isSelections(context.argumentsToSubmit.sketches)) {
return 'Unable to revolve, selections are missing'
}
// Gotcha: this validation only works for the first sketch
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Didn't want to rotate on this any more than what was necessary to not break the existing, since dry run validations aren't really something we're sure have a future atm

) {
return baseCommand
}
const prepareToEditExtrude: PrepareToEditCallback = async ({ operation }) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cleaned up all three below with an inverse util function to go from the sketches in the operation object to graph selections. Trying to make things as consistent as possible but still allowing for specific needs of each

}

const pathToNode = getNodePathFromSourceRange(
if (!input) return Promise.reject(new Error('No input provided'))
Copy link
Contributor Author

@pierremtb pierremtb May 5, 2025

Choose a reason for hiding this comment

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

And finally modelingMachine.ts, the code mods here are much shorter and follow the same pattern for all four. Including the use of Promise.reject to make sure the errors aren't silent, which is something we haven't been consistent about in the past

  1. unpack args
  2. call function from addSweep
  3. if no error, call updateModelingState

@pierremtb pierremtb marked this pull request as ready for review May 5, 2025 14:15
@pierremtb pierremtb enabled auto-merge (squash) May 5, 2025 14:27
@maxammann maxammann disabled auto-merge May 6, 2025 09:48
@maxammann maxammann enabled auto-merge (squash) May 6, 2025 09:49
@maxammann maxammann disabled auto-merge May 6, 2025 09:49
Copy link
Contributor

@franknoirot franknoirot left a comment

Choose a reason for hiding this comment

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

Wow so much cleanup along with these UX improvements. Big PR forgiven 😄

Comment on lines +40 to +62
await toolbar.extrudeButton.click()
await cmdBar.expectState({
stage: 'arguments',
commandName: 'Extrude',
currentArgKey: 'sketches',
currentArgValue: '',
headerArguments: {
Sketches: '',
Length: '',
},
highlightedHeaderArg: 'sketches',
})
await cmdBar.progressCmdBar()
await cmdBar.progressCmdBar()
await cmdBar.expectState({
stage: 'review',
commandName: 'Extrude',
headerArguments: {
Sketches: '1 segment',
Length: '5',
},
})
await cmdBar.progressCmdBar()
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice 🔥

KCL_DEFAULT_CONSTANT_PREFIXES.EXTRUDE
)
const declaration = createVariableDeclaration(name, call)
modifiedAst.body.push(declaration)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nah do it haha I'm sick of dumb "smart" insertion

import type { Selections } from '@src/lib/selections'
import { err } from '@src/lib/trap'

export function addExtrude({
Copy link
Contributor

Choose a reason for hiding this comment

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

These seem like they might be good as comments around the code itself as well.

return sketchesExpr
}

function insertVariable(
Copy link
Contributor

Choose a reason for hiding this comment

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

For future reference there is already a very similar function in modifyAst called insertVariableAndOffsetPathToNode. Might be good to flag a TODO to unify since they both look pretty generic?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh good call I remember that now let me look quick

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This works perfectly!

Copy link
Contributor

Choose a reason for hiding this comment

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

@Irev-Dev might want eyes on these AST helpers here and in addSweep. I'm trying to get in the right headspace for reviewing them 😅

// KCL stdlib arguments
sketches: Selections
path: Selections
sectional?: boolean
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice we should make it one of the first truly optional arguments like these ones with the +s here
Screenshot 2025-05-06 at 3 03 16 PM

// KCL stdlib arguments
sketches: Selections
path: Selections
sectional?: boolean
Copy link
Contributor

Choose a reason for hiding this comment

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

(later)

// })),
// },
distance: {
length: {
Copy link
Contributor

Choose a reason for hiding this comment

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

I 100% agree this is good though. One of our goals for the UX is for the point-and-click experience to provide a smooth learning curve into KCL and more "power user" things. Making things match across that divide is lowkey important for supporting that

Copy link
Contributor

Choose a reason for hiding this comment

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

I really like this cleanup here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you!

…dit-flows-to-non-variable-sweep-declarations
Copy link
Contributor Author

@pierremtb pierremtb left a comment

Choose a reason for hiding this comment

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

Thanks so much for reviewing @franknoirot! Made two changes based on your suggestions in addSweep about comments and using an existing utility. Let's see if I didn't break anything!

import type { Selections } from '@src/lib/selections'
import { err } from '@src/lib/trap'

export function addExtrude({
Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're totally right, added them!

KCL_DEFAULT_CONSTANT_PREFIXES.EXTRUDE
)
const declaration = createVariableDeclaration(name, call)
modifiedAst.body.push(declaration)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright hahaha let's do this

return sketchesExpr
}

function insertVariable(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This works perfectly!

// KCL stdlib arguments
sketches: Selections
path: Selections
sectional?: boolean
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh yesssss

// })),
// },
distance: {
length: {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds great!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you!

variable: KclCommandValue,
modifiedAst: Node<Program>,
pathToNode: PathToNode
pathToNode?: PathToNode
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@franknoirot @Irev-Dev this way I can use it in addSweep.ts. Doesn't seem like a big change since we had the typeof check already

@franknoirot franknoirot merged commit 996517f into main May 6, 2025
46 checks passed
@franknoirot franknoirot deleted the pierremtb/issue6434-Extend-point-and-click-edit-flows-to-non-variable-sweep-declarations branch May 6, 2025 21:57
nodeToEdit?: PathToNode
): Error | Expr[] {
const sketches: Expr[] = selection.graphSelections.flatMap((s) => {
const path = getNodePathFromSourceRange(ast, s?.codeRef.range)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this fine for this PR, but we should probably get in the habit of using codeRef.pathToNode directly. As since #6632 it should be more reliable than range (range does not update under circumstances like comments or white space changes which can really mess things up)

But there's an argument for me or Jon to go through and banish ranges from the app entirely one we're able to come up for air, so just socialising it at this point.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh nice yeah, thank you! Might do a follow up if that's quick and easy

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.

Extend point-and-click edit flows to non-variable sweep declarations

3 participants