Compare commits

...

2 Commits

Author SHA1 Message Date
cd577ad573 Fix lints 2025-04-27 22:01:00 -05:00
8a96a5d6d7 turn positional or kw into just kw 2025-04-27 21:57:46 -05:00
12 changed files with 52 additions and 191 deletions

View File

@ -22,12 +22,7 @@ import { findUsesOfTagInPipe, getNodeFromPath } from '@src/lang/queryAst'
import { getConstraintInfoKw } from '@src/lang/std/sketch' import { getConstraintInfoKw } from '@src/lang/std/sketch'
import type { ConstrainInfo } from '@src/lang/std/stdTypes' import type { ConstrainInfo } from '@src/lang/std/stdTypes'
import { topLevelRange } from '@src/lang/util' import { topLevelRange } from '@src/lang/util'
import type { import type { CallExpressionKw, Expr, PathToNode } from '@src/lang/wasm'
CallExpression,
CallExpressionKw,
Expr,
PathToNode,
} from '@src/lang/wasm'
import { defaultSourceRange, parse, recast, resultIsOk } from '@src/lang/wasm' import { defaultSourceRange, parse, recast, resultIsOk } from '@src/lang/wasm'
import { cameraMouseDragGuards } from '@src/lib/cameraControls' import { cameraMouseDragGuards } from '@src/lib/cameraControls'
import { import {
@ -530,10 +525,10 @@ const ConstraintSymbol = ({
if (trap(pResult) || !resultIsOk(pResult)) if (trap(pResult) || !resultIsOk(pResult))
return Promise.reject(pResult) return Promise.reject(pResult)
const _node1 = getNodeFromPath<CallExpression | CallExpressionKw>( const _node1 = getNodeFromPath<CallExpressionKw>(
pResult.program, pResult.program,
pathToNode, pathToNode,
['CallExpression', 'CallExpressionKw'], ['CallExpressionKw'],
true true
) )
if (trap(_node1)) return Promise.reject(_node1) if (trap(_node1)) return Promise.reject(_node1)

View File

@ -764,10 +764,10 @@ export class SceneEntities {
) )
let seg: Group let seg: Group
const _node1 = getNodeFromPath<Node<CallExpression | CallExpressionKw>>( const _node1 = getNodeFromPath<Node<CallExpressionKw>>(
maybeModdedAst, maybeModdedAst,
segPathToNode, segPathToNode,
['CallExpression', 'CallExpressionKw'] ['CallExpressionKw']
) )
if (err(_node1)) { if (err(_node1)) {
this.tearDownSketch({ removeAxis: false }) this.tearDownSketch({ removeAxis: false })
@ -2903,16 +2903,15 @@ export class SceneEntities {
Number(nodePathWithCorrectedIndexForTruncatedAst[1][0]) - Number(nodePathWithCorrectedIndexForTruncatedAst[1][0]) -
Number(sketchNodePaths[0][1][0]) Number(sketchNodePaths[0][1][0])
const _node = getNodeFromPath<Node<CallExpression | CallExpressionKw>>( const _node = getNodeFromPath<Node<CallExpressionKw>>(
modifiedAst, modifiedAst,
draftInfo ? nodePathWithCorrectedIndexForTruncatedAst : pathToNode, draftInfo ? nodePathWithCorrectedIndexForTruncatedAst : pathToNode,
['CallExpression', 'CallExpressionKw'] ['CallExpressionKw']
) )
if (trap(_node)) return if (trap(_node)) return
const node = _node.node const node = _node.node
if (node.type !== 'CallExpression' && node.type !== 'CallExpressionKw') if (node.type !== 'CallExpressionKw') return
return
let modded: let modded:
| { | {
@ -3335,12 +3334,11 @@ export class SceneEntities {
if (trap(pResult) || !resultIsOk(pResult)) if (trap(pResult) || !resultIsOk(pResult))
return Promise.reject(pResult) return Promise.reject(pResult)
const updatedAst = pResult.program const updatedAst = pResult.program
const _node = getNodeFromPath< const _node = getNodeFromPath<Node<CallExpressionKw>>(
Node<CallExpression | CallExpressionKw> updatedAst,
>(updatedAst, parent.userData.pathToNode, [ parent.userData.pathToNode,
'CallExpressionKw', ['CallExpressionKw', 'CallExpression']
'CallExpression', )
])
if (trap(_node, { suppress: true })) return if (trap(_node, { suppress: true })) return
const node = _node.node const node = _node.node
this.editorManager.setHighlightRange([ this.editorManager.setHighlightRange([

View File

@ -287,7 +287,7 @@ export function useEngineConnectionSubscriptions() {
>( >(
kclManager.ast, kclManager.ast,
chamferInfo?.segment.codeRef.pathToNode || [], chamferInfo?.segment.codeRef.pathToNode || [],
['CallExpression', 'CallExpressionKw'] ['CallExpressionKw']
) )
if (err(segmentCallExpr)) return null if (err(segmentCallExpr)) return null
if ( if (

View File

@ -427,11 +427,9 @@ export function giveSketchFnCallTag(
| Error { | Error {
const path = getNodePathFromSourceRange(ast, range) const path = getNodePathFromSourceRange(ast, range)
const maybeTag = (() => { const maybeTag = (() => {
const callNode = getNodeFromPath<CallExpression | CallExpressionKw>( const callNode = getNodeFromPath<CallExpressionKw>(ast, path, [
ast, 'CallExpressionKw',
path, ])
['CallExpression', 'CallExpressionKw']
)
if (!err(callNode) && callNode.node.type === 'CallExpressionKw') { if (!err(callNode) && callNode.node.type === 'CallExpressionKw') {
const { node: primaryCallExp } = callNode const { node: primaryCallExp } = callNode
const existingTag = findKwArg(ARG_TAG, primaryCallExp) const existingTag = findKwArg(ARG_TAG, primaryCallExp)

View File

@ -690,11 +690,9 @@ export function sketchOnExtrudedFace(
const { node: oldSketchNode } = _node1 const { node: oldSketchNode } = _node1
const oldSketchName = oldSketchNode.id.name const oldSketchName = oldSketchNode.id.name
const _node2 = getNodeFromPath<CallExpression | CallExpressionKw>( const _node2 = getNodeFromPath<CallExpressionKw>(_node, sketchPathToNode, [
_node, 'CallExpressionKw',
sketchPathToNode, ])
['CallExpression', 'CallExpressionKw']
)
if (err(_node2)) return _node2 if (err(_node2)) return _node2
const { node: expression } = _node2 const { node: expression } = _node2

View File

@ -326,10 +326,10 @@ export function mutateAstWithTagForSketchSegment(
astClone: Node<Program>, astClone: Node<Program>,
pathToSegmentNode: PathToNode pathToSegmentNode: PathToNode
): { modifiedAst: Node<Program>; tag: string } | Error { ): { modifiedAst: Node<Program>; tag: string } | Error {
const segmentNode = getNodeFromPath<CallExpression | CallExpressionKw>( const segmentNode = getNodeFromPath<CallExpressionKw>(
astClone, astClone,
pathToSegmentNode, pathToSegmentNode,
['CallExpression', 'CallExpressionKw'] ['CallExpressionKw']
) )
if (err(segmentNode)) return segmentNode if (err(segmentNode)) return segmentNode
@ -588,21 +588,15 @@ export const hasValidEdgeTreatmentSelection = ({
// selection exists: // selection exists:
for (const selection of selectionRanges.graphSelections) { for (const selection of selectionRanges.graphSelections) {
// check if all selections are in sketchLineHelperMap // check if all selections are in sketchLineHelperMap
const segmentNode = getNodeFromPath< const segmentNode = getNodeFromPath<Node<CallExpressionKw>>(
Node<CallExpression | CallExpressionKw> ast,
>(ast, selection.codeRef.pathToNode, ['CallExpression', 'CallExpressionKw']) selection.codeRef.pathToNode,
['CallExpressionKw']
)
if (err(segmentNode)) return false if (err(segmentNode)) return false
if ( if (!(segmentNode.node.type === 'CallExpressionKw')) return false
!( if (!(segmentNode.node.callee.name.name in sketchLineHelperMapKw))
segmentNode.node.type === 'CallExpression' ||
segmentNode.node.type === 'CallExpressionKw'
)
) {
return false return false
}
if (!(segmentNode.node.callee.name.name in sketchLineHelperMapKw)) {
return false
}
// check if selection is extruded // check if selection is extruded
// TODO: option 1 : extrude is in the sketch pipe // TODO: option 1 : extrude is in the sketch pipe

View File

@ -20,7 +20,6 @@ import {
} from '@src/lang/std/artifactGraph' } from '@src/lang/std/artifactGraph'
import type { import type {
ArtifactGraph, ArtifactGraph,
CallExpression,
CallExpressionKw, CallExpressionKw,
ExpressionStatement, ExpressionStatement,
KclValue, KclValue,
@ -230,10 +229,10 @@ export async function deleteFromSelection(
varDec.node.type === 'CallExpression' || varDec.node.type === 'CallExpression' ||
varDec.node.type === 'CallExpressionKw' varDec.node.type === 'CallExpressionKw'
) { ) {
const callExp = getNodeFromPath<CallExpression | CallExpressionKw>( const callExp = getNodeFromPath<CallExpressionKw>(
astClone, astClone,
pathToNode, pathToNode,
['CallExpression', 'CallExpressionKw'] ['CallExpressionKw']
) )
if (err(callExp)) return callExp if (err(callExp)) return callExp
extrudeNameToDelete = callExp.node.callee.name.name extrudeNameToDelete = callExp.node.callee.name.name

View File

@ -3,7 +3,6 @@ import type { Name } from '@rust/kcl-lib/bindings/Name'
import { import {
createArrayExpression, createArrayExpression,
createCallExpression, createCallExpression,
createCallExpressionStdLib,
createLiteral, createLiteral,
createPipeSubstitution, createPipeSubstitution,
} from '@src/lang/create' } from '@src/lang/create'
@ -21,7 +20,7 @@ import {
} from '@src/lang/queryAst' } from '@src/lang/queryAst'
import { getNodePathFromSourceRange } from '@src/lang/queryAstNodePathUtils' import { getNodePathFromSourceRange } from '@src/lang/queryAstNodePathUtils'
import { codeRefFromRange } from '@src/lang/std/artifactGraph' import { codeRefFromRange } from '@src/lang/std/artifactGraph'
import { addCallExpressionsToPipe, addCloseToPipe } from '@src/lang/std/sketch' import { addCloseToPipe } from '@src/lang/std/sketch'
import { topLevelRange } from '@src/lang/util' import { topLevelRange } from '@src/lang/util'
import type { Identifier, PathToNode } from '@src/lang/wasm' import type { Identifier, PathToNode } from '@src/lang/wasm'
import { assertParse, recast } from '@src/lang/wasm' import { assertParse, recast } from '@src/lang/wasm'
@ -698,60 +697,6 @@ describe('Testing specific sketch getNodeFromPath workflow', () => {
expect(ast.start).toEqual(0) expect(ast.start).toEqual(0)
expect(ast.end).toEqual(243) expect(ast.end).toEqual(243)
}) })
it('should find the location to add new lineTo', () => {
const openSketch = `sketch001 = startSketchOn(XZ)
|> startProfile(at = [0.02, 0.22])
|> xLine(length = 0.39)
|> line([0.02, -0.17], %)
|> yLine(length = -0.15)
|> line([-0.21, -0.02], %)
|> xLine(length = -0.15)
|> line([-0.02, 0.21], %)
|> line([-0.08, 0.05], %)`
const ast = assertParse(openSketch)
const sketchSnippet = `startProfile(at = [0.02, 0.22])`
const sketchRange = topLevelRange(
openSketch.indexOf(sketchSnippet),
openSketch.indexOf(sketchSnippet) + sketchSnippet.length
)
const sketchPathToNode = getNodePathFromSourceRange(ast, sketchRange)
const modifiedAst = addCallExpressionsToPipe({
node: ast,
variables: {},
pathToNode: sketchPathToNode,
expressions: [
createCallExpressionStdLib(
'lineTo', // We are forcing lineTo!
[
createArrayExpression([
createCallExpressionStdLib('profileStartX', [
createPipeSubstitution(),
]),
createCallExpressionStdLib('profileStartY', [
createPipeSubstitution(),
]),
]),
createPipeSubstitution(),
]
),
],
})
if (err(modifiedAst)) throw modifiedAst
const recasted = recast(modifiedAst)
const expectedCode = `sketch001 = startSketchOn(XZ)
|> startProfile(at = [0.02, 0.22])
|> xLine(length = 0.39)
|> line([0.02, -0.17], %)
|> yLine(length = -0.15)
|> line([-0.21, -0.02], %)
|> xLine(length = -0.15)
|> line([-0.02, 0.21], %)
|> line([-0.08, 0.05], %)
|> lineTo([profileStartX(%), profileStartY(%)], %)
`
expect(recasted).toEqual(expectedCode)
})
it('it should find the location to add close', () => { it('it should find the location to add close', () => {
const openSketch = `sketch001 = startSketchOn(XZ) const openSketch = `sketch001 = startSketchOn(XZ)
|> startProfile(at = [0.02, 0.22]) |> startProfile(at = [0.02, 0.22])

View File

@ -9,7 +9,7 @@ import type { ToolTip } from '@src/lang/langHelpers'
import { splitPathAtLastIndex } from '@src/lang/modifyAst' import { splitPathAtLastIndex } from '@src/lang/modifyAst'
import { getNodePathFromSourceRange } from '@src/lang/queryAstNodePathUtils' import { getNodePathFromSourceRange } from '@src/lang/queryAstNodePathUtils'
import { codeRefFromRange } from '@src/lang/std/artifactGraph' import { codeRefFromRange } from '@src/lang/std/artifactGraph'
import { getArgForEnd, getFirstArg } from '@src/lang/std/sketch' import { getArgForEnd } from '@src/lang/std/sketch'
import { getSketchSegmentFromSourceRange } from '@src/lang/std/sketchConstraints' import { getSketchSegmentFromSourceRange } from '@src/lang/std/sketchConstraints'
import { import {
getConstraintLevelFromSourceRange, getConstraintLevelFromSourceRange,
@ -521,10 +521,10 @@ export function isLinesParallelAndConstrained(
ast, ast,
secondaryLine?.codeRef?.range secondaryLine?.codeRef?.range
) )
const _secondaryNode = getNodeFromPath<CallExpression | CallExpressionKw>( const _secondaryNode = getNodeFromPath<CallExpressionKw>(
ast, ast,
secondaryPath, secondaryPath,
['CallExpression', 'CallExpressionKw'] ['CallExpressionKw']
) )
if (err(_secondaryNode)) return _secondaryNode if (err(_secondaryNode)) return _secondaryNode
const secondaryNode = _secondaryNode.node const secondaryNode = _secondaryNode.node
@ -565,10 +565,7 @@ export function isLinesParallelAndConstrained(
Math.abs(primaryAngle - secondaryAngleAlt) < EPSILON Math.abs(primaryAngle - secondaryAngleAlt) < EPSILON
// is secondary line fully constrain, or has constrain type of 'angle' // is secondary line fully constrain, or has constrain type of 'angle'
const secondaryFirstArg = const secondaryFirstArg = getArgForEnd(secondaryNode)
secondaryNode.type === 'CallExpression'
? getFirstArg(secondaryNode)
: getArgForEnd(secondaryNode)
if (err(secondaryFirstArg)) return secondaryFirstArg if (err(secondaryFirstArg)) return secondaryFirstArg
const isAbsolute = false // ADAM: TODO const isAbsolute = false // ADAM: TODO
@ -677,11 +674,9 @@ export function findUsesOfTagInPipe(
'segEndY', 'segEndY',
'segLen', 'segLen',
] ]
const nodeMeta = getNodeFromPath<CallExpression | CallExpressionKw>( const nodeMeta = getNodeFromPath<CallExpressionKw>(ast, pathToNode, [
ast, 'CallExpressionKw',
pathToNode, ])
['CallExpression', 'CallExpressionKw']
)
if (err(nodeMeta)) { if (err(nodeMeta)) {
console.error(nodeMeta) console.error(nodeMeta)
return [] return []
@ -689,11 +684,7 @@ export function findUsesOfTagInPipe(
const node = nodeMeta.node const node = nodeMeta.node
if (node.type !== 'CallExpressionKw' && node.type !== 'CallExpression') if (node.type !== 'CallExpressionKw' && node.type !== 'CallExpression')
return [] return []
const tagIndex = node.callee.name.name === 'close' ? 1 : 2 const tagParam = findKwArg(ARG_TAG, node)
const tagParam =
node.type === 'CallExpression'
? node.arguments[tagIndex]
: findKwArg(ARG_TAG, node)
if (!(tagParam?.type === 'TagDeclarator' || tagParam?.type === 'Name')) if (!(tagParam?.type === 'TagDeclarator' || tagParam?.type === 'Name'))
return [] return []
const tag = const tag =

View File

@ -3250,7 +3250,7 @@ export function addCallExpressionsToPipe({
node: Node<Program> node: Node<Program>
variables: VariableMap variables: VariableMap
pathToNode: PathToNode pathToNode: PathToNode
expressions: Node<CallExpression | CallExpressionKw>[] expressions: Node<CallExpressionKw>[]
}) { }) {
const _node: Node<Program> = structuredClone(node) const _node: Node<Program> = structuredClone(node)
const pipeExpression = getNodeFromPath<Node<PipeExpression>>( const pipeExpression = getNodeFromPath<Node<PipeExpression>>(

View File

@ -3,7 +3,6 @@ import { type NonCodeMeta } from '@rust/kcl-lib/bindings/NonCodeMeta'
import { import {
ARG_ANGLE, ARG_ANGLE,
ARG_END,
ARG_END_ABSOLUTE, ARG_END_ABSOLUTE,
ARG_END_ABSOLUTE_X, ARG_END_ABSOLUTE_X,
ARG_END_ABSOLUTE_Y, ARG_END_ABSOLUTE_Y,
@ -1288,7 +1287,7 @@ const transformMap: TransformMap = {
} }
export function getRemoveConstraintsTransform( export function getRemoveConstraintsTransform(
sketchFnExp: CallExpression | CallExpressionKw, sketchFnExp: CallExpressionKw,
constraintType: ConstraintType constraintType: ConstraintType
): TransformInfo | false { ): TransformInfo | false {
let name = sketchFnExp.callee.name.name as ToolTip let name = sketchFnExp.callee.name.name as ToolTip
@ -1335,19 +1334,14 @@ export function getRemoveConstraintsTransform(
) { ) {
return false return false
} }
const isAbsolute = const isAbsolute = isAbsoluteLine(sketchFnExp)
// isAbsolute doesn't matter if the call is positional.
sketchFnExp.type === 'CallExpression' ? false : isAbsoluteLine(sketchFnExp)
if (err(isAbsolute)) { if (err(isAbsolute)) {
console.error(isAbsolute) console.error(isAbsolute)
return false return false
} }
// check if the function is locked down and so can't be transformed // check if the function is locked down and so can't be transformed
const firstArg = const firstArg = getArgForEnd(sketchFnExp)
sketchFnExp.type === 'CallExpression'
? getFirstArg(sketchFnExp)
: getArgForEnd(sketchFnExp)
if (err(firstArg)) { if (err(firstArg)) {
return false return false
} }
@ -1386,19 +1380,14 @@ export function removeSingleConstraint({
inputDetails: SimplifiedArgDetails inputDetails: SimplifiedArgDetails
ast: Program ast: Program
}): TransformInfo | false { }): TransformInfo | false {
const callExp = getNodeFromPath<CallExpression | CallExpressionKw>( const callExp = getNodeFromPath<CallExpressionKw>(ast, pathToCallExp, [
ast, 'CallExpressionKw',
pathToCallExp, ])
['CallExpression', 'CallExpressionKw']
)
if (err(callExp)) { if (err(callExp)) {
console.error(callExp) console.error(callExp)
return false return false
} }
if ( if (callExp.node.type !== 'CallExpressionKw') {
callExp.node.type !== 'CallExpression' &&
callExp.node.type !== 'CallExpressionKw'
) {
console.error(new Error('Invalid node type')) console.error(new Error('Invalid node type'))
return false return false
} }
@ -1455,51 +1444,6 @@ export function removeSingleConstraint({
noncode noncode
) )
} }
if (inputToReplace.type === 'arrayItem') {
const values = inputs.map((arg) => {
const argExpr = arg.overrideExpr ?? arg.expr
if (
!(
(arg.type === 'arrayItem' || arg.type === 'arrayOrObjItem') &&
arg.index === inputToReplace.index
)
)
return argExpr
const rawArg = rawArgs.find(
(rawValue) =>
(rawValue.type === 'arrayItem' ||
rawValue.type === 'arrayOrObjItem') &&
rawValue.index === inputToReplace.index
)
const literal = rawArg?.overrideExpr ?? rawArg?.expr
return (arg.index === inputToReplace.index && literal) || argExpr
})
if (callExp.node.type === 'CallExpression') {
return createStdlibCallExpression(
callExp.node.callee.name.name as any,
createArrayExpression(values),
tag
)
} else {
// It's a kw call.
const isAbsolute = callExp.node.callee.name.name == 'lineTo'
if (isAbsolute) {
const args = [
createLabeledArg(ARG_END_ABSOLUTE, createArrayExpression(values)),
]
return createStdlibCallExpressionKw('line', args, tag)
} else {
const args = [
createLabeledArg(ARG_END, createArrayExpression(values)),
]
return createStdlibCallExpressionKw(
callExp.node.callee.name.name as ToolTip,
args,
tag
)
}
}
}
if ( if (
inputToReplace.type === 'arrayInObject' || inputToReplace.type === 'arrayInObject' ||
inputToReplace.type === 'objectProperty' inputToReplace.type === 'objectProperty'
@ -1870,7 +1814,7 @@ export function getRemoveConstraintsTransforms(
} }
const node = nodeMeta.node const node = nodeMeta.node
if (node?.type === 'CallExpression' || node?.type === 'CallExpressionKw') { if (node?.type === 'CallExpressionKw') {
return getRemoveConstraintsTransform(node, constraintType) return getRemoveConstraintsTransform(node, constraintType)
} }
@ -2210,7 +2154,7 @@ export function getConstraintLevelFromSourceRange(
const path = getNodePathFromSourceRange(ast, cursorRange) const path = getNodePathFromSourceRange(ast, cursorRange)
const nodeMeta = getNodeFromPath< const nodeMeta = getNodeFromPath<
Node<CallExpression> | Node<CallExpressionKw> Node<CallExpression> | Node<CallExpressionKw>
>(ast, path, ['CallExpression', 'CallExpressionKw']) >(ast, path, ['CallExpressionKw'])
if (err(nodeMeta)) return nodeMeta if (err(nodeMeta)) return nodeMeta
const { node: sketchFnExp } = nodeMeta const { node: sketchFnExp } = nodeMeta

View File

@ -19,7 +19,6 @@ import type { PathToNodeMap } from '@src/lang/std/sketchcombos'
import { isCursorInSketchCommandRange, topLevelRange } from '@src/lang/util' import { isCursorInSketchCommandRange, topLevelRange } from '@src/lang/util'
import type { import type {
ArtifactGraph, ArtifactGraph,
CallExpression,
CallExpressionKw, CallExpressionKw,
Expr, Expr,
Program, Program,
@ -354,10 +353,10 @@ function updateSceneObjectColors(codeBasedSelections: Selection[]) {
Object.values(sceneEntitiesManager.activeSegments).forEach((segmentGroup) => { Object.values(sceneEntitiesManager.activeSegments).forEach((segmentGroup) => {
if (!SEGMENT_BODIES_PLUS_PROFILE_START.includes(segmentGroup?.name)) return if (!SEGMENT_BODIES_PLUS_PROFILE_START.includes(segmentGroup?.name)) return
const nodeMeta = getNodeFromPath<Node<CallExpression | CallExpressionKw>>( const nodeMeta = getNodeFromPath<Node<CallExpressionKw>>(
updated, updated,
segmentGroup.userData.pathToNode, segmentGroup.userData.pathToNode,
['CallExpression', 'CallExpressionKw'] ['CallExpressionKw']
) )
if (err(nodeMeta)) return if (err(nodeMeta)) return
const node = nodeMeta.node const node = nodeMeta.node