Skip to content

Commit

Permalink
Remove TS artifact graph code
Browse files Browse the repository at this point in the history
  • Loading branch information
jtran committed Jan 15, 2025
1 parent 3d73ee0 commit 177c078
Show file tree
Hide file tree
Showing 11 changed files with 146 additions and 660 deletions.
7 changes: 1 addition & 6 deletions src/lang/KclSingleton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,12 +376,7 @@ export class KclManager {
}
this.ast = { ...ast }
// updateArtifactGraph relies on updated executeState/programMemory
this.engineCommandManager.updateArtifactGraph(
this.ast,
execState.artifactCommands,
execState.artifacts,
execState.artifactGraph
)
this.engineCommandManager.updateArtifactGraph(execState.artifactGraph)
this._executeCallback()
if (!isInterrupted) {
sceneInfra.modelingSend({ type: 'code edit during sketch' })
Expand Down
22 changes: 14 additions & 8 deletions src/lang/getNodePathFromSourceRange.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { getNodePathFromSourceRange, getNodeFromPath } from './queryAst'
import { Identifier, assertParse, initPromise, Parameter } from './wasm'
import {
Identifier,
assertParse,
initPromise,
Parameter,
SourceRange,
} from './wasm'
import { err } from 'lib/trap'

beforeAll(async () => {
Expand All @@ -17,10 +23,10 @@ const sk3 = startSketchAt([0, 0])
`
const subStr = 'lineTo([3, 4], %, $yo)'
const lineToSubstringIndex = code.indexOf(subStr)
const sourceRange: [number, number, boolean] = [
const sourceRange: SourceRange = [
lineToSubstringIndex,
lineToSubstringIndex + subStr.length,
true,
0,
]

const ast = assertParse(code)
Expand All @@ -29,7 +35,7 @@ const sk3 = startSketchAt([0, 0])
if (err(_node)) throw _node
const { node } = _node

expect([node.start, node.end, true]).toEqual(sourceRange)
expect([node.start, node.end, 0]).toEqual(sourceRange)
expect(node.type).toBe('CallExpression')
})
it('gets path right for function definition params', () => {
Expand All @@ -45,10 +51,10 @@ const sk3 = startSketchAt([0, 0])
const b1 = cube([0,0], 10)`
const subStr = 'pos, scale'
const subStrIndex = code.indexOf(subStr)
const sourceRange: [number, number, boolean] = [
const sourceRange: SourceRange = [
subStrIndex,
subStrIndex + 'pos'.length,
true,
0,
]

const ast = assertParse(code)
Expand Down Expand Up @@ -81,10 +87,10 @@ const b1 = cube([0,0], 10)`
const b1 = cube([0,0], 10)`
const subStr = 'scale, 0'
const subStrIndex = code.indexOf(subStr)
const sourceRange: [number, number, boolean] = [
const sourceRange: SourceRange = [
subStrIndex,
subStrIndex + 'scale'.length,
true,
0,
]

const ast = assertParse(code)
Expand Down
76 changes: 39 additions & 37 deletions src/lang/modifyAst.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { assertParse, recast, initPromise, Identifier } from './wasm'
import {
assertParse,
recast,
initPromise,
Identifier,
SourceRange,
} from './wasm'
import {
createLiteral,
createIdentifier,
Expand Down Expand Up @@ -148,11 +154,7 @@ function giveSketchFnCallTagTestHelper(
// making it more of an integration test, but easier to read the test intention is the goal
const ast = assertParse(code)
const start = code.indexOf(searchStr)
const range: [number, number, boolean] = [
start,
start + searchStr.length,
true,
]
const range: SourceRange = [start, start + searchStr.length, 0]
const sketchRes = giveSketchFnCallTag(ast, range)
if (err(sketchRes)) throw sketchRes
const { modifiedAst, tag, isTagExisting } = sketchRes
Expand Down Expand Up @@ -230,7 +232,7 @@ yo2 = hmm([identifierGuy + 5])`
const { modifiedAst } = moveValueIntoNewVariable(
ast,
execState.memory,
[startIndex, startIndex, true],
[startIndex, startIndex, 0],
'newVar'
)
const newCode = recast(modifiedAst)
Expand All @@ -244,7 +246,7 @@ yo2 = hmm([identifierGuy + 5])`
const { modifiedAst } = moveValueIntoNewVariable(
ast,
execState.memory,
[startIndex, startIndex, true],
[startIndex, startIndex, 0],
'newVar'
)
const newCode = recast(modifiedAst)
Expand All @@ -258,7 +260,7 @@ yo2 = hmm([identifierGuy + 5])`
const { modifiedAst } = moveValueIntoNewVariable(
ast,
execState.memory,
[startIndex, startIndex, true],
[startIndex, startIndex, 0],
'newVar'
)
const newCode = recast(modifiedAst)
Expand All @@ -272,7 +274,7 @@ yo2 = hmm([identifierGuy + 5])`
const { modifiedAst } = moveValueIntoNewVariable(
ast,
execState.memory,
[startIndex, startIndex, true],
[startIndex, startIndex, 0],
'newVar'
)
const newCode = recast(modifiedAst)
Expand All @@ -286,7 +288,7 @@ yo2 = hmm([identifierGuy + 5])`
const { modifiedAst } = moveValueIntoNewVariable(
ast,
execState.memory,
[startIndex, startIndex, true],
[startIndex, startIndex, 0],
'newVar'
)
const newCode = recast(modifiedAst)
Expand All @@ -306,17 +308,17 @@ describe('testing sketchOnExtrudedFace', () => {
const ast = assertParse(code)

const segmentSnippet = `line([9.7, 9.19], %)`
const segmentRange: [number, number, boolean] = [
const segmentRange: SourceRange = [
code.indexOf(segmentSnippet),
code.indexOf(segmentSnippet) + segmentSnippet.length,
true,
0,
]
const segmentPathToNode = getNodePathFromSourceRange(ast, segmentRange)
const extrudeSnippet = `extrude(5 + 7, %)`
const extrudeRange: [number, number, boolean] = [
const extrudeRange: SourceRange = [
code.indexOf(extrudeSnippet),
code.indexOf(extrudeSnippet) + extrudeSnippet.length,
true,
0,
]
const extrudePathToNode = getNodePathFromSourceRange(ast, extrudeRange)

Expand Down Expand Up @@ -346,17 +348,17 @@ sketch001 = startSketchOn(part001, seg01)`)
|> extrude(5 + 7, %)`
const ast = assertParse(code)
const segmentSnippet = `close(%)`
const segmentRange: [number, number, boolean] = [
const segmentRange: SourceRange = [
code.indexOf(segmentSnippet),
code.indexOf(segmentSnippet) + segmentSnippet.length,
true,
0,
]
const segmentPathToNode = getNodePathFromSourceRange(ast, segmentRange)
const extrudeSnippet = `extrude(5 + 7, %)`
const extrudeRange: [number, number, boolean] = [
const extrudeRange: SourceRange = [
code.indexOf(extrudeSnippet),
code.indexOf(extrudeSnippet) + extrudeSnippet.length,
true,
0,
]
const extrudePathToNode = getNodePathFromSourceRange(ast, extrudeRange)

Expand Down Expand Up @@ -386,17 +388,17 @@ sketch001 = startSketchOn(part001, seg01)`)
|> extrude(5 + 7, %)`
const ast = assertParse(code)
const sketchSnippet = `startProfileAt([3.58, 2.06], %)`
const sketchRange: [number, number, boolean] = [
const sketchRange: SourceRange = [
code.indexOf(sketchSnippet),
code.indexOf(sketchSnippet) + sketchSnippet.length,
true,
0,
]
const sketchPathToNode = getNodePathFromSourceRange(ast, sketchRange)
const extrudeSnippet = `extrude(5 + 7, %)`
const extrudeRange: [number, number, boolean] = [
const extrudeRange: SourceRange = [
code.indexOf(extrudeSnippet),
code.indexOf(extrudeSnippet) + extrudeSnippet.length,
true,
0,
]
const extrudePathToNode = getNodePathFromSourceRange(ast, extrudeRange)

Expand Down Expand Up @@ -435,17 +437,17 @@ sketch001 = startSketchOn(part001, 'END')`)
part001 = extrude(5 + 7, sketch001)`
const ast = assertParse(code)
const segmentSnippet = `line([4.99, -0.46], %)`
const segmentRange: [number, number, boolean] = [
const segmentRange: SourceRange = [
code.indexOf(segmentSnippet),
code.indexOf(segmentSnippet) + segmentSnippet.length,
true,
0,
]
const segmentPathToNode = getNodePathFromSourceRange(ast, segmentRange)
const extrudeSnippet = `extrude(5 + 7, sketch001)`
const extrudeRange: [number, number, boolean] = [
const extrudeRange: SourceRange = [
code.indexOf(extrudeSnippet),
code.indexOf(extrudeSnippet) + extrudeSnippet.length,
true,
0,
]
const extrudePathToNode = getNodePathFromSourceRange(ast, extrudeRange)

Expand All @@ -471,10 +473,10 @@ describe('Testing deleteSegmentFromPipeExpression', () => {
const ast = assertParse(code)
const execState = await enginelessExecutor(ast)
const lineOfInterest = 'line([306.21, 198.85], %, $a)'
const range: [number, number, boolean] = [
const range: SourceRange = [
code.indexOf(lineOfInterest),
code.indexOf(lineOfInterest) + lineOfInterest.length,
true,
0,
]
const pathToNode = getNodePathFromSourceRange(ast, range)
const modifiedAst = deleteSegmentFromPipeExpression(
Expand Down Expand Up @@ -549,10 +551,10 @@ ${!replace1 ? ` |> ${line}\n` : ''} |> angledLine([-65, ${
const ast = assertParse(code)
const execState = await enginelessExecutor(ast)
const lineOfInterest = line
const range: [number, number, boolean] = [
const range: SourceRange = [
code.indexOf(lineOfInterest),
code.indexOf(lineOfInterest) + lineOfInterest.length,
true,
0,
]
const pathToNode = getNodePathFromSourceRange(ast, range)
const dependentSegments = findUsesOfTagInPipe(ast, pathToNode)
Expand Down Expand Up @@ -638,10 +640,10 @@ describe('Testing removeSingleConstraintInfo', () => {

const execState = await enginelessExecutor(ast)
const lineOfInterest = expectedFinish.split('(')[0] + '('
const range: [number, number, boolean] = [
const range: SourceRange = [
code.indexOf(lineOfInterest) + 1,
code.indexOf(lineOfInterest) + lineOfInterest.length,
true,
0,
]
const pathToNode = getNodePathFromSourceRange(ast, range)
let argPosition: SimplifiedArgDetails
Expand Down Expand Up @@ -692,10 +694,10 @@ describe('Testing removeSingleConstraintInfo', () => {

const execState = await enginelessExecutor(ast)
const lineOfInterest = expectedFinish.split('(')[0] + '('
const range: [number, number, boolean] = [
const range: SourceRange = [
code.indexOf(lineOfInterest) + 1,
code.indexOf(lineOfInterest) + lineOfInterest.length,
true,
0,
]
let argPosition: SimplifiedArgDetails
if (key === 'arrayIndex' && typeof value === 'number') {
Expand Down Expand Up @@ -889,10 +891,10 @@ sketch002 = startSketchOn({
const execState = await enginelessExecutor(ast)

// deleteFromSelection
const range: [number, number, boolean] = [
const range: SourceRange = [
codeBefore.indexOf(lineOfInterest),
codeBefore.indexOf(lineOfInterest) + lineOfInterest.length,
true,
0,
]
const artifact = { type } as Artifact
const newAst = await deleteFromSelection(
Expand Down
Loading

0 comments on commit 177c078

Please sign in to comment.