Refactor source ranges into a generic node type (#4350)

* WIP

Signed-off-by: Nick Cameron <nrc@ncameron.org>

* Fix formatting

* Fix yarn build:wasm

* Fix ts_rs bindings

* Fix tsc errors

* Fix wasm TS types

* Add minimal failing test

* Rename field to avoid name collisions

* Remove node wrapper around NonCodeMeta

Trying to fix TS unit test errors deserializing JSON AST in Rust.

* Rename Node to BoxNode

* Fix lints

* Fix lint by boxing literals

* Rename UnboxedNode to Node

* Look at this (photo)Graph *in the voice of Nickelback*

* Update docs

* Update snapshots

* initial trait

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* update docs

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* gross hack for TagNode

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* extend gross hack

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* fix EnvRef bullshit

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* Fix to fail parsing when a tag declarator matches a stdlib function name

* Fix test errors after merging main

* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest)

* Confirm

* Change to use simpler map_err

* Add comment

---------

Signed-off-by: Nick Cameron <nrc@ncameron.org>
Signed-off-by: Jess Frazelle <github@jessfraz.com>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Jess Frazelle <github@jessfraz.com>
This commit is contained in:
Jonathan Tran
2024-10-30 16:52:17 -04:00
committed by GitHub
parent 0c6c646fe7
commit 43bec115c0
148 changed files with 12935 additions and 13924 deletions

View File

@ -49,6 +49,7 @@ import {
getSketchSegmentFromSourceRange,
} from './sketchConstraints'
import { getAngle, roundOff, normaliseAngle } from '../../lib/utils'
import { Node } from 'wasm-lib/kcl/bindings/Node'
export type LineInputsType =
| 'xAbsolute'
@ -325,7 +326,7 @@ const setHorzVertDistanceCreateNode =
if (isUndef(refNum) || err(literalArg)) return REF_NUM_ERR
const valueUsedInTransform = roundOff(literalArg - refNum, 2)
let finalValue: Expr = createBinaryExpressionWithUnary([
let finalValue: Node<Expr> = createBinaryExpressionWithUnary([
createSegEnd(referenceSegName, !index),
forceValueUsedInTransform || createLiteral(valueUsedInTransform),
])
@ -1541,7 +1542,7 @@ export function transformSecondarySketchLinesTagFirst({
forceSegName,
forceValueUsedInTransform,
}: {
ast: Program
ast: Node<Program>
selectionRanges: Selections
transformInfos: TransformInfo[]
programMemory: ProgramMemory
@ -1549,7 +1550,7 @@ export function transformSecondarySketchLinesTagFirst({
forceValueUsedInTransform?: BinaryPart
}):
| {
modifiedAst: Program
modifiedAst: Node<Program>
valueUsedInTransform?: number
pathToNodeMap: PathToNodeMap
tagInfo: {
@ -1620,7 +1621,7 @@ export function transformAstSketchLines({
forceValueUsedInTransform,
referencedSegmentRange,
}: {
ast: Program
ast: Node<Program>
selectionRanges: Selections | PathToNode[]
transformInfos: TransformInfo[]
programMemory: ProgramMemory
@ -1629,7 +1630,7 @@ export function transformAstSketchLines({
referencedSegmentRange?: Selection['range']
}):
| {
modifiedAst: Program
modifiedAst: Node<Program>
valueUsedInTransform?: number
pathToNodeMap: PathToNodeMap
}
@ -1647,7 +1648,7 @@ export function transformAstSketchLines({
const getNode = getNodeFromPathCurry(node, _pathToNode)
const callExp = getNode<CallExpression>('CallExpression')
const callExp = getNode<Node<CallExpression>>('CallExpression')
if (err(callExp)) return callExp
const varDec = getNode<VariableDeclarator>('VariableDeclarator')
if (err(varDec)) return varDec
@ -1806,13 +1807,16 @@ function createSegAngle(referenceSegName: string): BinaryPart {
return createCallExpression('segAng', [createIdentifier(referenceSegName)])
}
function createSegEnd(referenceSegName: string, isX: boolean): CallExpression {
function createSegEnd(
referenceSegName: string,
isX: boolean
): Node<CallExpression> {
return createCallExpression(isX ? 'segEndX' : 'segEndY', [
createIdentifier(referenceSegName),
])
}
function createLastSeg(isX: boolean): CallExpression {
function createLastSeg(isX: boolean): Node<CallExpression> {
return createCallExpression(isX ? 'lastSegX' : 'lastSegY', [
createPipeSubstitution(),
])
@ -1830,7 +1834,7 @@ export function getConstraintLevelFromSourceRange(
ast: Program | Error
): Error | { range: [number, number]; level: ConstraintLevel } {
if (err(ast)) return ast
const nodeMeta = getNodeFromPath<CallExpression>(
const nodeMeta = getNodeFromPath<Node<CallExpression>>(
ast,
getNodePathFromSourceRange(ast, cursorRange),
'CallExpression'