asyncronise executor (#115)
* Intital async of executor The execture now sends websocket message instead of calling functions directly from the engine, When it does so it holds onto the id. The engine is still returning geo/polys directly but I'm working make it so that the UI doesn't need to know about that, so that we can switch over the streaming ui. Things left to do: - it is still making both direct function calls and websockets, and the former should be removed. - It does highlighting of segments and sourceRanges not through websockets and that needs to be fixed. - Tests have not been adjusted for these changes. - Selecting the head of a segment is not working correctly again yet. * Rough engine prep changes (#135) * rough changes for engine prep * mouse movements working again * connect to engine for startsketch, line, close and extrude
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
import { abstractSyntaxTree } from '../abstractSyntaxTree'
|
||||
import { executor, SketchGroup } from '../executor'
|
||||
import { SketchGroup } from '../executor'
|
||||
import { lexer } from '../tokeniser'
|
||||
import {
|
||||
ConstraintType,
|
||||
@ -10,11 +10,12 @@ import { recast } from '../recast'
|
||||
import { initPromise } from '../rust'
|
||||
import { getSketchSegmentFromSourceRange } from './sketchConstraints'
|
||||
import { Selection } from '../../useStore'
|
||||
import { executor } from '../../lib/testHelpers'
|
||||
|
||||
beforeAll(() => initPromise)
|
||||
|
||||
// testing helper function
|
||||
function testingSwapSketchFnCall({
|
||||
async function testingSwapSketchFnCall({
|
||||
inputCode,
|
||||
callToSwap,
|
||||
constraintType,
|
||||
@ -22,10 +23,10 @@ function testingSwapSketchFnCall({
|
||||
inputCode: string
|
||||
callToSwap: string
|
||||
constraintType: ConstraintType
|
||||
}): {
|
||||
}): Promise<{
|
||||
newCode: string
|
||||
originalRange: [number, number]
|
||||
} {
|
||||
}> {
|
||||
const startIndex = inputCode.indexOf(callToSwap)
|
||||
const range: Selection = {
|
||||
type: 'default',
|
||||
@ -33,7 +34,7 @@ function testingSwapSketchFnCall({
|
||||
}
|
||||
const tokens = lexer(inputCode)
|
||||
const ast = abstractSyntaxTree(tokens)
|
||||
const programMemory = executor(ast)
|
||||
const programMemory = await executor(ast)
|
||||
const selections = {
|
||||
codeBasedSelections: [range],
|
||||
otherSelections: [],
|
||||
@ -94,10 +95,10 @@ describe('testing swaping out sketch calls with xLine/xLineTo', () => {
|
||||
`show(part001)`,
|
||||
]
|
||||
const bigExample = bigExampleArr.join('\n')
|
||||
it('line with tag converts to xLine', () => {
|
||||
it('line with tag converts to xLine', async () => {
|
||||
const callToSwap = "line({ to: [-2.04, -0.7], tag: 'abc2' }, %)"
|
||||
const expectedLine = "xLine({ length: -2.04, tag: 'abc2' }, %)"
|
||||
const { newCode, originalRange } = testingSwapSketchFnCall({
|
||||
const { newCode, originalRange } = await testingSwapSketchFnCall({
|
||||
inputCode: bigExample,
|
||||
callToSwap,
|
||||
constraintType: 'horizontal',
|
||||
@ -106,10 +107,10 @@ describe('testing swaping out sketch calls with xLine/xLineTo', () => {
|
||||
// new line should start at the same place as the old line
|
||||
expect(originalRange[0]).toBe(newCode.indexOf(expectedLine))
|
||||
})
|
||||
it('line w/o tag converts to xLine', () => {
|
||||
it('line w/o tag converts to xLine', async () => {
|
||||
const callToSwap = 'line([0.73, -0.75], %)'
|
||||
const expectedLine = 'xLine(0.73, %)'
|
||||
const { newCode, originalRange } = testingSwapSketchFnCall({
|
||||
const { newCode, originalRange } = await testingSwapSketchFnCall({
|
||||
inputCode: bigExample,
|
||||
callToSwap,
|
||||
constraintType: 'horizontal',
|
||||
@ -118,8 +119,8 @@ describe('testing swaping out sketch calls with xLine/xLineTo', () => {
|
||||
// new line should start at the same place as the old line
|
||||
expect(originalRange[0]).toBe(newCode.indexOf(expectedLine))
|
||||
})
|
||||
it('lineTo with tag converts to xLineTo', () => {
|
||||
const { newCode, originalRange } = testingSwapSketchFnCall({
|
||||
it('lineTo with tag converts to xLineTo', async () => {
|
||||
const { newCode, originalRange } = await testingSwapSketchFnCall({
|
||||
inputCode: bigExample,
|
||||
callToSwap: "lineTo({ to: [1, 1], tag: 'abc1' }, %)",
|
||||
constraintType: 'horizontal',
|
||||
@ -129,8 +130,8 @@ describe('testing swaping out sketch calls with xLine/xLineTo', () => {
|
||||
// new line should start at the same place as the old line
|
||||
expect(originalRange[0]).toBe(newCode.indexOf(expectedLine))
|
||||
})
|
||||
it('lineTo w/o tag converts to xLineTo', () => {
|
||||
const { newCode, originalRange } = testingSwapSketchFnCall({
|
||||
it('lineTo w/o tag converts to xLineTo', async () => {
|
||||
const { newCode, originalRange } = await testingSwapSketchFnCall({
|
||||
inputCode: bigExample,
|
||||
callToSwap: 'lineTo([2.55, 3.58], %)',
|
||||
constraintType: 'horizontal',
|
||||
@ -140,8 +141,8 @@ describe('testing swaping out sketch calls with xLine/xLineTo', () => {
|
||||
// new line should start at the same place as the old line
|
||||
expect(originalRange[0]).toBe(newCode.indexOf(expectedLine))
|
||||
})
|
||||
it('angledLine with tag converts to xLine', () => {
|
||||
const { newCode, originalRange } = testingSwapSketchFnCall({
|
||||
it('angledLine with tag converts to xLine', async () => {
|
||||
const { newCode, originalRange } = await testingSwapSketchFnCall({
|
||||
inputCode: bigExample,
|
||||
callToSwap: [
|
||||
`angledLine({`,
|
||||
@ -157,8 +158,8 @@ describe('testing swaping out sketch calls with xLine/xLineTo', () => {
|
||||
// new line should start at the same place as the old line
|
||||
expect(originalRange[0]).toBe(newCode.indexOf(expectedLine))
|
||||
})
|
||||
it('angledLine w/o tag converts to xLine', () => {
|
||||
const { newCode, originalRange } = testingSwapSketchFnCall({
|
||||
it('angledLine w/o tag converts to xLine', async () => {
|
||||
const { newCode, originalRange } = await testingSwapSketchFnCall({
|
||||
inputCode: bigExample,
|
||||
callToSwap: 'angledLine([63, 1.38], %)',
|
||||
constraintType: 'horizontal',
|
||||
@ -168,8 +169,8 @@ describe('testing swaping out sketch calls with xLine/xLineTo', () => {
|
||||
// new line should start at the same place as the old line
|
||||
expect(originalRange[0]).toBe(newCode.indexOf(expectedLine))
|
||||
})
|
||||
it('angledLineOfXLength with tag converts to xLine', () => {
|
||||
const { newCode, originalRange } = testingSwapSketchFnCall({
|
||||
it('angledLineOfXLength with tag converts to xLine', async () => {
|
||||
const { newCode, originalRange } = await testingSwapSketchFnCall({
|
||||
inputCode: bigExample,
|
||||
callToSwap: [
|
||||
`angledLineOfXLength({`,
|
||||
@ -186,8 +187,8 @@ describe('testing swaping out sketch calls with xLine/xLineTo', () => {
|
||||
// new line should start at the same place as the old line
|
||||
expect(originalRange[0]).toBe(newCode.indexOf(expectedLine))
|
||||
})
|
||||
it('angledLineOfXLength w/o tag converts to xLine', () => {
|
||||
const { newCode, originalRange } = testingSwapSketchFnCall({
|
||||
it('angledLineOfXLength w/o tag converts to xLine', async () => {
|
||||
const { newCode, originalRange } = await testingSwapSketchFnCall({
|
||||
inputCode: bigExample,
|
||||
callToSwap: 'angledLineOfXLength([319, 1.15], %)',
|
||||
constraintType: 'horizontal',
|
||||
@ -197,8 +198,8 @@ describe('testing swaping out sketch calls with xLine/xLineTo', () => {
|
||||
// new line should start at the same place as the old line
|
||||
expect(originalRange[0]).toBe(newCode.indexOf(expectedLine))
|
||||
})
|
||||
it('angledLineOfYLength with tag converts to yLine', () => {
|
||||
const { newCode, originalRange } = testingSwapSketchFnCall({
|
||||
it('angledLineOfYLength with tag converts to yLine', async () => {
|
||||
const { newCode, originalRange } = await testingSwapSketchFnCall({
|
||||
inputCode: bigExample,
|
||||
callToSwap: [
|
||||
`angledLineOfYLength({`,
|
||||
@ -214,8 +215,8 @@ describe('testing swaping out sketch calls with xLine/xLineTo', () => {
|
||||
// new line should start at the same place as the old line
|
||||
expect(originalRange[0]).toBe(newCode.indexOf(expectedLine))
|
||||
})
|
||||
it('angledLineOfYLength w/o tag converts to yLine', () => {
|
||||
const { newCode, originalRange } = testingSwapSketchFnCall({
|
||||
it('angledLineOfYLength w/o tag converts to yLine', async () => {
|
||||
const { newCode, originalRange } = await testingSwapSketchFnCall({
|
||||
inputCode: bigExample,
|
||||
callToSwap: 'angledLineOfYLength([50, 1.35], %)',
|
||||
constraintType: 'vertical',
|
||||
@ -225,8 +226,8 @@ describe('testing swaping out sketch calls with xLine/xLineTo', () => {
|
||||
// new line should start at the same place as the old line
|
||||
expect(originalRange[0]).toBe(newCode.indexOf(expectedLine))
|
||||
})
|
||||
it('angledLineToX with tag converts to xLineTo', () => {
|
||||
const { newCode, originalRange } = testingSwapSketchFnCall({
|
||||
it('angledLineToX with tag converts to xLineTo', async () => {
|
||||
const { newCode, originalRange } = await testingSwapSketchFnCall({
|
||||
inputCode: bigExample,
|
||||
callToSwap: "angledLineToX({ angle: 55, to: -2.89, tag: 'abc6' }, %)",
|
||||
constraintType: 'horizontal',
|
||||
@ -236,8 +237,8 @@ describe('testing swaping out sketch calls with xLine/xLineTo', () => {
|
||||
// new line should start at the same place as the old line
|
||||
expect(originalRange[0]).toBe(newCode.indexOf(expectedLine))
|
||||
})
|
||||
it('angledLineToX w/o tag converts to xLineTo', () => {
|
||||
const { newCode, originalRange } = testingSwapSketchFnCall({
|
||||
it('angledLineToX w/o tag converts to xLineTo', async () => {
|
||||
const { newCode, originalRange } = await testingSwapSketchFnCall({
|
||||
inputCode: bigExample,
|
||||
callToSwap: 'angledLineToX([291, 6.66], %)',
|
||||
constraintType: 'horizontal',
|
||||
@ -247,8 +248,8 @@ describe('testing swaping out sketch calls with xLine/xLineTo', () => {
|
||||
// new line should start at the same place as the old line
|
||||
expect(originalRange[0]).toBe(newCode.indexOf(expectedLine))
|
||||
})
|
||||
it('angledLineToY with tag converts to yLineTo', () => {
|
||||
const { newCode, originalRange } = testingSwapSketchFnCall({
|
||||
it('angledLineToY with tag converts to yLineTo', async () => {
|
||||
const { newCode, originalRange } = await testingSwapSketchFnCall({
|
||||
inputCode: bigExample,
|
||||
callToSwap: "angledLineToY({ angle: 330, to: 2.53, tag: 'abc7' }, %)",
|
||||
constraintType: 'vertical',
|
||||
@ -258,8 +259,8 @@ describe('testing swaping out sketch calls with xLine/xLineTo', () => {
|
||||
// new line should start at the same place as the old line
|
||||
expect(originalRange[0]).toBe(newCode.indexOf(expectedLine))
|
||||
})
|
||||
it('angledLineToY w/o tag converts to yLineTo', () => {
|
||||
const { newCode, originalRange } = testingSwapSketchFnCall({
|
||||
it('angledLineToY w/o tag converts to yLineTo', async () => {
|
||||
const { newCode, originalRange } = await testingSwapSketchFnCall({
|
||||
inputCode: bigExample,
|
||||
callToSwap: 'angledLineToY([228, 2.14], %)',
|
||||
constraintType: 'vertical',
|
||||
@ -294,8 +295,8 @@ describe('testing swaping out sketch calls with xLine/xLineTo while keeping vari
|
||||
`show(part001)`,
|
||||
]
|
||||
const varExample = variablesExampleArr.join('\n')
|
||||
it('line keeps variable when converted to xLine', () => {
|
||||
const { newCode, originalRange } = testingSwapSketchFnCall({
|
||||
it('line keeps variable when converted to xLine', async () => {
|
||||
const { newCode, originalRange } = await testingSwapSketchFnCall({
|
||||
inputCode: varExample,
|
||||
callToSwap: 'line([lineX, 2.13], %)',
|
||||
constraintType: 'horizontal',
|
||||
@ -305,8 +306,8 @@ describe('testing swaping out sketch calls with xLine/xLineTo while keeping vari
|
||||
// new line should start at the same place as the old line
|
||||
expect(originalRange[0]).toBe(newCode.indexOf(expectedLine))
|
||||
})
|
||||
it('lineTo keeps variable when converted to xLineTo', () => {
|
||||
const { newCode, originalRange } = testingSwapSketchFnCall({
|
||||
it('lineTo keeps variable when converted to xLineTo', async () => {
|
||||
const { newCode, originalRange } = await testingSwapSketchFnCall({
|
||||
inputCode: varExample,
|
||||
callToSwap: 'lineTo([lineToX, 2.85], %)',
|
||||
constraintType: 'horizontal',
|
||||
@ -316,8 +317,8 @@ describe('testing swaping out sketch calls with xLine/xLineTo while keeping vari
|
||||
// new line should start at the same place as the old line
|
||||
expect(originalRange[0]).toBe(newCode.indexOf(expectedLine))
|
||||
})
|
||||
it('angledLineOfXLength keeps variable when converted to xLine', () => {
|
||||
const { newCode, originalRange } = testingSwapSketchFnCall({
|
||||
it('angledLineOfXLength keeps variable when converted to xLine', async () => {
|
||||
const { newCode, originalRange } = await testingSwapSketchFnCall({
|
||||
inputCode: varExample,
|
||||
callToSwap: 'angledLineOfXLength([329, angledLineOfXLengthX], %)',
|
||||
constraintType: 'horizontal',
|
||||
@ -327,8 +328,8 @@ describe('testing swaping out sketch calls with xLine/xLineTo while keeping vari
|
||||
// new line should start at the same place as the old line
|
||||
expect(originalRange[0]).toBe(newCode.indexOf(expectedLine))
|
||||
})
|
||||
it('angledLineOfYLength keeps variable when converted to yLine', () => {
|
||||
const { newCode, originalRange } = testingSwapSketchFnCall({
|
||||
it('angledLineOfYLength keeps variable when converted to yLine', async () => {
|
||||
const { newCode, originalRange } = await testingSwapSketchFnCall({
|
||||
inputCode: varExample,
|
||||
callToSwap: 'angledLineOfYLength([222, angledLineOfYLengthY], %)',
|
||||
constraintType: 'vertical',
|
||||
@ -338,8 +339,8 @@ describe('testing swaping out sketch calls with xLine/xLineTo while keeping vari
|
||||
// new line should start at the same place as the old line
|
||||
expect(originalRange[0]).toBe(newCode.indexOf(expectedLine))
|
||||
})
|
||||
it('angledLineToX keeps variable when converted to xLineTo', () => {
|
||||
const { newCode, originalRange } = testingSwapSketchFnCall({
|
||||
it('angledLineToX keeps variable when converted to xLineTo', async () => {
|
||||
const { newCode, originalRange } = await testingSwapSketchFnCall({
|
||||
inputCode: varExample,
|
||||
callToSwap: 'angledLineToX([330, angledLineToXx], %)',
|
||||
constraintType: 'horizontal',
|
||||
@ -349,8 +350,8 @@ describe('testing swaping out sketch calls with xLine/xLineTo while keeping vari
|
||||
// new line should start at the same place as the old line
|
||||
expect(originalRange[0]).toBe(newCode.indexOf(expectedLine))
|
||||
})
|
||||
it('angledLineToY keeps variable when converted to yLineTo', () => {
|
||||
const { newCode, originalRange } = testingSwapSketchFnCall({
|
||||
it('angledLineToY keeps variable when converted to yLineTo', async () => {
|
||||
const { newCode, originalRange } = await testingSwapSketchFnCall({
|
||||
inputCode: varExample,
|
||||
callToSwap: 'angledLineToY([217, angledLineToYy], %)',
|
||||
constraintType: 'vertical',
|
||||
@ -361,14 +362,14 @@ describe('testing swaping out sketch calls with xLine/xLineTo while keeping vari
|
||||
expect(originalRange[0]).toBe(newCode.indexOf(expectedLine))
|
||||
})
|
||||
|
||||
it('trying to convert angledLineToY to xLineTo should not work because of the variable', () => {
|
||||
it('trying to convert angledLineToY to xLineTo should not work because of the variable', async () => {
|
||||
const illegalConvert = () =>
|
||||
testingSwapSketchFnCall({
|
||||
inputCode: varExample,
|
||||
callToSwap: 'angledLineToY([217, angledLineToYy], %)',
|
||||
constraintType: 'horizontal',
|
||||
})
|
||||
expect(illegalConvert).toThrowError()
|
||||
await expect(illegalConvert).rejects.toThrowError('no callback helper')
|
||||
})
|
||||
})
|
||||
|
||||
@ -380,8 +381,8 @@ const part001 = startSketchAt([0, 0.04]) // segment-in-start
|
||||
|> line([2.14, 1.35], %) // normal-segment
|
||||
|> xLine(3.54, %)
|
||||
show(part001)`
|
||||
it('normal case works', () => {
|
||||
const programMemory = executor(abstractSyntaxTree(lexer(code)))
|
||||
it('normal case works', async () => {
|
||||
const programMemory = await executor(abstractSyntaxTree(lexer(code)))
|
||||
const index = code.indexOf('// normal-segment') - 7
|
||||
const { __geoMeta, ...segment } = getSketchSegmentFromSourceRange(
|
||||
programMemory.root['part001'] as SketchGroup,
|
||||
@ -393,8 +394,8 @@ show(part001)`
|
||||
from: [3.48, 0.44],
|
||||
})
|
||||
})
|
||||
it('verify it works when the segment is in the `start` property', () => {
|
||||
const programMemory = executor(abstractSyntaxTree(lexer(code)))
|
||||
it('verify it works when the segment is in the `start` property', async () => {
|
||||
const programMemory = await executor(abstractSyntaxTree(lexer(code)))
|
||||
const index = code.indexOf('// segment-in-start') - 7
|
||||
const { __geoMeta, ...segment } = getSketchSegmentFromSourceRange(
|
||||
programMemory.root['part001'] as SketchGroup,
|
||||
|
Reference in New Issue
Block a user