Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions src/components/Toolbar/angleLengthInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,5 @@ export function angleLengthInfo({
selectionRanges.graphSelections.length <= 1 &&
isAllTooltips &&
transforms.every(Boolean)
console.log(
'enabled',
enabled,
selectionRanges.graphSelections.length,
isAllTooltips,
transforms.every(Boolean)
)
return { enabled, transforms }
}
10 changes: 8 additions & 2 deletions src/lang/modifyAst.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1030,19 +1030,25 @@ sketch003 = startSketchOn(XZ)

describe('Testing splitPipedProfile', () => {
it('should split the pipe expression correctly', () => {
const codeBefore = `part001 = startSketchOn(XZ)
const codeBefore = `// comment 1
part001 = startSketchOn(XZ)
|> startProfileAt([1, 2], %)
// comment 2
|> line([3, 4], %)
|> line([5, 6], %)
|> close(%)
// comment 3
extrude001 = extrude(5, part001)
`

const expectedCodeAfter = `sketch001 = startSketchOn(XZ)
const expectedCodeAfter = `// comment 1
sketch001 = startSketchOn(XZ)
part001 = startProfileAt([1, 2], sketch001)
// comment 2
|> line([3, 4], %)
|> line([5, 6], %)
|> close(%)
// comment 3
extrude001 = extrude(5, part001)
`

Expand Down
67 changes: 47 additions & 20 deletions src/lang/modifyAst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import type { Models } from '@kittycad/lib'
import type { BodyItem } from '@rust/kcl-lib/bindings/BodyItem'
import type { Name } from '@rust/kcl-lib/bindings/Name'
import type { Node } from '@rust/kcl-lib/bindings/Node'
import type { NonCodeMeta } from '@rust/kcl-lib/bindings/NonCodeMeta'

import {
createArrayExpression,
createCallExpression,
createCallExpressionStdLib,
createCallExpressionStdLibKw,
createIdentifier,
Expand Down Expand Up @@ -1640,7 +1640,7 @@ export function splitPipedProfile(
}
| Error {
const _ast = structuredClone(ast)
const varDec = getNodeFromPath<VariableDeclaration>(
const varDec = getNodeFromPath<Node<VariableDeclaration>>(
_ast,
pathToPipe,
'VariableDeclaration'
Expand All @@ -1664,26 +1664,53 @@ export function splitPipedProfile(
const newVarName = findUniqueName(_ast, 'sketch')
const secondCallArgs = structuredClone(secondCall.arguments)
secondCallArgs[1] = createLocalName(newVarName)
const firstCallOfNewPipe = createCallExpression(
'startProfileAt',
secondCallArgs
)
const newSketch = createVariableDeclaration(
newVarName,
varDec.node.declaration.init.body[0]
)
const newProfile = createVariableDeclaration(
varName,
varDec.node.declaration.init.body.length <= 2
? firstCallOfNewPipe
: createPipeExpression([
firstCallOfNewPipe,
...varDec.node.declaration.init.body.slice(2),
])
)
const startSketchOnBrokenIntoNewVarDec = structuredClone(varDec.node)
const profileBrokenIntoItsOwnVar = structuredClone(varDec.node)
if (
startSketchOnBrokenIntoNewVarDec.declaration.init.type !== 'PipeExpression'
) {
return new Error('clonedVarDec1 is not a PipeExpression')
}
varDec.node.declaration.init =
startSketchOnBrokenIntoNewVarDec.declaration.init.body[0]
varDec.node.declaration.id.name = newVarName
if (profileBrokenIntoItsOwnVar.declaration.init.type !== 'PipeExpression') {
return new Error('clonedVarDec2 is not a PipeExpression')
}
profileBrokenIntoItsOwnVar.declaration.init.body =
profileBrokenIntoItsOwnVar.declaration.init.body.slice(1)
if (
!(
profileBrokenIntoItsOwnVar.declaration.init.body[0].type ===
'CallExpression' &&
profileBrokenIntoItsOwnVar.declaration.init.body[0].callee.name.name ===
'startProfileAt'
)
) {
return new Error('problem breaking pipe, expect startProfileAt to be first')
}
profileBrokenIntoItsOwnVar.declaration.init.body[0].arguments[1] =
createLocalName(newVarName)
profileBrokenIntoItsOwnVar.declaration.id.name = varName
profileBrokenIntoItsOwnVar.preComments = [] // we'll duplicate the comments since the new variable will have it to

// new pipe has one less from the start, so need to decrement comments for them to remain in the same place
if (profileBrokenIntoItsOwnVar.declaration.init?.nonCodeMeta?.nonCodeNodes) {
let decrementedNonCodeMeta: NonCodeMeta['nonCodeNodes'] = {}
decrementedNonCodeMeta =
Object.entries(
profileBrokenIntoItsOwnVar.declaration.init?.nonCodeMeta?.nonCodeNodes
).reduce((acc, [key, value]) => {
acc[Number(key) - 1] = value
return acc
}, decrementedNonCodeMeta) || {}
profileBrokenIntoItsOwnVar.declaration.init.nonCodeMeta.nonCodeNodes =
decrementedNonCodeMeta
}

const index = getBodyIndex(pathToPipe)
if (err(index)) return index
_ast.body.splice(index, 1, newSketch, newProfile)
_ast.body.splice(index + 1, 0, profileBrokenIntoItsOwnVar)
const pathToPlane = structuredClone(pathToPipe)
const pathToProfile = structuredClone(pathToPipe)
pathToProfile[1][0] = index + 1
Expand Down
2 changes: 1 addition & 1 deletion src/machines/modelingMachine.ts

Large diffs are not rendered by default.

Loading