Merge branch 'main' into kurt-bring-back-multi-profile
This commit is contained in:
@ -1,4 +1,12 @@
|
||||
import { ExecState, Expr, PathToNode, Program, SourceRange } from 'lang/wasm'
|
||||
import {
|
||||
ArtifactCommand,
|
||||
ExecState,
|
||||
Expr,
|
||||
PathToNode,
|
||||
Program,
|
||||
SourceRange,
|
||||
sourceRangeFromRust,
|
||||
} from 'lang/wasm'
|
||||
import { Models } from '@kittycad/lib'
|
||||
import { getNodePathFromSourceRange } from 'lang/queryAst'
|
||||
import { err } from 'lib/trap'
|
||||
@ -151,22 +159,18 @@ type OkWebSocketResponseData = Models['OkWebSocketResponseData_type']
|
||||
export interface ResponseMap {
|
||||
[commandId: string]: OkWebSocketResponseData
|
||||
}
|
||||
export interface OrderedCommand {
|
||||
command: EngineCommand
|
||||
range: SourceRange
|
||||
}
|
||||
|
||||
/** Creates a graph of artifacts from a list of ordered commands and their responses
|
||||
* muting the Map should happen entirely this function, other functions called within
|
||||
* should return data on how to update the map, and not do so directly.
|
||||
*/
|
||||
export function createArtifactGraph({
|
||||
orderedCommands,
|
||||
artifactCommands,
|
||||
responseMap,
|
||||
ast,
|
||||
execStateArtifacts,
|
||||
}: {
|
||||
orderedCommands: Array<OrderedCommand>
|
||||
artifactCommands: Array<ArtifactCommand>
|
||||
responseMap: ResponseMap
|
||||
ast: Node<Program>
|
||||
execStateArtifacts: ExecState['artifacts']
|
||||
@ -176,17 +180,15 @@ export function createArtifactGraph({
|
||||
/** see docstring for {@link getArtifactsToUpdate} as to why this is needed */
|
||||
let currentPlaneId = ''
|
||||
|
||||
orderedCommands.forEach((orderedCommand) => {
|
||||
if (orderedCommand.command?.type === 'modeling_cmd_req') {
|
||||
if (orderedCommand.command.cmd.type === 'enable_sketch_mode') {
|
||||
currentPlaneId = orderedCommand.command.cmd.entity_id
|
||||
}
|
||||
if (orderedCommand.command.cmd.type === 'sketch_mode_disable') {
|
||||
currentPlaneId = ''
|
||||
}
|
||||
for (const artifactCommand of artifactCommands) {
|
||||
if (artifactCommand.command.type === 'enable_sketch_mode') {
|
||||
currentPlaneId = artifactCommand.command.entity_id
|
||||
}
|
||||
if (artifactCommand.command.type === 'sketch_mode_disable') {
|
||||
currentPlaneId = ''
|
||||
}
|
||||
const artifactsToUpdate = getArtifactsToUpdate({
|
||||
orderedCommand,
|
||||
artifactCommand,
|
||||
responseMap,
|
||||
getArtifact: (id: ArtifactId) => myMap.get(id),
|
||||
currentPlaneId,
|
||||
@ -197,7 +199,7 @@ export function createArtifactGraph({
|
||||
const mergedArtifact = mergeArtifacts(myMap.get(id), artifact)
|
||||
myMap.set(id, mergedArtifact)
|
||||
})
|
||||
})
|
||||
}
|
||||
return myMap
|
||||
}
|
||||
|
||||
@ -238,14 +240,14 @@ function mergeArtifacts(
|
||||
* can remove this.
|
||||
*/
|
||||
export function getArtifactsToUpdate({
|
||||
orderedCommand: { command, range },
|
||||
artifactCommand,
|
||||
getArtifact,
|
||||
responseMap,
|
||||
currentPlaneId,
|
||||
ast,
|
||||
execStateArtifacts,
|
||||
}: {
|
||||
orderedCommand: OrderedCommand
|
||||
artifactCommand: ArtifactCommand
|
||||
responseMap: ResponseMap
|
||||
/** Passing in a getter because we don't wan this function to update the map directly */
|
||||
getArtifact: (id: ArtifactId) => Artifact | undefined
|
||||
@ -256,14 +258,12 @@ export function getArtifactsToUpdate({
|
||||
id: ArtifactId
|
||||
artifact: Artifact
|
||||
}> {
|
||||
const range = sourceRangeFromRust(artifactCommand.range)
|
||||
const pathToNode = getNodePathFromSourceRange(ast, range)
|
||||
|
||||
// expect all to be `modeling_cmd_req` as batch commands have
|
||||
// already been expanded before being added to orderedCommands
|
||||
if (command.type !== 'modeling_cmd_req') return []
|
||||
const id = command.cmd_id
|
||||
const id = artifactCommand.cmdId
|
||||
const response = responseMap[id]
|
||||
const cmd = command.cmd
|
||||
const cmd = artifactCommand.command
|
||||
const returnArr: ReturnType<typeof getArtifactsToUpdate> = []
|
||||
if (!response) return returnArr
|
||||
if (cmd.type === 'make_plane' && range[1] !== 0) {
|
||||
@ -1156,8 +1156,8 @@ export function getArtifactFromRange(
|
||||
for (const artifact of artifactGraph.values()) {
|
||||
if ('codeRef' in artifact && artifact.codeRef) {
|
||||
const match =
|
||||
artifact?.codeRef.range[0] === range[0] &&
|
||||
artifact?.codeRef.range[1] === range[1]
|
||||
artifact.codeRef?.range[0] === range[0] &&
|
||||
artifact.codeRef.range[1] === range[1]
|
||||
if (match) return artifact
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user