Prompt to edit (#4830)
* initial plumbing for getting the new option into the cmd-bar * start of prompt edit * update AI poll * add spinner * more prompt engineering * add success toast, allowing user's to reject code * select code that changed in prompt to edit * selection in scene should not disappear when opening prompt cmd * tweak * fmt * add tests * some clean up * clean up * fix tests
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
import { executeAst, lintAst } from 'lang/langHelpers'
|
||||
import { Selections } from 'lib/selections'
|
||||
import { handleSelectionBatch, Selections } from 'lib/selections'
|
||||
import {
|
||||
KCLError,
|
||||
complilationErrorsToDiagnostics,
|
||||
@ -28,7 +28,10 @@ import { codeManager, editorManager, sceneInfra } from 'lib/singletons'
|
||||
import { Diagnostic } from '@codemirror/lint'
|
||||
import { markOnce } from 'lib/performance'
|
||||
import { Node } from 'wasm-lib/kcl/bindings/Node'
|
||||
import { EntityType_type } from '@kittycad/lib/dist/types/src/models'
|
||||
import {
|
||||
EntityType_type,
|
||||
ModelingCmdReq_type,
|
||||
} from '@kittycad/lib/dist/types/src/models'
|
||||
|
||||
interface ExecuteArgs {
|
||||
ast?: Node<Program>
|
||||
@ -311,7 +314,7 @@ export class KclManager {
|
||||
// Do not send send scene commands if the program was interrupted, go to clean up
|
||||
if (!isInterrupted) {
|
||||
this.addDiagnostics(await lintAst({ ast: ast }))
|
||||
setSelectionFilterToDefault(execState.memory, this.engineCommandManager)
|
||||
setSelectionFilterToDefault(this.engineCommandManager)
|
||||
|
||||
if (args.zoomToFit) {
|
||||
let zoomObjectId: string | undefined = ''
|
||||
@ -603,8 +606,8 @@ export class KclManager {
|
||||
return Promise.all(thePromises)
|
||||
}
|
||||
/** TODO: this function is hiding unawaited asynchronous work */
|
||||
defaultSelectionFilter() {
|
||||
setSelectionFilterToDefault(this.programMemory, this.engineCommandManager)
|
||||
defaultSelectionFilter(selectionsToRestore?: Selections) {
|
||||
setSelectionFilterToDefault(this.engineCommandManager, selectionsToRestore)
|
||||
}
|
||||
/** TODO: this function is hiding unawaited asynchronous work */
|
||||
setSelectionFilter(filter: EntityType_type[]) {
|
||||
@ -640,25 +643,65 @@ const defaultSelectionFilter: EntityType_type[] = [
|
||||
|
||||
/** TODO: This function is not synchronous but is currently treated as such */
|
||||
function setSelectionFilterToDefault(
|
||||
programMemory: ProgramMemory,
|
||||
engineCommandManager: EngineCommandManager
|
||||
engineCommandManager: EngineCommandManager,
|
||||
selectionsToRestore?: Selections
|
||||
) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
setSelectionFilter(defaultSelectionFilter, engineCommandManager)
|
||||
setSelectionFilter(
|
||||
defaultSelectionFilter,
|
||||
engineCommandManager,
|
||||
selectionsToRestore
|
||||
)
|
||||
}
|
||||
|
||||
/** TODO: This function is not synchronous but is currently treated as such */
|
||||
function setSelectionFilter(
|
||||
filter: EntityType_type[],
|
||||
engineCommandManager: EngineCommandManager
|
||||
engineCommandManager: EngineCommandManager,
|
||||
selectionsToRestore?: Selections
|
||||
) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
engineCommandManager.sendSceneCommand({
|
||||
type: 'modeling_cmd_req',
|
||||
cmd_id: uuidv4(),
|
||||
cmd: {
|
||||
type: 'set_selection_filter',
|
||||
filter,
|
||||
},
|
||||
const { engineEvents } = selectionsToRestore
|
||||
? handleSelectionBatch({
|
||||
selections: selectionsToRestore,
|
||||
})
|
||||
: { engineEvents: undefined }
|
||||
if (!selectionsToRestore || !engineEvents) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
engineCommandManager.sendSceneCommand({
|
||||
type: 'modeling_cmd_req',
|
||||
cmd_id: uuidv4(),
|
||||
cmd: {
|
||||
type: 'set_selection_filter',
|
||||
filter,
|
||||
},
|
||||
})
|
||||
return
|
||||
}
|
||||
const modelingCmd: ModelingCmdReq_type[] = []
|
||||
engineEvents.forEach((event) => {
|
||||
if (event.type === 'modeling_cmd_req') {
|
||||
modelingCmd.push({
|
||||
cmd_id: uuidv4(),
|
||||
cmd: event.cmd,
|
||||
})
|
||||
}
|
||||
})
|
||||
// batch is needed other wise the selection flickers.
|
||||
engineCommandManager
|
||||
.sendSceneCommand({
|
||||
type: 'modeling_cmd_batch_req',
|
||||
batch_id: uuidv4(),
|
||||
requests: [
|
||||
{
|
||||
cmd_id: uuidv4(),
|
||||
cmd: {
|
||||
type: 'set_selection_filter',
|
||||
filter,
|
||||
},
|
||||
},
|
||||
...modelingCmd,
|
||||
],
|
||||
responses: false,
|
||||
})
|
||||
.catch(reportError)
|
||||
}
|
||||
|
Reference in New Issue
Block a user