clean up for face codeRef
This commit is contained in:
@ -100,6 +100,7 @@ import { uuidv4 } from 'lib/utils'
|
||||
import { IndexLoaderData } from 'lib/types'
|
||||
import { Node } from 'wasm-lib/kcl/bindings/Node'
|
||||
import {
|
||||
getFaceCodeRef,
|
||||
getPathsFromArtifact,
|
||||
getPlaneFromArtifact,
|
||||
} from 'lang/std/artifactGraph'
|
||||
@ -832,12 +833,7 @@ export const ModelingMachineProvider = ({
|
||||
ast: kclManager.ast,
|
||||
})
|
||||
if (err(sketchPaths)) return Promise.reject(sketchPaths)
|
||||
let codeRef =
|
||||
'faceCodeRef' in plane && plane.faceCodeRef
|
||||
? plane.faceCodeRef
|
||||
: 'codeRef' in plane && plane.codeRef
|
||||
? plane.codeRef
|
||||
: null
|
||||
let codeRef = getFaceCodeRef(plane)
|
||||
if (!codeRef) return Promise.reject(new Error('No plane codeRef'))
|
||||
// codeRef.pathToNode is not always populated correctly
|
||||
const planeNodePath = getNodePathFromSourceRange(
|
||||
|
@ -19,6 +19,7 @@ import {
|
||||
import { Models } from '@kittycad/lib'
|
||||
import { getNodePathFromSourceRange } from 'lang/queryAstNodePathUtils'
|
||||
import { err } from 'lib/trap'
|
||||
import { Cap, Plane, Wall } from 'wasm-lib/kcl/bindings/Artifact'
|
||||
|
||||
export type { Artifact, ArtifactId, SegmentArtifact } from 'lang/wasm'
|
||||
|
||||
@ -599,12 +600,7 @@ export function getArtifactFromRange(
|
||||
artifactGraph: ArtifactGraph
|
||||
): Artifact | null {
|
||||
for (const artifact of artifactGraph.values()) {
|
||||
const codeRef =
|
||||
'codeRef' in artifact
|
||||
? artifact.codeRef
|
||||
: 'faceCodeRef' in artifact
|
||||
? artifact.faceCodeRef
|
||||
: null
|
||||
const codeRef = getFaceCodeRef(artifact)
|
||||
if (codeRef) {
|
||||
const match =
|
||||
codeRef?.range[0] === range[0] && codeRef.range[1] === range[1]
|
||||
@ -613,3 +609,15 @@ export function getArtifactFromRange(
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
export function getFaceCodeRef(
|
||||
artifact: Artifact | Plane | Wall | Cap
|
||||
): CodeRef | null {
|
||||
if ('faceCodeRef' in artifact) {
|
||||
return artifact.faceCodeRef
|
||||
}
|
||||
if ('codeRef' in artifact) {
|
||||
return artifact.codeRef
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import {
|
||||
LiteralValue,
|
||||
NumericSuffix,
|
||||
} from './wasm'
|
||||
import { filterArtifacts } from 'lang/std/artifactGraph'
|
||||
import { filterArtifacts, getFaceCodeRef } from 'lang/std/artifactGraph'
|
||||
import { isArray, isOverlap } from 'lib/utils'
|
||||
|
||||
/**
|
||||
@ -65,12 +65,7 @@ export function isCursorInSketchCommandRange(
|
||||
{
|
||||
types: ['segment', 'path', 'plane', 'cap', 'wall'],
|
||||
predicate: (artifact) => {
|
||||
const codeRefRange =
|
||||
'codeRef' in artifact
|
||||
? artifact?.codeRef.range
|
||||
: 'faceCodeRef' in artifact
|
||||
? artifact?.faceCodeRef.range
|
||||
: null
|
||||
const codeRefRange = getFaceCodeRef(artifact)?.range
|
||||
return selectionRanges.graphSelections.some(
|
||||
(selection) =>
|
||||
isArray(selection?.codeRef?.range) &&
|
||||
|
@ -40,6 +40,7 @@ import {
|
||||
CodeRef,
|
||||
getCodeRefsByArtifactId,
|
||||
ArtifactId,
|
||||
getFaceCodeRef,
|
||||
} from 'lang/std/artifactGraph'
|
||||
import { Node } from 'wasm-lib/kcl/bindings/Node'
|
||||
import { DefaultPlaneStr } from './planes'
|
||||
@ -613,12 +614,7 @@ export function codeToIdSelections(
|
||||
// TODO #868: loops over all artifacts will become inefficient at a large scale
|
||||
const overlappingEntries = Array.from(engineCommandManager.artifactGraph)
|
||||
.map(([id, artifact]) => {
|
||||
const codeRef =
|
||||
'codeRef' in artifact
|
||||
? artifact.codeRef
|
||||
: 'faceCodeRef' in artifact
|
||||
? artifact.faceCodeRef
|
||||
: null
|
||||
const codeRef = getFaceCodeRef(artifact)
|
||||
if (!codeRef) return null
|
||||
return isOverlap(codeRef.range, selection.range)
|
||||
? {
|
||||
|
Reference in New Issue
Block a user