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:
Kurt Hutten
2023-06-22 16:43:33 +10:00
committed by GitHub
parent dd3117cf03
commit 2d3c73d46a
39 changed files with 1798 additions and 2443 deletions

View File

@ -10,7 +10,7 @@ import {
} from './sketchcombos'
import { initPromise } from '../rust'
import { Selections, TooTip } from '../../useStore'
import { executor } from '../../lang/executor'
import { executor } from '../../lib/testHelpers'
import { recast } from '../../lang/recast'
beforeAll(() => initPromise)
@ -196,7 +196,7 @@ const part001 = startSketchAt([0, 0])
|> xLine(segLen('seg01', %), %) // ln-xLineTo-free should convert to xLine
|> yLine(segLen('seg01', %), %) // ln-yLineTo-free should convert to yLine
show(part001)`
it('It should transform the ast', () => {
it('It should transform the ast', async () => {
const ast = abstractSyntaxTree(lexer(inputScript))
const selectionRanges: Selections['codeBasedSelections'] = inputScript
.split('\n')
@ -210,7 +210,7 @@ show(part001)`
}
})
const programMemory = executor(ast)
const programMemory = await executor(ast)
const transformInfos = getTransformInfos(
makeSelections(selectionRanges.slice(1)),
ast,
@ -255,7 +255,7 @@ const part001 = startSketchAt([0, 0])
|> angledLineToX([333, myVar3], %) // select for horizontal constraint 10
|> angledLineToY([301, myVar], %) // select for vertical constraint 10
show(part001)`
it('It should transform horizontal lines the ast', () => {
it('It should transform horizontal lines the ast', async () => {
const expectModifiedScript = `const myVar = 2
const myVar2 = 12
const myVar3 = -10
@ -295,7 +295,7 @@ show(part001)`
}
})
const programMemory = executor(ast)
const programMemory = await executor(ast)
const transformInfos = getTransformInfos(
makeSelections(selectionRanges),
ast,
@ -312,7 +312,7 @@ show(part001)`
const newCode = recast(newAst)
expect(newCode).toBe(expectModifiedScript)
})
it('It should transform vertical lines the ast', () => {
it('It should transform vertical lines the ast', async () => {
const expectModifiedScript = `const myVar = 2
const myVar2 = 12
const myVar3 = -10
@ -352,7 +352,7 @@ show(part001)`
}
})
const programMemory = executor(ast)
const programMemory = await executor(ast)
const transformInfos = getTransformInfos(
makeSelections(selectionRanges),
ast,
@ -381,13 +381,13 @@ const part001 = startSketchAt([0, 0])
|> line([myVar, 0.01], %) // xRelative
|> line([0.7, myVar], %) // yRelative
show(part001)`
it('testing for free to horizontal and vertical distance', () => {
const expectedHorizontalCode = helperThing(
it('testing for free to horizontal and vertical distance', async () => {
const expectedHorizontalCode = await helperThing(
inputScript,
['// base selection', '// free'],
'setHorzDistance'
)
const expectedVerticalCode = helperThing(
const expectedVerticalCode = await helperThing(
inputScript,
['// base selection', '// free'],
'setVertDistance'
@ -399,8 +399,8 @@ show(part001)`
`lineTo([1.21, segEndY('seg01', %) + 2.92], %) // free`
)
})
it('testing for xRelative to vertical distance', () => {
const expectedCode = helperThing(
it('testing for xRelative to vertical distance', async () => {
const expectedCode = await helperThing(
inputScript,
['// base selection', '// xRelative'],
'setVertDistance'
@ -410,8 +410,8 @@ show(part001)`
segEndY('seg01', %) + 2.93
], %) // xRelative`)
})
it('testing for yRelative to horizontal distance', () => {
const expectedCode = helperThing(
it('testing for yRelative to horizontal distance', async () => {
const expectedCode = await helperThing(
inputScript,
['// base selection', '// yRelative'],
'setHorzDistance'
@ -424,11 +424,11 @@ show(part001)`
})
})
function helperThing(
async function helperThing(
inputScript: string,
linesOfInterest: string[],
constraint: ConstraintType
): string {
): Promise<string> {
const ast = abstractSyntaxTree(lexer(inputScript))
const selectionRanges: Selections['codeBasedSelections'] = inputScript
.split('\n')
@ -444,7 +444,7 @@ function helperThing(
}
})
const programMemory = executor(ast)
const programMemory = await executor(ast)
const transformInfos = getTransformInfos(
makeSelections(selectionRanges.slice(1)),
ast,