ArtifactGraph reThink (PART 3) (#3140)

* adjust engine connection to opt out of webRTC connection

* refactor start and test setup

* add env to unit test

* spell config update

* fix beforeAll order bug

* initial integration of new artifact map with tests passing

* remove old artifact map and clean up

* graph artifact map

* have graph commited

* have graph commited

* remove bad file

* install playwright

* fmt

* commit permissions

* typo

* flesh out tests more

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

* multi highlight

* redo image logic

* add in solid 2d data into artifactMap

* fix snapshots

* stabiles graph images

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

* tweak tests

* rename blend to edgeCut

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

* fix playw tests

* start of artifact map rename to graph

* rename file

* rename test

* rename clearup

* comments

* docs

* docs proof read

* few tweaks here and there

* typos

* delete get parent logic

* nit, combine if statements

* remove unused param

* fix silly test bug

* rename surfId to sufaceId

* rename types

* update comments

* add comment

* add extra check

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

* pull out merge artifact function

* update comments

* fix test

* fmt

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
Kurt Hutten
2024-08-03 18:08:51 +10:00
committed by GitHub
parent 7bf6bc3048
commit e5bec2140e
37 changed files with 2285 additions and 587 deletions

View File

@ -1,12 +1,7 @@
import { Selections } from 'lib/selections'
import { Program, PathToNode } from './wasm'
import { getNodeFromPath } from './queryAst'
import {
ArtifactMap,
ArtifactMapCommand,
SegmentArtifact,
StartPathArtifact,
} from 'lang/std/artifactMap'
import { ArtifactGraph, filterArtifacts } from 'lang/std/artifactGraph'
import { isOverlap } from 'lib/utils'
import { err } from 'lib/trap'
@ -51,25 +46,29 @@ export function updatePathToNodeFromMap(
}
export function isCursorInSketchCommandRange(
artifactMap: ArtifactMap,
artifactGraph: ArtifactGraph,
selectionRanges: Selections
): string | false {
const overlappingEntries = Object.entries(artifactMap).filter(
([id, artifact]: [string, ArtifactMapCommand]) =>
selectionRanges.codeBasedSelections.some(
(selection) =>
Array.isArray(selection?.range) &&
Array.isArray(artifact?.range) &&
isOverlap(selection.range, artifact.range) &&
(artifact.type === 'startPath' || artifact.type === 'segment')
)
) as [string, StartPathArtifact | SegmentArtifact][]
const secondEntry = overlappingEntries?.[0]?.[1]
const parentId = secondEntry?.type === 'segment' ? secondEntry.pathId : false
let result = parentId
const overlappingEntries = filterArtifacts(
{
types: ['segment', 'path'],
predicate: (artifact) => {
return selectionRanges.codeBasedSelections.some(
(selection) =>
Array.isArray(selection?.range) &&
Array.isArray(artifact?.codeRef?.range) &&
isOverlap(selection.range, artifact.codeRef.range)
)
},
},
artifactGraph
)
const firstEntry = [...overlappingEntries.values()]?.[0]
const parentId = firstEntry?.type === 'segment' ? firstEntry.pathId : false
return parentId
? parentId
: overlappingEntries.find(
([, artifact]) => artifact.type === 'startPath'
: [...overlappingEntries].find(
([, artifact]) => artifact.type === 'path'
)?.[0] || false
return result
}