Files
modeling-app/src/lang/modifyAst/deleteSelection.ts
Frank Noirot f30fc376ee Allow deletion of only item in AST (#6335)
* Update test to check for deletion of only operation

* Allow updateEditorWithAstAndWriteToFile to clear AST

* Update src/lang/codeManager.ts

Co-authored-by: Jonathan Tran <jonnytran@gmail.com>

* Weave `isDeleting` through to `deleteSelectionPromise`

* fmt

---------

Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
Co-authored-by: Pierre Jacquier <pierrejacquier39@gmail.com>
2025-04-19 05:27:23 -04:00

54 lines
1.3 KiB
TypeScript

import { executeAstMock } from '@src/lang/langHelpers'
import { updateModelingState } from '@src/lang/modelingWorkflows'
import { deleteFromSelection } from '@src/lang/modifyAst'
import { EXECUTION_TYPE_REAL } from '@src/lib/constants'
import type { Selection } from '@src/lib/selections'
import {
codeManager,
editorManager,
kclManager,
rustContext,
sceneEntitiesManager,
} from '@src/lib/singletons'
import { err } from '@src/lib/trap'
export const deletionErrorMessage =
'Unable to delete selection. Please edit manually in code pane.'
export async function deleteSelectionPromise(
selection: Selection
): Promise<Error | void> {
let ast = kclManager.ast
const modifiedAst = await deleteFromSelection(
ast,
selection,
kclManager.variables,
kclManager.artifactGraph,
sceneEntitiesManager.getFaceDetails
)
if (err(modifiedAst)) {
return new Error(deletionErrorMessage)
}
const testExecute = await executeAstMock({
ast: modifiedAst,
rustContext: rustContext,
})
if (testExecute.errors.length) {
return new Error(deletionErrorMessage)
}
await updateModelingState(
modifiedAst,
EXECUTION_TYPE_REAL,
{
kclManager,
editorManager,
codeManager,
},
{
isDeleting: true,
}
)
}