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