diff --git a/e2e/playwright/testing-constraints.spec.ts b/e2e/playwright/testing-constraints.spec.ts index e731fef33..343ccabd0 100644 --- a/e2e/playwright/testing-constraints.spec.ts +++ b/e2e/playwright/testing-constraints.spec.ts @@ -57,7 +57,7 @@ test.describe('Testing constraints', () => { .click() await expect(page.locator('.cm-content')).toHaveText( - `length001 = 20sketch001 = startSketchOn('XY') |> startProfileAt([-10, -10], %) |> line(end = [20, 0], %) |> angledLine([90, length001], %) |> xLine(-20)` + `length001 = 20sketch001 = startSketchOn('XY') |> startProfileAt([-10, -10], %) |> line(end = [20, 0]) |> angledLine([90, length001], %) |> xLine(-20, %)` ) // Make sure we didn't pop out of sketch mode. diff --git a/src/components/Toolbar/setAngleLength.tsx b/src/components/Toolbar/setAngleLength.tsx index 5453ef684..5123c660f 100644 --- a/src/components/Toolbar/setAngleLength.tsx +++ b/src/components/Toolbar/setAngleLength.tsx @@ -39,7 +39,7 @@ export function angleLengthInfo({ } | Error { const nodes = selectionRanges.graphSelections.map(({ codeRef }) => - getNodeFromPath(kclManager.ast, codeRef.pathToNode, 'CallExpression') + getNodeFromPath(kclManager.ast, codeRef.pathToNode, ['CallExpression', 'CallExpressionKw']) ) const _err1 = nodes.find(err) if (_err1 instanceof Error) return _err1 @@ -47,7 +47,7 @@ export function angleLengthInfo({ const isAllTooltips = nodes.every((meta) => { if (err(meta)) return false return ( - meta.node?.type === 'CallExpression' && + (meta.node?.type === 'CallExpressionKw' || meta.node?.type === 'CallExpression') && toolTips.includes(meta.node.callee.name as any) ) }) diff --git a/src/lang/std/sketchConstraints.ts b/src/lang/std/sketchConstraints.ts index df1dd883b..4927f7258 100644 --- a/src/lang/std/sketchConstraints.ts +++ b/src/lang/std/sketchConstraints.ts @@ -12,8 +12,11 @@ import { Expr, topLevelRange, LabeledArg, + CallExpressionKw, } from '../wasm' import { err } from 'lib/trap' +import { findKwArgAny } from 'lang/util' +import { ARG_END, ARG_END_ABSOLUTE } from './sketch' export function getSketchSegmentFromPathToNode( sketch: Sketch, @@ -107,18 +110,33 @@ export function isSketchVariablesLinked( const { init } = secondaryVarDec if ( !init || - !(init.type === 'CallExpression' || init.type === 'PipeExpression') + !( + init.type === 'CallExpression' || + init.type === 'CallExpressionKw' || + init.type === 'PipeExpression' + ) ) return false const firstCallExp = // first in pipe expression or just the call expression - init?.type === 'CallExpression' ? init : (init?.body[0] as CallExpression) + init?.type === 'PipeExpression' + ? (init?.body[0] as CallExpression | CallExpressionKw) + : init if ( !firstCallExp || !toolTips.includes(firstCallExp?.callee?.name as ToolTip) ) return false // convention for sketch fns is that the second argument is the sketch - const secondArg = firstCallExp?.arguments[1] + // This is not the convention for kw arg calls, so, TODO at some point, + // rename this var. + const secondArg = (() => { + switch (firstCallExp.type) { + case 'CallExpression': + return firstCallExp?.arguments[1] + case 'CallExpressionKw': + return findKwArgAny([ARG_END, ARG_END_ABSOLUTE], firstCallExp) + } + })() if (!secondArg || secondArg?.type !== 'Identifier') return false if (secondArg.name === primaryVarDec?.id?.name) return true