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