Move artifact graph out of engine connection (#6062)

* cleanups

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* cleanups

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* fmt

Signed-off-by: Jess Frazelle <github@jessfraz.com>

---------

Signed-off-by: Jess Frazelle <github@jessfraz.com>
This commit is contained in:
Jess Frazelle
2025-03-29 17:25:26 -07:00
committed by GitHub
parent db5ce7ba85
commit 57d78b6094
23 changed files with 229 additions and 247 deletions

View File

@ -1,5 +1,5 @@
import { useModelingContext } from 'hooks/useModelingContext'
import { editorManager, engineCommandManager, kclManager } from 'lib/singletons'
import { editorManager, kclManager } from 'lib/singletons'
import { getNodeFromPath } from 'lang/queryAst'
import { getNodePathFromSourceRange } from 'lang/queryAstNodePathUtils'
import { useEffect, useRef, useState } from 'react'
@ -135,12 +135,10 @@ function DisplayObj({
const range = topLevelRange(obj?.start || 0, obj.end || 0)
const idInfo = codeToIdSelections(
[{ codeRef: codeRefFromRange(range, kclManager.ast) }],
engineCommandManager.artifactGraph,
engineCommandManager.artifactIndex
kclManager.artifactGraph,
kclManager.artifactIndex
)[0]
const artifact = engineCommandManager.artifactGraph.get(
idInfo?.id || ''
)
const artifact = kclManager.artifactGraph.get(idInfo?.id || '')
if (!artifact) return
send({
type: 'Set selection',

View File

@ -1,13 +1,13 @@
import { useMemo } from 'react'
import { engineCommandManager } from 'lib/singletons'
import { kclManager } from 'lib/singletons'
import { expandPlane, PlaneArtifactRich } from 'lang/std/artifactGraph'
import { ArtifactGraph } from 'lang/wasm'
import { DebugDisplayArray, GenericObj } from './DebugDisplayObj'
export function DebugArtifactGraph() {
const artifactGraphTree = useMemo(() => {
return computeTree(engineCommandManager.artifactGraph)
}, [engineCommandManager.artifactGraph])
return computeTree(kclManager.artifactGraph)
}, [kclManager.artifactGraph])
const filterKeys: string[] = ['codeRef', 'pathToNode']
return (

View File

@ -566,7 +566,7 @@ export const ModelingMachineProvider = ({
// See if the selection is "close enough" to be coerced to the plane later
const maybePlane = getPlaneFromArtifact(
selectionRanges.graphSelections[0].artifact,
engineCommandManager.artifactGraph
kclManager.artifactGraph
)
return !err(maybePlane)
}
@ -579,7 +579,7 @@ export const ModelingMachineProvider = ({
return false
}
return !!isCursorInSketchCommandRange(
engineCommandManager.artifactGraph,
kclManager.artifactGraph,
selectionRanges
)
},
@ -841,7 +841,7 @@ export const ModelingMachineProvider = ({
const artifact = selectionRanges.graphSelections[0].artifact
const plane = getPlaneFromArtifact(
artifact,
engineCommandManager.artifactGraph
kclManager.artifactGraph
)
if (err(plane)) return Promise.reject(plane)
// if the user selected a segment, make sure we enter the right sketch as there can be multiple on a plane
@ -917,14 +917,13 @@ export const ModelingMachineProvider = ({
info?.sketchDetails?.faceId || ''
)
const sketchArtifact =
engineCommandManager.artifactGraph.get(mainPath)
const sketchArtifact = kclManager.artifactGraph.get(mainPath)
if (sketchArtifact?.type !== 'path')
return Promise.reject(new Error('No sketch artifact'))
const sketchPaths = getPathsFromArtifact({
artifact: engineCommandManager.artifactGraph.get(plane.id),
artifact: kclManager.artifactGraph.get(plane.id),
sketchPathToNode: sketchArtifact?.codeRef?.pathToNode,
artifactGraph: engineCommandManager.artifactGraph,
artifactGraph: kclManager.artifactGraph,
ast: kclManager.ast,
})
if (err(sketchPaths)) return Promise.reject(sketchPaths)
@ -1743,7 +1742,7 @@ export const ModelingMachineProvider = ({
prompt: input.prompt,
selections: input.selection,
token,
artifactGraph: engineCommandManager.artifactGraph,
artifactGraph: kclManager.artifactGraph,
projectName: context.project.name,
})
}),

View File

@ -13,7 +13,7 @@ import {
getOperationLabel,
stdLibMap,
} from 'lib/operations'
import { editorManager, engineCommandManager, kclManager } from 'lib/singletons'
import { editorManager, kclManager } from 'lib/singletons'
import { ComponentProps, useEffect, useMemo, useRef, useState } from 'react'
import { Operation } from '@rust/kcl-lib/bindings/Operation'
import { Actor, Prop } from 'xstate'
@ -58,7 +58,7 @@ export const FeatureTreePane = () => {
const artifact = context.targetSourceRange
? getArtifactFromRange(
context.targetSourceRange,
engineCommandManager.artifactGraph
kclManager.artifactGraph
)
: null

View File

@ -304,7 +304,7 @@ export const Stream = () => {
}
const path = getArtifactOfTypes(
{ key: entity_id, types: ['path', 'solid2d', 'segment', 'helix'] },
engineCommandManager.artifactGraph
kclManager.artifactGraph
)
if (err(path)) {
return path

View File

@ -16,7 +16,7 @@ import { TransformInfo } from 'lang/std/stdTypes'
import { GetInfoModal, createInfoModal } from '../SetHorVertDistanceModal'
import { createVariableDeclaration } from '../../lang/modifyAst'
import { removeDoubleNegatives } from '../AvailableVarsHelpers'
import { engineCommandManager, kclManager } from 'lib/singletons'
import { kclManager } from 'lib/singletons'
import { err } from 'lib/trap'
import { Node } from '@rust/kcl-lib/bindings/Node'
@ -45,7 +45,7 @@ export function intersectInfo({
selectionRanges.graphSelections.length > 1 &&
isLinesParallelAndConstrained(
kclManager.ast,
engineCommandManager.artifactGraph,
kclManager.artifactGraph,
kclManager.variables,
selectionRanges.graphSelections[0],
selectionRanges.graphSelections[1]