Add point-and-click Insert from local project files#6129
Conversation
Will eventually fix #6120 Right now the whole loop is there but the codemod doesn't work yet
|
QA Wolf here! As you write new code it's important that your test coverage is keeping up. |
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #6129 +/- ##
=======================================
Coverage 85.09% 85.09%
=======================================
Files 110 110
Lines 44684 44684
=======================================
Hits 38024 38024
Misses 6660 6660
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| (command) => kclSamples.length || command.name !== 'open-kcl-example' | ||
| ), | ||
| [codeManager, kclManager, send, kclSamples] | ||
| [codeManager, kclManager, send, kclSamples, project, file] |
There was a problem hiding this comment.
This right here is the reason why this command was added in kclCommands and not in modelingMachine as it was at first, since I wanted the path input to be prefilled with project files which is a lot easier and faster to navigate than a full blown filesystem dialog. But I didn't really know how to nicely inject thse dependencies into the modelingMachine, so I went this way instead. Feedback on this super welcome!
There was a problem hiding this comment.
@nadr0 is in the process of excavating the projectMachine out of React. When that is done, then the inputs will be available anywhere the appMachine is, and it should be easier to get into a modeling command definition. But I think this is understandable as an approach!
There was a problem hiding this comment.
Ok phew that's awesome!
| // TODO: understand why this skip flag is needed for insertAstMod. | ||
| // It's unclear why we double casts the AST |
There was a problem hiding this comment.
This took a lot of time from a few of us to debug. Thanks a lot to @franknoirot @nadr0 @lee-at-zoo-corp
The solution below is not perfect but helps unblocking us without changing the code path too much.
| onSubmit: (data) => { | ||
| if (!data) { | ||
| return new Error('No input provided') | ||
| } | ||
|
|
||
| const ast = kclManager.ast | ||
| const { path, localName } = data | ||
| const { modifiedAst, pathToImportNode, pathToInsertNode } = | ||
| addImportAndInsert({ | ||
| node: ast, | ||
| path, | ||
| localName, | ||
| }) | ||
| updateModelingState( | ||
| modifiedAst, | ||
| EXECUTION_TYPE_REAL, | ||
| { kclManager, editorManager, codeManager }, | ||
| { | ||
| skipUpdateAst: true, | ||
| focusPath: [pathToImportNode, pathToInsertNode], | ||
| } | ||
| ).catch(reportRejection) | ||
| }, | ||
| }, |
There was a problem hiding this comment.
This started as insertAstMod in the modelingMachine file, moved it here after the transition to prefilled paths. Not entirely sure this is the correct way forward.
There was a problem hiding this comment.
my only problem with is the name, I know you didn't name it but updateModelingState does not strike me as something that's about executing, updating the kcl-singleton and editor, sounds like it should be part of the modeling machine.
Irev-Dev
left a comment
There was a problem hiding this comment.
Quick thought from having just watched the vid, surely we should pre-fill the localName with something derived from the fileNam?
| if (!tronApp) { | ||
| throwTronAppMissing() | ||
| return | ||
| } |
There was a problem hiding this comment.
Shouldn't this be abstracted into one of the fixtures, and just be a oneLiner, or maybe part of "goToModelingScene"?
There was a problem hiding this comment.
I might leave this with @nadr0 as a separate issue if that's cool. This pattern only exists in e2e/playwright/native-file-menu.spec.ts, not sure how much it should be generalized.
But I agree with the sentiment yes!
| onSubmit: (data) => { | ||
| if (!data) { | ||
| return new Error('No input provided') | ||
| } | ||
|
|
||
| const ast = kclManager.ast | ||
| const { path, localName } = data | ||
| const { modifiedAst, pathToImportNode, pathToInsertNode } = | ||
| addImportAndInsert({ | ||
| node: ast, | ||
| path, | ||
| localName, | ||
| }) | ||
| updateModelingState( | ||
| modifiedAst, | ||
| EXECUTION_TYPE_REAL, | ||
| { kclManager, editorManager, codeManager }, | ||
| { | ||
| skipUpdateAst: true, | ||
| focusPath: [pathToImportNode, pathToInsertNode], | ||
| } | ||
| ).catch(reportRejection) | ||
| }, | ||
| }, |
There was a problem hiding this comment.
my only problem with is the name, I know you didn't name it but updateModelingState does not strike me as something that's about executing, updating the kcl-singleton and editor, sounds like it should be part of the modeling machine.
|
@Irev-Dev Re:
Totally agree, would probably make sense to be something clearer like |
Co-authored-by: Kurt Hutten <k.hutten@protonmail.ch>
@Irev-Dev Yes I actually wanted to do this and I think I just forgot. I have two follow up PRs to this one and I can for sure create a dedicated one for a nice little |
|
@Irev-Dev re:
You're super right and it actualy gets worse as we start talking about #6020, since in the case of module with no return value (say any part ending with a variable-assigned extrude for instance), you can use |
Ahh kk so long as your on top of it. Oh btw, we should allow inserting static assets with the point and click as well right? (maybe a follow up PR thing) Screenshare.-.2025-04-08.5_11_28.AM.mp4 |
|
Wrong link, the linked PR is #6159 |
* WIP: Add point-and-click Import for geometry Will eventually fix #6120 Right now the whole loop is there but the codemod doesn't work yet * Better pathToNOde, log on non-working cm dispatch call * Add workaround to updateModelingState not working * Back to updateModelingState with a skip flag * Better todo * Change working from Import to Insert, cleanups * Sister command in kclCommands to populate file options * Improve path selector * Unsure: move importAstMod to kclCommands onSubmit 😶 * Add e2e test * Clean up for review * Add native file menu entry and test * No await yo lint said so * @lrev-Dev's suggestion to remove a comment Co-authored-by: Kurt Hutten <k.hutten@protonmail.ch> * Update to scene.settled(cmdBar) * Lint --------- Co-authored-by: Kurt Hutten <k.hutten@protonmail.ch>
|
Sorry post merge. But one other thing I thought of is your e2e test, is the happy path, should there be a sad path test? |
* origin/main: Quick app rename typo fix in settings.md (#6198) Add point-and-click Insert from local project files (#6129) Install and start Vector on macOS CI runners (#6147) Implement polar std function in KCL (#6180) Bump typescript from 5.8.2 to 5.8.3 in /packages/codemirror-lsp-client in the patch group (#6188) Bump @types/node from 22.13.13 to 22.14.0 in /packages/codemirror-lsp-client in the minor group (#6189) Bump the major group in /packages/codemirror-lang-kcl with 2 updates (#6194) Bump taiki-e/install-action from 2.49.30 to 2.49.45 in the patch group (#6185) Bump the patch group with 6 updates (#6186) Bump the patch group in /rust/kcl-language-server with 3 updates (#6183) Bump the patch group in /packages/codemirror-lang-kcl with 2 updates (#6193) Remove unnecessary timeouts waiting for command bar (#6199) Stream handling / Stream idle mode v2; a ton of network related changes (ping; scene indicator -> stream indicator, stream resizing (even on pause)) (#5312) More propagation of numeric types (#6177) Apply type-directed coercions to arguments in calls of user functions (#6179) Erase comment start positions from snapshot tests (#6178) Implement coercion of numeric types for ascription and arithmetic (off by default) (#6175) Reduce the number of reps in the add_lots test (#6174) take things off the batch in a more safe way (#6171)
|
@Irev-Dev yeah you're totally right. Once clone is available inserting the same part work will work through a clone() codemod, but now, importing twice will fail to execute. Which I thought wouldn't be horrible from a user standpoint but I guess we should check for the execution errors to occur. I'll make it part of #6152 |

Closes #6120
Ok here we go this is the first step towards #4735, and is about importing existing parts in project as whole modules and executing as such. This is a first pass and does not include:
all of which are layed out as separate subissues in Support basic assemblies in point-and-click UI #4735
Note that the lingo here is Insert, not Import. As the codemod suggests, inserting is about importing and the instantiating (in our case here executing the whole module), and is akin to what regular CAD software looks like for assemblies.
But it does include:
Recording.2025-04-04.133516.mp4