Fix the 'constrain length' test

This commit is contained in:
Adam Chalmers
2025-01-21 16:55:01 -06:00
committed by Nick Cameron
parent 09df8a734a
commit 8bac097743
3 changed files with 24 additions and 6 deletions

View File

@ -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.

View File

@ -39,7 +39,7 @@ export function angleLengthInfo({
}
| Error {
const nodes = selectionRanges.graphSelections.map(({ codeRef }) =>
getNodeFromPath<Expr>(kclManager.ast, codeRef.pathToNode, 'CallExpression')
getNodeFromPath<Expr>(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)
)
})

View File

@ -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