Selections Refactor (#4381)

* selection stuff

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

* trigger CI

* fix bugs

* some edge cut stuff

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

* trigger CI

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

* fix sketch mode issues

* fix more tests, selection in sketch related

* more test fixing

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

* Trigger ci

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

* Trigger ci

* more sketch mode selection fixes

* fix unit tests

* rename function

* remove .only

* migrate a more selections types

* migrate a more selections types

* migrate a more selections types

* lint

* migrate a more selections types

* migrate a more selections types

* migrate a more selections types

* migrate a more selections types

* migrate a more selections types

* migrate a more selections types

* migrate a more selections types

* migrate a more selections types

* migrate a more selections types

* migrate a more selections types

* fix bad pathToNode issue

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

* fix sketch on face

* migrate a more selections types

* migrate a more selections types

* fix code selection of fillets

* migrate a more selections types

* migrate a more selections types

* migrate a more selections types

* migrate a more selections types

* migrate a more selections types

* fix bad path to node, looks like a race

* migrate a more selections types

* migrate a more selections types

* fix cmd bar selections

* fix cmd bar selections

* fix display issues

* migrate a more selections types

* Revert "migrate a more selections types"

This reverts commit 0d0e453bbb.

* migrate a more selections types

* clean up1

* clean up 2

* fix types after main merge

* review tweaks

* fix wall selection bug

* Update src/lang/std/engineConnection.ts

Co-authored-by: Jonathan Tran <jonnytran@gmail.com>

* add franks TODO comment

* fix type after main merge, plus a touch of clean up

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
This commit is contained in:
Kurt Hutten
2024-11-21 15:04:30 +11:00
committed by GitHub
parent c17cb1067f
commit 59e0df7879
49 changed files with 885 additions and 763 deletions

View File

@ -1,4 +1,4 @@
import { parse, Expr, recast, initPromise } from '../wasm'
import { parse, Expr, recast, initPromise, Program } from '../wasm'
import {
getConstraintType,
getTransformInfos,
@ -9,9 +9,10 @@ import {
getConstraintLevelFromSourceRange,
} from './sketchcombos'
import { ToolTip } from 'lang/langHelpers'
import { Selection, Selections } from 'lib/selections'
import { Selections, Selection } from 'lib/selections'
import { err } from 'lib/trap'
import { enginelessExecutor } from '../../lib/testHelpers'
import { codeRefFromRange } from './artifactGraph'
beforeAll(async () => {
await initPromise
@ -87,10 +88,10 @@ function getConstraintTypeFromSourceHelper2(
}
function makeSelections(
codeBaseSelections: Selections['codeBasedSelections']
graphSelections: Selections['graphSelections']
): Selections {
return {
codeBasedSelections: codeBaseSelections,
graphSelections: graphSelections,
otherSelections: [],
}
}
@ -112,7 +113,11 @@ describe('testing transformAstForSketchLines for equal length constraint', () =>
|> close(%)
`
const selectLine = (script: string, lineNumber: number): Selection => {
const selectLine = (
script: string,
lineNumber: number,
ast: Program
): Selection => {
const lines = script.split('\n')
const codeBeforeLine = lines.slice(0, lineNumber).join('\n').length
const line = lines.find((_, i) => i === lineNumber)
@ -124,14 +129,13 @@ describe('testing transformAstForSketchLines for equal length constraint', () =>
const start = codeBeforeLine + line.indexOf('|> ' + 5)
const range: [number, number] = [start, start]
return {
type: 'default',
range,
codeRef: codeRefFromRange(range, ast),
}
}
async function applyTransformation(
inputCode: string,
selectionRanges: Selections['codeBasedSelections']
selectionRanges: Selections['graphSelections']
) {
const ast = parse(inputCode)
if (err(ast)) return Promise.reject(ast)
@ -157,9 +161,11 @@ describe('testing transformAstForSketchLines for equal length constraint', () =>
}
it(`Should reorder when user selects first-to-last`, async () => {
const selectionRanges: Selections['codeBasedSelections'] = [
selectLine(inputScript, 3),
selectLine(inputScript, 4),
const ast = parse(inputScript)
if (err(ast)) return Promise.reject(ast)
const selectionRanges: Selections['graphSelections'] = [
selectLine(inputScript, 3, ast),
selectLine(inputScript, 4, ast),
]
const newCode = await applyTransformation(inputScript, selectionRanges)
@ -167,9 +173,11 @@ describe('testing transformAstForSketchLines for equal length constraint', () =>
})
it(`Should reorder when user selects last-to-first`, async () => {
const selectionRanges: Selections['codeBasedSelections'] = [
selectLine(inputScript, 4),
selectLine(inputScript, 3),
const ast = parse(inputScript)
if (err(ast)) return Promise.reject(ast)
const selectionRanges: Selections['graphSelections'] = [
selectLine(inputScript, 4, ast),
selectLine(inputScript, 3, ast),
]
const newCode = await applyTransformation(inputScript, selectionRanges)
@ -288,15 +296,14 @@ part001 = startSketchOn('XY')
const ast = parse(inputScript)
if (err(ast)) return Promise.reject(ast)
const selectionRanges: Selections['codeBasedSelections'] = inputScript
const selectionRanges: Selections['graphSelections'] = inputScript
.split('\n')
.filter((ln) => ln.includes('//'))
.map((ln) => {
const comment = ln.split('//')[1]
const start = inputScript.indexOf('//' + comment) - 7
return {
type: 'default',
range: [start, start],
codeRef: codeRefFromRange([start, start], ast),
}
})
@ -379,15 +386,14 @@ part001 = startSketchOn('XY')
const ast = parse(inputScript)
if (err(ast)) return Promise.reject(ast)
const selectionRanges: Selections['codeBasedSelections'] = inputScript
const selectionRanges: Selections['graphSelections'] = inputScript
.split('\n')
.filter((ln) => ln.includes('// select for horizontal constraint'))
.map((ln) => {
const comment = ln.split('//')[1]
const start = inputScript.indexOf('//' + comment) - 7
return {
type: 'default',
range: [start, start],
codeRef: codeRefFromRange([start, start], ast),
}
})
@ -441,15 +447,14 @@ part001 = startSketchOn('XY')
const ast = parse(inputScript)
if (err(ast)) return Promise.reject(ast)
const selectionRanges: Selections['codeBasedSelections'] = inputScript
const selectionRanges: Selections['graphSelections'] = inputScript
.split('\n')
.filter((ln) => ln.includes('// select for vertical constraint'))
.map((ln) => {
const comment = ln.split('//')[1]
const start = inputScript.indexOf('//' + comment) - 7
return {
type: 'default',
range: [start, start],
codeRef: codeRefFromRange([start, start], ast),
}
})
@ -536,7 +541,7 @@ async function helperThing(
const ast = parse(inputScript)
if (err(ast)) return Promise.reject(ast)
const selectionRanges: Selections['codeBasedSelections'] = inputScript
const selectionRanges: Selections['graphSelections'] = inputScript
.split('\n')
.filter((ln) =>
linesOfInterest.some((lineOfInterest) => ln.includes(lineOfInterest))
@ -545,8 +550,7 @@ async function helperThing(
const comment = ln.split('//')[1]
const start = inputScript.indexOf('//' + comment) - 7
return {
type: 'default',
range: [start, start],
codeRef: codeRefFromRange([start, start], ast),
}
})
@ -605,7 +609,7 @@ part001 = startSketchOn('XY')
const ast = parse(code)
const constraintLevels: ConstraintLevel[] = ['full', 'partial', 'free']
constraintLevels.forEach((constraintLevel) => {
const recursivelySeachCommentsAndCheckConstraintLevel = (
const recursivelySearchCommentsAndCheckConstraintLevel = (
str: string,
offset: number = 0
): null => {
@ -622,12 +626,12 @@ part001 = startSketchOn('XY')
throw expectedConstraintLevel
}
expect(expectedConstraintLevel.level).toBe(constraintLevel)
return recursivelySeachCommentsAndCheckConstraintLevel(
return recursivelySearchCommentsAndCheckConstraintLevel(
str,
index + constraintLevel.length
)
}
recursivelySeachCommentsAndCheckConstraintLevel(code)
recursivelySearchCommentsAndCheckConstraintLevel(code)
})
})
})