Fix edge treatment tests
This commit is contained in:
@ -18,7 +18,7 @@ import {
|
||||
import { err, reportRejection } from 'lib/trap'
|
||||
import { DefaultPlaneStr, getFaceDetails } from 'clientSideScene/sceneEntities'
|
||||
import { getNodeFromPath, getNodePathFromSourceRange } from 'lang/queryAst'
|
||||
import { CallExpression, defaultSourceRange } from 'lang/wasm'
|
||||
import { CallExpression, CallExpressionKw, defaultSourceRange } from 'lang/wasm'
|
||||
import { EdgeCutInfo, ExtrudeFacePlane } from 'machines/modelingMachine'
|
||||
|
||||
export function useEngineConnectionSubscriptions() {
|
||||
@ -239,14 +239,23 @@ export function useEngineConnectionSubscriptions() {
|
||||
}
|
||||
}
|
||||
if (!chamferInfo) return null
|
||||
const segmentCallExpr = getNodeFromPath<CallExpression>(
|
||||
const segmentCallExpr = getNodeFromPath<
|
||||
CallExpression | CallExpressionKw
|
||||
>(
|
||||
kclManager.ast,
|
||||
chamferInfo?.segment.codeRef.pathToNode || [],
|
||||
'CallExpression'
|
||||
['CallExpression', 'CallExpressionKw']
|
||||
)
|
||||
if (err(segmentCallExpr)) return null
|
||||
if (segmentCallExpr.node.type !== 'CallExpression') return null
|
||||
const sketchNodeArgs = segmentCallExpr.node.arguments
|
||||
if (
|
||||
segmentCallExpr.node.type !== 'CallExpression' &&
|
||||
segmentCallExpr.node.type !== 'CallExpressionKw'
|
||||
)
|
||||
return null
|
||||
const sketchNodeArgs =
|
||||
segmentCallExpr.node.type == 'CallExpression'
|
||||
? segmentCallExpr.node.arguments
|
||||
: segmentCallExpr.node.arguments.map((la) => la.arg)
|
||||
const tagDeclarator = sketchNodeArgs.find(
|
||||
({ type }) => type === 'TagDeclarator'
|
||||
)
|
||||
|
||||
@ -12,6 +12,7 @@ import { EXECUTE_AST_INTERRUPT_ERROR_MESSAGE } from 'lib/constants'
|
||||
|
||||
import {
|
||||
CallExpression,
|
||||
CallExpressionKw,
|
||||
clearSceneAndBustCache,
|
||||
emptyExecState,
|
||||
ExecState,
|
||||
@ -455,14 +456,15 @@ export class KclManager {
|
||||
Array.from(this.engineCommandManager.artifactGraph).forEach(
|
||||
([commandId, artifact]) => {
|
||||
if (!('codeRef' in artifact)) return
|
||||
const _node1 = getNodeFromPath<Node<CallExpression>>(
|
||||
const _node1 = getNodeFromPath<Node<CallExpression | CallExpressionKw>>(
|
||||
this.ast,
|
||||
artifact.codeRef.pathToNode,
|
||||
'CallExpression'
|
||||
['CallExpression', 'CallExpressionKw']
|
||||
)
|
||||
if (err(_node1)) return
|
||||
const { node } = _node1
|
||||
if (node.type !== 'CallExpression') return
|
||||
if (node.type !== 'CallExpression' && node.type !== 'CallExpressionKw')
|
||||
return
|
||||
const [oldStart, oldEnd] = artifact.codeRef.range
|
||||
if (oldStart === 0 && oldEnd === 0) return
|
||||
if (oldStart === node.start && oldEnd === node.end) return
|
||||
|
||||
@ -34,7 +34,12 @@ import {
|
||||
ARG_INDEX_FIELD,
|
||||
LABELED_ARG_FIELD,
|
||||
} from './queryAst'
|
||||
import { addTagForSketchOnFace, ARG_TAG, getConstraintInfo } from './std/sketch'
|
||||
import {
|
||||
addTagForSketchOnFace,
|
||||
ARG_TAG,
|
||||
getConstraintInfo,
|
||||
getConstraintInfoKw,
|
||||
} from './std/sketch'
|
||||
import {
|
||||
PathToNodeMap,
|
||||
isLiteralArrayOrStatic,
|
||||
@ -1034,6 +1039,7 @@ export function giveSketchFnCallTag(
|
||||
return { tagDeclarator, isTagExisting }
|
||||
}
|
||||
|
||||
// We've handled CallExpressionKw above, so this has to be positional.
|
||||
const _node1 = getNodeFromPath<CallExpression>(ast, path, 'CallExpression')
|
||||
if (err(_node1)) return _node1
|
||||
const { node: primaryCallExp } = _node1
|
||||
@ -1175,17 +1181,22 @@ export function deleteSegmentFromPipeExpression(
|
||||
dependentRanges.forEach((range) => {
|
||||
const path = getNodePathFromSourceRange(_modifiedAst, range)
|
||||
|
||||
const callExp = getNodeFromPath<Node<CallExpression>>(
|
||||
const callExp = getNodeFromPath<Node<CallExpression | CallExpressionKw>>(
|
||||
_modifiedAst,
|
||||
path,
|
||||
'CallExpression',
|
||||
['CallExpression', 'CallExpressionKw'],
|
||||
true
|
||||
)
|
||||
if (err(callExp)) return callExp
|
||||
|
||||
const constraintInfo = getConstraintInfo(callExp.node, code, path).find(
|
||||
({ sourceRange }) => isOverlap(sourceRange, range)
|
||||
)
|
||||
const constraintInfo =
|
||||
callExp.node.type === 'CallExpression'
|
||||
? getConstraintInfo(callExp.node, code, path).find(({ sourceRange }) =>
|
||||
isOverlap(sourceRange, range)
|
||||
)
|
||||
: getConstraintInfoKw(callExp.node, code, path).find(
|
||||
({ sourceRange }) => isOverlap(sourceRange, range)
|
||||
)
|
||||
if (!constraintInfo) return
|
||||
|
||||
if (!constraintInfo.argPosition) return
|
||||
|
||||
@ -63,18 +63,18 @@ const runGetPathToExtrudeForSegmentSelectionTest = async (
|
||||
function getExtrudeExpression(
|
||||
ast: Program,
|
||||
pathToExtrudeNode: PathToNode
|
||||
): CallExpression | PipeExpression | undefined | Error {
|
||||
): CallExpression | CallExpressionKw | PipeExpression | undefined | Error {
|
||||
if (pathToExtrudeNode.length === 0) return undefined // no extrude node
|
||||
|
||||
const extrudeNodeResult = getNodeFromPath<CallExpression>(
|
||||
ast,
|
||||
pathToExtrudeNode
|
||||
)
|
||||
const extrudeNodeResult = getNodeFromPath<
|
||||
CallExpression | CallExpressionKw
|
||||
>(ast, pathToExtrudeNode)
|
||||
if (err(extrudeNodeResult)) {
|
||||
return extrudeNodeResult
|
||||
}
|
||||
return extrudeNodeResult.node
|
||||
}
|
||||
|
||||
function getExpectedExtrudeExpression(
|
||||
ast: Program,
|
||||
code: string,
|
||||
@ -605,10 +605,10 @@ extrude001 = extrude(sketch001, length = -5)
|
||||
)
|
||||
const pathToNode = getNodePathFromSourceRange(ast, range)
|
||||
if (err(pathToNode)) return
|
||||
const callExp = getNodeFromPath<CallExpression>(
|
||||
const callExp = getNodeFromPath<CallExpression | CallExpressionKw>(
|
||||
ast,
|
||||
pathToNode,
|
||||
'CallExpression'
|
||||
['CallExpression', 'CallExpressionKw']
|
||||
)
|
||||
if (err(callExp)) return
|
||||
const edges = isTagUsedInEdgeTreatment({ ast, callExp: callExp.node })
|
||||
@ -640,7 +640,7 @@ extrude001 = extrude(sketch001, length = -5)
|
||||
const range = topLevelRange(start, start + lineOfInterest.length)
|
||||
const pathToNode = getNodePathFromSourceRange(ast, range)
|
||||
if (err(pathToNode)) return
|
||||
const callExp = getNodeFromPath<CallExpression>(
|
||||
const callExp = getNodeFromPath<CallExpressionKw>(
|
||||
ast,
|
||||
pathToNode,
|
||||
'CallExpression'
|
||||
|
||||
@ -310,10 +310,10 @@ export function mutateAstWithTagForSketchSegment(
|
||||
astClone: Node<Program>,
|
||||
pathToSegmentNode: PathToNode
|
||||
): { modifiedAst: Program; tag: string } | Error {
|
||||
const segmentNode = getNodeFromPath<CallExpression>(
|
||||
const segmentNode = getNodeFromPath<CallExpression | CallExpressionKw>(
|
||||
astClone,
|
||||
pathToSegmentNode,
|
||||
'CallExpression'
|
||||
['CallExpression', 'CallExpressionKw']
|
||||
)
|
||||
if (err(segmentNode)) return segmentNode
|
||||
|
||||
|
||||
@ -26,7 +26,7 @@ import {
|
||||
import { createIdentifier, splitPathAtLastIndex } from './modifyAst'
|
||||
import { getSketchSegmentFromSourceRange } from './std/sketchConstraints'
|
||||
import { getAngle } from '../lib/utils'
|
||||
import { ARG_TAG, getFirstArg } from './std/sketch'
|
||||
import { ARG_TAG, getArgForEnd, getFirstArg } from './std/sketch'
|
||||
import {
|
||||
getConstraintLevelFromSourceRange,
|
||||
getConstraintType,
|
||||
@ -772,10 +772,10 @@ export function isLinesParallelAndConstrained(
|
||||
ast,
|
||||
secondaryLine?.codeRef?.range
|
||||
)
|
||||
const _secondaryNode = getNodeFromPath<CallExpression>(
|
||||
const _secondaryNode = getNodeFromPath<CallExpression | CallExpressionKw>(
|
||||
ast,
|
||||
secondaryPath,
|
||||
'CallExpression'
|
||||
['CallExpression', 'CallExpressionKw']
|
||||
)
|
||||
if (err(_secondaryNode)) return _secondaryNode
|
||||
const secondaryNode = _secondaryNode.node
|
||||
@ -809,7 +809,10 @@ export function isLinesParallelAndConstrained(
|
||||
Math.abs(primaryAngle - secondaryAngleAlt) < EPSILON
|
||||
|
||||
// is secondary line fully constrain, or has constrain type of 'angle'
|
||||
const secondaryFirstArg = getFirstArg(secondaryNode)
|
||||
const secondaryFirstArg =
|
||||
secondaryNode.type === 'CallExpression'
|
||||
? getFirstArg(secondaryNode)
|
||||
: getArgForEnd(secondaryNode)
|
||||
if (err(secondaryFirstArg)) return secondaryFirstArg
|
||||
|
||||
const isAbsolute = false // ADAM: TODO
|
||||
|
||||
@ -2012,7 +2012,10 @@ export function changeSketchArguments(
|
||||
sourceRangeOrPath.type === 'sourceRange'
|
||||
? getNodePathFromSourceRange(_node, sourceRangeOrPath.sourceRange)
|
||||
: sourceRangeOrPath.pathToNode
|
||||
const nodeMeta = getNodeFromPath<CallExpression>(_node, thePath)
|
||||
const nodeMeta = getNodeFromPath<CallExpression | CallExpressionKw>(
|
||||
_node,
|
||||
thePath
|
||||
)
|
||||
if (err(nodeMeta)) return nodeMeta
|
||||
|
||||
const { node: callExpression, shallowPath } = nodeMeta
|
||||
@ -2268,7 +2271,7 @@ export function replaceSketchLine({
|
||||
*/
|
||||
function addTagToChamfer(
|
||||
tagInfo: AddTagInfo,
|
||||
edgeCutMeta: EdgeCutInfo | null
|
||||
edgeCutMeta: EdgeCutInfo
|
||||
):
|
||||
| {
|
||||
modifiedAst: Node<Program>
|
||||
@ -2406,6 +2409,11 @@ export function addTagForSketchOnFace(
|
||||
return addTagKw()(tagInfo)
|
||||
}
|
||||
if (expressionName === 'chamfer') {
|
||||
if (edgeCutMeta === null) {
|
||||
return new Error(
|
||||
'Cannot add tag to chamfer because no edge cut was provided'
|
||||
)
|
||||
}
|
||||
return addTagToChamfer(tagInfo, edgeCutMeta)
|
||||
}
|
||||
if (expressionName in sketchLineHelperMapKw) {
|
||||
|
||||
@ -443,10 +443,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>>(
|
||||
const nodeMeta = getNodeFromPath<Node<CallExpression | CallExpression>>(
|
||||
updated,
|
||||
segmentGroup.userData.pathToNode,
|
||||
'CallExpression'
|
||||
['CallExpression', 'CallExpressionKw']
|
||||
)
|
||||
if (err(nodeMeta)) return
|
||||
const node = nodeMeta.node
|
||||
|
||||
Reference in New Issue
Block a user