diff --git a/e2e/playwright/sketch-tests.spec.ts b/e2e/playwright/sketch-tests.spec.ts index efd352574..e4916f936 100644 --- a/e2e/playwright/sketch-tests.spec.ts +++ b/e2e/playwright/sketch-tests.spec.ts @@ -101,7 +101,6 @@ test.describe('Sketch tests', () => { page, scene, homePage, - scene, }) => { const u = await getUtils(page) await page.addInitScript(async () => { diff --git a/src/clientSideScene/ClientSideSceneComp.tsx b/src/clientSideScene/ClientSideSceneComp.tsx index b1227e22a..dbce82144 100644 --- a/src/clientSideScene/ClientSideSceneComp.tsx +++ b/src/clientSideScene/ClientSideSceneComp.tsx @@ -124,14 +124,7 @@ export const ClientSideScene = ({ 'mouseup', toSync(sceneInfra.onMouseUp, reportRejection) ) - sceneEntitiesManager - .tearDownSketch() - .then(() => { - // no op - }) - .catch((e) => { - console.error(e) - }) + sceneEntitiesManager.tearDownSketch({ removeAxis: true }) } }, []) diff --git a/src/clientSideScene/sceneEntities.ts b/src/clientSideScene/sceneEntities.ts index b4d882e3e..bc75f6b5f 100644 --- a/src/clientSideScene/sceneEntities.ts +++ b/src/clientSideScene/sceneEntities.ts @@ -724,7 +724,7 @@ export class SceneEntities { } const startRange = _node1.node.start const endRange = _node1.node.end - const sourceRange: SourceRange = [startRange, endRange, true] + const sourceRange: SourceRange = [startRange, endRange, 0] const selection: Selections = computeSelectionFromSourceRangeAndAST( sourceRange, maybeModdedAst @@ -793,7 +793,7 @@ export class SceneEntities { ) => { if (trap(modifiedAst)) return Promise.reject(modifiedAst) const nextAst = await kclManager.updateAst(modifiedAst, false) - await this.tearDownSketch({ removeAxis: false }) + this.tearDownSketch({ removeAxis: false }) sceneInfra.resetMouseListeners() await this.setupSketch({ sketchEntryNodePath, @@ -859,7 +859,7 @@ export class SceneEntities { const draftExpressionsIndices = { start: index, end: index } - if (shouldTearDown) await this.tearDownSketch({ removeAxis: false }) + if (shouldTearDown) this.tearDownSketch({ removeAxis: false }) sceneInfra.resetMouseListeners() const { truncatedAst, programMemoryOverride } = await this.setupSketch({ @@ -1797,7 +1797,7 @@ export class SceneEntities { sceneInfra.setCallbacks({ onDragEnd: async () => { if (addingNewSegmentStatus !== 'nothing') { - await this.tearDownSketch({ removeAxis: false }) + this.tearDownSketch({ removeAxis: false }) // eslint-disable-next-line @typescript-eslint/no-floating-promises this.setupSketch({ sketchEntryNodePath, @@ -1868,7 +1868,7 @@ export class SceneEntities { if (trap(mod)) return await kclManager.executeAstMock(mod.modifiedAst) - await this.tearDownSketch({ removeAxis: false }) + this.tearDownSketch({ removeAxis: false }) // eslint-disable-next-line @typescript-eslint/no-floating-promises this.setupSketch({ sketchEntryNodePath: pathToNode, @@ -2289,7 +2289,7 @@ export class SceneEntities { removeSketchGrid() { if (this.axisGroup) this.scene.remove(this.axisGroup) } - async tearDownSketch({ removeAxis = true }: { removeAxis?: boolean }) { + tearDownSketch({ removeAxis = true }: { removeAxis?: boolean }) { // Remove all draft groups this.draftPointGroups.forEach((draftPointGroup) => { this.scene.remove(draftPointGroup) diff --git a/src/components/ModelingMachineProvider.tsx b/src/components/ModelingMachineProvider.tsx index d5fb11cfe..c1c7a10e7 100644 --- a/src/components/ModelingMachineProvider.tsx +++ b/src/components/ModelingMachineProvider.tsx @@ -767,8 +767,9 @@ export const ModelingMachineProvider = ({ sketchPathToNode: sketchPathToNode || [], }) if (err(sketchPaths)) return Promise.reject(sketchPaths) - if (!plane.codeRef) - return Promise.reject(new Error('No plane codeRef')) + const noCodeRefErr = new Error('No plane codeRef') + if (!('codeRef' in plane)) return Promise.reject(noCodeRefErr) + if (!plane.codeRef) return Promise.reject(noCodeRefErr) return { sketchEntryNodePath: sketchPathToNode || [], sketchNodePaths: sketchPaths, @@ -1314,7 +1315,7 @@ export const ModelingMachineProvider = ({ async ({ input: { sketchDetails, data } }) => { if (!sketchDetails || !data) return reject('No sketch details or data') - await sceneEntitiesManager.tearDownSketch({ removeAxis: false }) + sceneEntitiesManager.tearDownSketch({ removeAxis: false }) const result = await sceneEntitiesManager.setupDraftCircle( sketchDetails.sketchEntryNodePath, @@ -1335,7 +1336,7 @@ export const ModelingMachineProvider = ({ async ({ input: { sketchDetails, data } }) => { if (!sketchDetails || !data) return reject('No sketch details or data') - await sceneEntitiesManager.tearDownSketch({ removeAxis: false }) + sceneEntitiesManager.tearDownSketch({ removeAxis: false }) const result = await sceneEntitiesManager.setupDraftCircleThreePoint( @@ -1358,7 +1359,7 @@ export const ModelingMachineProvider = ({ async ({ input: { sketchDetails, data } }) => { if (!sketchDetails || !data) return reject('No sketch details or data') - await sceneEntitiesManager.tearDownSketch({ removeAxis: false }) + sceneEntitiesManager.tearDownSketch({ removeAxis: false }) const result = await sceneEntitiesManager.setupDraftRectangle( sketchDetails.sketchEntryNodePath, @@ -1379,7 +1380,7 @@ export const ModelingMachineProvider = ({ async ({ input: { sketchDetails, data } }) => { if (!sketchDetails || !data) return reject('No sketch details or data') - await sceneEntitiesManager.tearDownSketch({ removeAxis: false }) + sceneEntitiesManager.tearDownSketch({ removeAxis: false }) const result = await sceneEntitiesManager.setupDraftCenterRectangle( sketchDetails.sketchEntryNodePath, sketchDetails.sketchNodePaths, diff --git a/src/lang/KclSingleton.ts b/src/lang/KclSingleton.ts index 334dc44aa..9c086b383 100644 --- a/src/lang/KclSingleton.ts +++ b/src/lang/KclSingleton.ts @@ -379,12 +379,7 @@ export class KclManager { } this.ast = { ...ast } // updateArtifactGraph relies on updated executeState/programMemory - await this.engineCommandManager.updateArtifactGraph( - this.ast, - execState.artifactCommands, - execState.artifacts, - args.isPartialExecution - ) + await this.engineCommandManager.updateArtifactGraph(execState.artifactGraph) this._executeCallback() if (!isInterrupted) sceneInfra.modelingSend({ type: 'code edit during sketch' }) diff --git a/src/lang/modifyAst.test.ts b/src/lang/modifyAst.test.ts index 1999b1110..57117a68c 100644 --- a/src/lang/modifyAst.test.ts +++ b/src/lang/modifyAst.test.ts @@ -950,10 +950,10 @@ extrude001 = extrude(5, part001) const ast = assertParse(codeBefore) const codeOfInterest = `startSketchOn('XZ')` - const range: [number, number, boolean] = [ + const range: [number, number, number] = [ codeBefore.indexOf(codeOfInterest), codeBefore.indexOf(codeOfInterest) + codeOfInterest.length, - true, + 0, ] const pathToPipe = getNodePathFromSourceRange(ast, range) @@ -977,10 +977,10 @@ extrude001 = extrude(5, part001) const ast = assertParse(codeBefore) const codeOfInterest = `startProfileAt([1, 2], sketch001)` - const range: [number, number, boolean] = [ + const range: [number, number, number] = [ codeBefore.indexOf(codeOfInterest), codeBefore.indexOf(codeOfInterest) + codeOfInterest.length, - true, + 0, ] const pathToPipe = getNodePathFromSourceRange(ast, range) diff --git a/src/lang/modifyAst/addRevolve.ts b/src/lang/modifyAst/addRevolve.ts index 5241fd32f..5cae0006e 100644 --- a/src/lang/modifyAst/addRevolve.ts +++ b/src/lang/modifyAst/addRevolve.ts @@ -28,7 +28,9 @@ export function revolveSketch( ast: Node, pathToSketchNode: PathToNode, angle: Expr = createLiteral(4), - axis: Selections, + axisOrEdge: string, + axis: string, + edge: Selections, artifact?: Artifact ): | { diff --git a/src/lang/queryAst.ts b/src/lang/queryAst.ts index f83904c81..038f81f0a 100644 --- a/src/lang/queryAst.ts +++ b/src/lang/queryAst.ts @@ -21,6 +21,7 @@ import { VariableDeclaration, VariableDeclarator, recast, + ArtifactGraph, } from './wasm' import { getNodePathFromSourceRange } from 'lang/queryAstNodePathUtils' import { createIdentifier, splitPathAtLastIndex } from './modifyAst' @@ -33,7 +34,7 @@ import { } from './std/sketchcombos' import { err, Reason } from 'lib/trap' import { Node } from 'wasm-lib/kcl/bindings/Node' -import { ArtifactGraph, codeRefFromRange } from './std/artifactGraph' +import { codeRefFromRange } from './std/artifactGraph' import { FunctionExpression } from 'wasm-lib/kcl/bindings/FunctionExpression' /** diff --git a/src/lang/std/artifactGraph.ts b/src/lang/std/artifactGraph.ts index 78a136aa3..845c3713e 100644 --- a/src/lang/std/artifactGraph.ts +++ b/src/lang/std/artifactGraph.ts @@ -240,6 +240,7 @@ export function expandSegment( if (err(path)) return path if (err(surf)) return surf if (err(edgeCut)) return edgeCut + if (!surf) return new Error('Segment does not have a surface') return { type: 'segment', @@ -435,7 +436,7 @@ function getPlaneFromSegment( return getPlaneFromPath(path, graph) } function getPlaneFromSolid2D( - solid2D: Solid2DArtifact, + solid2D: Solid2D, graph: ArtifactGraph ): PlaneArtifact | WallArtifact | CapArtifact | Error { const path = getArtifactOfTypes( @@ -490,7 +491,7 @@ export function getPlaneFromArtifact( if (artifact.type === 'plane') return artifact if (artifact.type === 'path') return getPlaneFromPath(artifact, graph) if (artifact.type === 'segment') return getPlaneFromSegment(artifact, graph) - if (artifact.type === 'solid2D') return getPlaneFromSolid2D(artifact, graph) + if (artifact.type === 'solid2d') return getPlaneFromSolid2D(artifact, graph) if (artifact.type === 'cap') return getPlaneFromCap(artifact, graph) if (artifact.type === 'wall') return getPlaneFromWall(artifact, graph) if (artifact.type === 'sweepEdge') diff --git a/src/lang/std/sketch.ts b/src/lang/std/sketch.ts index 7d98e04ca..a1ee579fc 100644 --- a/src/lang/std/sketch.ts +++ b/src/lang/std/sketch.ts @@ -1304,7 +1304,7 @@ export const circleThreePoint: SketchLineHelper = { sourceRange: [ p1Details.expr.elements[0].start, p1Details.expr.elements[0].end, - true, + 0, ], pathToNode: pathToP1XArg, value: code.slice( @@ -1325,7 +1325,7 @@ export const circleThreePoint: SketchLineHelper = { sourceRange: [ p1Details.expr.elements[1].start, p1Details.expr.elements[1].end, - true, + 0, ], pathToNode: pathToP1YArg, value: code.slice( @@ -1346,7 +1346,7 @@ export const circleThreePoint: SketchLineHelper = { sourceRange: [ p2Details.expr.elements[0].start, p2Details.expr.elements[0].end, - true, + 0, ], pathToNode: pathToP2XArg, value: code.slice( @@ -1367,7 +1367,7 @@ export const circleThreePoint: SketchLineHelper = { sourceRange: [ p2Details.expr.elements[1].start, p2Details.expr.elements[1].end, - true, + 0, ], pathToNode: pathToP2YArg, value: code.slice( @@ -1388,7 +1388,7 @@ export const circleThreePoint: SketchLineHelper = { sourceRange: [ p3Details.expr.elements[0].start, p3Details.expr.elements[0].end, - true, + 0, ], pathToNode: pathToP3XArg, value: code.slice( @@ -1409,7 +1409,7 @@ export const circleThreePoint: SketchLineHelper = { sourceRange: [ p3Details.expr.elements[1].start, p3Details.expr.elements[1].end, - true, + 0, ], pathToNode: pathToP3YArg, value: code.slice( diff --git a/src/lib/commandBarConfigs/modelingCommandConfig.ts b/src/lib/commandBarConfigs/modelingCommandConfig.ts index 0032982b8..afd8aee26 100644 --- a/src/lib/commandBarConfigs/modelingCommandConfig.ts +++ b/src/lib/commandBarConfigs/modelingCommandConfig.ts @@ -56,7 +56,7 @@ export type ModelingCommandSchema = { Revolve: { selection: Selections angle: KclCommandValue - axisOrEdge: string + axisOrEdge: 'Axis' | 'Edge' axis: string edge: Selections } diff --git a/src/lib/selections.ts b/src/lib/selections.ts index 8c82de018..e92d6ed94 100644 --- a/src/lib/selections.ts +++ b/src/lib/selections.ts @@ -287,7 +287,7 @@ export function getEventForSegmentSelection( artifact, codeRef: { pathToNode: group?.userData?.pathToNode, - range: [node.node.start, node.node.end, true], + range: [node.node.start, node.node.end, 0], }, }, }, diff --git a/src/machines/modelingMachine.ts b/src/machines/modelingMachine.ts index 6fe176a7c..5d2987c0d 100644 --- a/src/machines/modelingMachine.ts +++ b/src/machines/modelingMachine.ts @@ -700,7 +700,8 @@ export const modelingMachine = setup({ : angle.valueAst, axisOrEdge, axis, - edge + edge, + selection.graphSelections[0]?.artifact ) if (trap(revolveSketchRes)) return const { modifiedAst, pathToRevolveArg } = revolveSketchRes @@ -1604,7 +1605,6 @@ export const modelingMachine = setup({ if (!input) return Promise.reject('No input provided') const { selection, distance } = input let ast = structuredClone(kclManager.ast) - let extrudeName: string | undefined = undefined const pathToNode = getNodePathFromSourceRange( ast, @@ -1614,7 +1614,7 @@ export const modelingMachine = setup({ const extrudeSketchRes = extrudeSketch( ast, pathToNode, - false, + selection.graphSelections[0].artifact, 'variableName' in distance ? distance.variableIdentifierAst : distance.valueAst