From 7b54ba84033fbc8045fc3b2833f68dff16d719e2 Mon Sep 17 00:00:00 2001 From: Pierre Jacquier Date: Tue, 3 Jun 2025 13:46:12 -0400 Subject: [PATCH] Clean up diff --- src/lib/operations.ts | 248 ++++++++++++++++++++---------------------- 1 file changed, 120 insertions(+), 128 deletions(-) diff --git a/src/lib/operations.ts b/src/lib/operations.ts index 67606504c..751482051 100644 --- a/src/lib/operations.ts +++ b/src/lib/operations.ts @@ -900,134 +900,6 @@ const prepareToEditRevolve: PrepareToEditCallback = async ({ } } -/** - * Gather up the argument values for the translate command - * to be used in the command bar edit flow. - */ -const prepareToEditTranslate: PrepareToEditCallback = async ({ operation }) => { - const baseCommand = { - name: 'Translate', - groupId: 'modeling', - } - const isModuleImport = operation.type === 'GroupBegin' - const isSupportedStdLibCall = - operation.type === 'StdLibCall' && - stdLibMap[operation.name]?.supportsTransform - if (!isModuleImport && !isSupportedStdLibCall) { - return { - reason: 'Unsupported operation type. Please edit in the code editor.', - } - } - - const nodeToEdit = getNodePathFromSourceRange( - kclManager.ast, - sourceRangeFromRust(operation.sourceRange) - ) - let x: KclExpression | undefined = undefined - let y: KclExpression | undefined = undefined - let z: KclExpression | undefined = undefined - const pipeLookupFromOperation = getNodeFromPath( - kclManager.ast, - nodeToEdit, - 'PipeExpression' - ) - let pipe: PipeExpression | undefined - const ast = kclManager.ast - if ( - err(pipeLookupFromOperation) || - pipeLookupFromOperation.node.type !== 'PipeExpression' - ) { - // Look for the last pipe with the import alias and a call to translate - const pipes = findPipesWithImportAlias(ast, nodeToEdit, 'translate') - pipe = pipes.at(-1)?.expression - } else { - pipe = pipeLookupFromOperation.node - } - - if (pipe) { - const translate = pipe.body.find( - (n) => n.type === 'CallExpressionKw' && n.callee.name.name === 'translate' - ) - if (translate?.type === 'CallExpressionKw') { - x = await retrieveArgFromPipedCallExpression(translate, 'x') - y = await retrieveArgFromPipedCallExpression(translate, 'y') - z = await retrieveArgFromPipedCallExpression(translate, 'z') - } - } - - // Won't be used since we provide nodeToEdit - const selection: Selections = { graphSelections: [], otherSelections: [] } - const argDefaultValues = { nodeToEdit, selection, x, y, z } - return { - ...baseCommand, - argDefaultValues, - } -} - -/** - * Gather up the argument values for the rotate command - * to be used in the command bar edit flow. - */ -const prepareToEditRotate: PrepareToEditCallback = async ({ operation }) => { - const baseCommand = { - name: 'Rotate', - groupId: 'modeling', - } - const isModuleImport = operation.type === 'GroupBegin' - const isSupportedStdLibCall = - operation.type === 'StdLibCall' && - stdLibMap[operation.name]?.supportsTransform - if (!isModuleImport && !isSupportedStdLibCall) { - return { - reason: 'Unsupported operation type. Please edit in the code editor.', - } - } - - const nodeToEdit = getNodePathFromSourceRange( - kclManager.ast, - sourceRangeFromRust(operation.sourceRange) - ) - let roll: KclExpression | undefined = undefined - let pitch: KclExpression | undefined = undefined - let yaw: KclExpression | undefined = undefined - const pipeLookupFromOperation = getNodeFromPath( - kclManager.ast, - nodeToEdit, - 'PipeExpression' - ) - let pipe: PipeExpression | undefined - const ast = kclManager.ast - if ( - err(pipeLookupFromOperation) || - pipeLookupFromOperation.node.type !== 'PipeExpression' - ) { - // Look for the last pipe with the import alias and a call to rotate - const pipes = findPipesWithImportAlias(ast, nodeToEdit, 'rotate') - pipe = pipes.at(-1)?.expression - } else { - pipe = pipeLookupFromOperation.node - } - - if (pipe) { - const rotate = pipe.body.find( - (n) => n.type === 'CallExpressionKw' && n.callee.name.name === 'rotate' - ) - if (rotate?.type === 'CallExpressionKw') { - roll = await retrieveArgFromPipedCallExpression(rotate, 'roll') - pitch = await retrieveArgFromPipedCallExpression(rotate, 'pitch') - yaw = await retrieveArgFromPipedCallExpression(rotate, 'yaw') - } - } - - // Won't be used since we provide nodeToEdit - const selection: Selections = { graphSelections: [], otherSelections: [] } - const argDefaultValues = { nodeToEdit, selection, roll, pitch, yaw } - return { - ...baseCommand, - argDefaultValues, - } -} - /** * A map of standard library calls to their corresponding information * for use in the feature tree UI. @@ -1447,6 +1319,66 @@ export async function enterAppearanceFlow({ ) } +const prepareToEditTranslate: PrepareToEditCallback = async ({ operation }) => { + const baseCommand = { + name: 'Translate', + groupId: 'modeling', + } + const isModuleImport = operation.type === 'GroupBegin' + const isSupportedStdLibCall = + operation.type === 'StdLibCall' && + stdLibMap[operation.name]?.supportsTransform + if (!isModuleImport && !isSupportedStdLibCall) { + return { + reason: 'Unsupported operation type. Please edit in the code editor.', + } + } + + const nodeToEdit = getNodePathFromSourceRange( + kclManager.ast, + sourceRangeFromRust(operation.sourceRange) + ) + let x: KclExpression | undefined = undefined + let y: KclExpression | undefined = undefined + let z: KclExpression | undefined = undefined + const pipeLookupFromOperation = getNodeFromPath( + kclManager.ast, + nodeToEdit, + 'PipeExpression' + ) + let pipe: PipeExpression | undefined + const ast = kclManager.ast + if ( + err(pipeLookupFromOperation) || + pipeLookupFromOperation.node.type !== 'PipeExpression' + ) { + // Look for the last pipe with the import alias and a call to translate + const pipes = findPipesWithImportAlias(ast, nodeToEdit, 'translate') + pipe = pipes.at(-1)?.expression + } else { + pipe = pipeLookupFromOperation.node + } + + if (pipe) { + const translate = pipe.body.find( + (n) => n.type === 'CallExpressionKw' && n.callee.name.name === 'translate' + ) + if (translate?.type === 'CallExpressionKw') { + x = await retrieveArgFromPipedCallExpression(translate, 'x') + y = await retrieveArgFromPipedCallExpression(translate, 'y') + z = await retrieveArgFromPipedCallExpression(translate, 'z') + } + } + + // Won't be used since we provide nodeToEdit + const selection: Selections = { graphSelections: [], otherSelections: [] } + const argDefaultValues = { nodeToEdit, selection, x, y, z } + return { + ...baseCommand, + argDefaultValues, + } +} + export async function enterTranslateFlow({ operation, }: EnterEditFlowProps): Promise { @@ -1461,6 +1393,66 @@ export async function enterTranslateFlow({ } } +const prepareToEditRotate: PrepareToEditCallback = async ({ operation }) => { + const baseCommand = { + name: 'Rotate', + groupId: 'modeling', + } + const isModuleImport = operation.type === 'GroupBegin' + const isSupportedStdLibCall = + operation.type === 'StdLibCall' && + stdLibMap[operation.name]?.supportsTransform + if (!isModuleImport && !isSupportedStdLibCall) { + return { + reason: 'Unsupported operation type. Please edit in the code editor.', + } + } + + const nodeToEdit = getNodePathFromSourceRange( + kclManager.ast, + sourceRangeFromRust(operation.sourceRange) + ) + let roll: KclExpression | undefined = undefined + let pitch: KclExpression | undefined = undefined + let yaw: KclExpression | undefined = undefined + const pipeLookupFromOperation = getNodeFromPath( + kclManager.ast, + nodeToEdit, + 'PipeExpression' + ) + let pipe: PipeExpression | undefined + const ast = kclManager.ast + if ( + err(pipeLookupFromOperation) || + pipeLookupFromOperation.node.type !== 'PipeExpression' + ) { + // Look for the last pipe with the import alias and a call to rotate + const pipes = findPipesWithImportAlias(ast, nodeToEdit, 'rotate') + pipe = pipes.at(-1)?.expression + } else { + pipe = pipeLookupFromOperation.node + } + + if (pipe) { + const rotate = pipe.body.find( + (n) => n.type === 'CallExpressionKw' && n.callee.name.name === 'rotate' + ) + if (rotate?.type === 'CallExpressionKw') { + roll = await retrieveArgFromPipedCallExpression(rotate, 'roll') + pitch = await retrieveArgFromPipedCallExpression(rotate, 'pitch') + yaw = await retrieveArgFromPipedCallExpression(rotate, 'yaw') + } + } + + // Won't be used since we provide nodeToEdit + const selection: Selections = { graphSelections: [], otherSelections: [] } + const argDefaultValues = { nodeToEdit, selection, roll, pitch, yaw } + return { + ...baseCommand, + argDefaultValues, + } +} + export async function enterRotateFlow({ operation, }: EnterEditFlowProps): Promise {