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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -3,7 +3,6 @@ import type { Name } from '@rust/kcl-lib/bindings/Name'
import {
createArrayExpression,
createCallExpression,
createCallExpressionStdLib,
createLiteral,
createPipeSubstitution,
} from '@src/lang/create'
@ -21,7 +20,7 @@ import {
} from '@src/lang/queryAst'
import { getNodePathFromSourceRange } from '@src/lang/queryAstNodePathUtils'
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 type { Identifier, PathToNode } 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.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', () => {
const openSketch = `sketch001 = startSketchOn(XZ)
|> 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 { getNodePathFromSourceRange } from '@src/lang/queryAstNodePathUtils'
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 {
getConstraintLevelFromSourceRange,
@ -521,10 +521,10 @@ export function isLinesParallelAndConstrained(
ast,
secondaryLine?.codeRef?.range
)
const _secondaryNode = getNodeFromPath<CallExpression | CallExpressionKw>(
const _secondaryNode = getNodeFromPath<CallExpressionKw>(
ast,
secondaryPath,
['CallExpression', 'CallExpressionKw']
['CallExpressionKw']
)
if (err(_secondaryNode)) return _secondaryNode
const secondaryNode = _secondaryNode.node
@ -565,10 +565,7 @@ export function isLinesParallelAndConstrained(
Math.abs(primaryAngle - secondaryAngleAlt) < EPSILON
// is secondary line fully constrain, or has constrain type of 'angle'
const secondaryFirstArg =
secondaryNode.type === 'CallExpression'
? getFirstArg(secondaryNode)
: getArgForEnd(secondaryNode)
const secondaryFirstArg = getArgForEnd(secondaryNode)
if (err(secondaryFirstArg)) return secondaryFirstArg
const isAbsolute = false // ADAM: TODO
@ -677,11 +674,9 @@ export function findUsesOfTagInPipe(
'segEndY',
'segLen',
]
const nodeMeta = getNodeFromPath<CallExpression | CallExpressionKw>(
ast,
pathToNode,
['CallExpression', 'CallExpressionKw']
)
const nodeMeta = getNodeFromPath<CallExpressionKw>(ast, pathToNode, [
'CallExpressionKw',
])
if (err(nodeMeta)) {
console.error(nodeMeta)
return []
@ -689,11 +684,7 @@ export function findUsesOfTagInPipe(
const node = nodeMeta.node
if (node.type !== 'CallExpressionKw' && node.type !== 'CallExpression')
return []
const tagIndex = node.callee.name.name === 'close' ? 1 : 2
const tagParam =
node.type === 'CallExpression'
? node.arguments[tagIndex]
: findKwArg(ARG_TAG, node)
const tagParam = findKwArg(ARG_TAG, node)
if (!(tagParam?.type === 'TagDeclarator' || tagParam?.type === 'Name'))
return []
const tag =

View File

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

View File

@ -3,7 +3,6 @@ import { type NonCodeMeta } from '@rust/kcl-lib/bindings/NonCodeMeta'
import {
ARG_ANGLE,
ARG_END,
ARG_END_ABSOLUTE,
ARG_END_ABSOLUTE_X,
ARG_END_ABSOLUTE_Y,
@ -1288,7 +1287,7 @@ const transformMap: TransformMap = {
}
export function getRemoveConstraintsTransform(
sketchFnExp: CallExpression | CallExpressionKw,
sketchFnExp: CallExpressionKw,
constraintType: ConstraintType
): TransformInfo | false {
let name = sketchFnExp.callee.name.name as ToolTip
@ -1335,19 +1334,14 @@ export function getRemoveConstraintsTransform(
) {
return false
}
const isAbsolute =
// isAbsolute doesn't matter if the call is positional.
sketchFnExp.type === 'CallExpression' ? false : isAbsoluteLine(sketchFnExp)
const isAbsolute = isAbsoluteLine(sketchFnExp)
if (err(isAbsolute)) {
console.error(isAbsolute)
return false
}
// check if the function is locked down and so can't be transformed
const firstArg =
sketchFnExp.type === 'CallExpression'
? getFirstArg(sketchFnExp)
: getArgForEnd(sketchFnExp)
const firstArg = getArgForEnd(sketchFnExp)
if (err(firstArg)) {
return false
}
@ -1386,19 +1380,14 @@ export function removeSingleConstraint({
inputDetails: SimplifiedArgDetails
ast: Program
}): TransformInfo | false {
const callExp = getNodeFromPath<CallExpression | CallExpressionKw>(
ast,
pathToCallExp,
['CallExpression', 'CallExpressionKw']
)
const callExp = getNodeFromPath<CallExpressionKw>(ast, pathToCallExp, [
'CallExpressionKw',
])
if (err(callExp)) {
console.error(callExp)
return false
}
if (
callExp.node.type !== 'CallExpression' &&
callExp.node.type !== 'CallExpressionKw'
) {
if (callExp.node.type !== 'CallExpressionKw') {
console.error(new Error('Invalid node type'))
return false
}
@ -1455,51 +1444,6 @@ export function removeSingleConstraint({
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 (
inputToReplace.type === 'arrayInObject' ||
inputToReplace.type === 'objectProperty'
@ -1870,7 +1814,7 @@ export function getRemoveConstraintsTransforms(
}
const node = nodeMeta.node
if (node?.type === 'CallExpression' || node?.type === 'CallExpressionKw') {
if (node?.type === 'CallExpressionKw') {
return getRemoveConstraintsTransform(node, constraintType)
}
@ -2210,7 +2154,7 @@ export function getConstraintLevelFromSourceRange(
const path = getNodePathFromSourceRange(ast, cursorRange)
const nodeMeta = getNodeFromPath<
Node<CallExpression> | Node<CallExpressionKw>
>(ast, path, ['CallExpression', 'CallExpressionKw'])
>(ast, path, ['CallExpressionKw'])
if (err(nodeMeta)) return 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 type {
ArtifactGraph,
CallExpression,
CallExpressionKw,
Expr,
Program,
@ -354,10 +353,10 @@ function updateSceneObjectColors(codeBasedSelections: Selection[]) {
Object.values(sceneEntitiesManager.activeSegments).forEach((segmentGroup) => {
if (!SEGMENT_BODIES_PLUS_PROFILE_START.includes(segmentGroup?.name)) return
const nodeMeta = getNodeFromPath<Node<CallExpression | CallExpressionKw>>(
const nodeMeta = getNodeFromPath<Node<CallExpressionKw>>(
updated,
segmentGroup.userData.pathToNode,
['CallExpression', 'CallExpressionKw']
['CallExpressionKw']
)
if (err(nodeMeta)) return
const node = nodeMeta.node