Add ability to create named constant without code (#5840)
* Add support for forcing kcl input create variable * Command palette padding tweak * Make traverse function work for ExpressionStatements * Add utilities for getting earliest safe index in AST * Fix the insertIndex logic to not be based on the selection anymore * Add workflow to create a named constant * Fix bug with nameEndInDigits matcher * Tweak command config * Add a three-dot menu to feature tree pane to create parameters * Add E2E test for create parameter flow * Remove edit flow oops * Fix tsc error * Fix E2E test * Update named constant position in edit flow test * Add tags into consideration for safe insert index Per @Irev-dev's helpful feedback, with unit tests!
This commit is contained in:
@ -50,6 +50,7 @@ import {
|
||||
createIdentifier,
|
||||
createLiteral,
|
||||
extrudeSketch,
|
||||
insertNamedConstant,
|
||||
loftSketches,
|
||||
} from 'lang/modifyAst'
|
||||
import {
|
||||
@ -306,6 +307,10 @@ export type ModelingMachineEvent =
|
||||
| { type: 'Constrain parallel' }
|
||||
| { type: 'Constrain remove constraints'; data?: PathToNode }
|
||||
| { type: 'Re-execute' }
|
||||
| {
|
||||
type: 'event.parameter.create'
|
||||
data: ModelingCommandSchema['event.parameter.create']
|
||||
}
|
||||
| { type: 'Export'; data: ModelingCommandSchema['Export'] }
|
||||
| { type: 'Make'; data: ModelingCommandSchema['Make'] }
|
||||
| { type: 'Extrude'; data?: ModelingCommandSchema['Extrude'] }
|
||||
@ -2291,6 +2296,32 @@ export const modelingMachine = setup({
|
||||
if (err(filletResult)) return filletResult
|
||||
}
|
||||
),
|
||||
'actor.parameter.create': fromPromise(
|
||||
async ({
|
||||
input,
|
||||
}: {
|
||||
input: ModelingCommandSchema['event.parameter.create'] | undefined
|
||||
}) => {
|
||||
if (!input) return new Error('No input provided')
|
||||
const { value } = input
|
||||
if (!('variableName' in value)) {
|
||||
return new Error('variable name is required')
|
||||
}
|
||||
const newAst = insertNamedConstant({
|
||||
node: kclManager.ast,
|
||||
newExpression: value,
|
||||
})
|
||||
const updateAstResult = await kclManager.updateAst(newAst, true)
|
||||
|
||||
await codeManager.updateEditorWithAstAndWriteToFile(
|
||||
updateAstResult.newAst
|
||||
)
|
||||
|
||||
if (updateAstResult?.selections) {
|
||||
editorManager.selectRange(updateAstResult?.selections)
|
||||
}
|
||||
}
|
||||
),
|
||||
'set-up-draft-circle': fromPromise(
|
||||
async (_: {
|
||||
input: Pick<ModelingMachineContext, 'sketchDetails'> & {
|
||||
@ -2539,6 +2570,10 @@ export const modelingMachine = setup({
|
||||
reenter: true,
|
||||
},
|
||||
|
||||
'event.parameter.create': {
|
||||
target: '#Modeling.parameter.creating',
|
||||
},
|
||||
|
||||
Export: {
|
||||
target: 'Exporting',
|
||||
guard: 'Has exportable geometry',
|
||||
@ -3839,6 +3874,24 @@ export const modelingMachine = setup({
|
||||
},
|
||||
},
|
||||
|
||||
parameter: {
|
||||
type: 'parallel',
|
||||
states: {
|
||||
creating: {
|
||||
invoke: {
|
||||
src: 'actor.parameter.create',
|
||||
id: 'actor.parameter.create',
|
||||
input: ({ event }) => {
|
||||
if (event.type !== 'event.parameter.create') return undefined
|
||||
return event.data
|
||||
},
|
||||
onDone: ['#Modeling.idle'],
|
||||
onError: ['#Modeling.idle'],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
'Applying Prompt-to-edit': {
|
||||
invoke: {
|
||||
src: 'submit-prompt-edit',
|
||||
|
Reference in New Issue
Block a user