UI fix for comment settings collision (#6249)

* UI fix for comment settings collision

* fmt

* Fix tsc by using Promise.reject

---------

Co-authored-by: Frank Noirot <frankjohnson1993@gmail.com>
This commit is contained in:
Kurt Hutten
2025-04-12 00:16:45 +10:00
committed by GitHub
parent c6ec54c138
commit 121c393466
4 changed files with 36 additions and 13 deletions

View File

@ -1180,7 +1180,8 @@ export class SceneEntities {
_ast = pResult.program _ast = pResult.program
// do a quick mock execution to get the program memory up-to-date // do a quick mock execution to get the program memory up-to-date
await this.kclManager.executeAstMock(_ast) const didReParse = await this.kclManager.executeAstMock(_ast)
if (err(didReParse)) return didReParse
const justCreatedNode = getNodeFromPath<VariableDeclaration>( const justCreatedNode = getNodeFromPath<VariableDeclaration>(
_ast, _ast,
@ -1580,7 +1581,8 @@ export class SceneEntities {
_ast = pResult.program _ast = pResult.program
// do a quick mock execution to get the program memory up-to-date // do a quick mock execution to get the program memory up-to-date
await this.kclManager.executeAstMock(_ast) const didReParse = await this.kclManager.executeAstMock(_ast)
if (err(didReParse)) return didReParse
const { truncatedAst } = await this.setupSketch({ const { truncatedAst } = await this.setupSketch({
sketchEntryNodePath: updatedEntryNodePath, sketchEntryNodePath: updatedEntryNodePath,
@ -1775,7 +1777,8 @@ export class SceneEntities {
_ast = pResult.program _ast = pResult.program
// do a quick mock execution to get the program memory up-to-date // do a quick mock execution to get the program memory up-to-date
await this.kclManager.executeAstMock(_ast) const didReParse = await this.kclManager.executeAstMock(_ast)
if (err(didReParse)) return didReParse
const index = sg.paths.length // because we've added a new segment that's not in the memory yet const index = sg.paths.length // because we've added a new segment that's not in the memory yet
const draftExpressionsIndices = { start: index, end: index } const draftExpressionsIndices = { start: index, end: index }
@ -2002,7 +2005,8 @@ export class SceneEntities {
_ast = pResult.program _ast = pResult.program
// do a quick mock execution to get the program memory up-to-date // do a quick mock execution to get the program memory up-to-date
await this.kclManager.executeAstMock(_ast) const didReParse = await this.kclManager.executeAstMock(_ast)
if (err(didReParse)) return didReParse
const index = sg.paths.length // because we've added a new segment that's not in the memory yet const index = sg.paths.length // because we've added a new segment that's not in the memory yet
const draftExpressionsIndices = { start: index, end: index } const draftExpressionsIndices = { start: index, end: index }
@ -2267,7 +2271,8 @@ export class SceneEntities {
_ast = pResult.program _ast = pResult.program
// do a quick mock execution to get the program memory up-to-date // do a quick mock execution to get the program memory up-to-date
await this.kclManager.executeAstMock(_ast) const didReParse = await this.kclManager.executeAstMock(_ast)
if (err(didReParse)) return didReParse
const { truncatedAst } = await this.setupSketch({ const { truncatedAst } = await this.setupSketch({
sketchEntryNodePath: updatedEntryNodePath, sketchEntryNodePath: updatedEntryNodePath,
@ -2500,7 +2505,10 @@ export class SceneEntities {
addingNewSegmentStatus = 'pending' addingNewSegmentStatus = 'pending'
if (trap(mod)) return if (trap(mod)) return
await this.kclManager.executeAstMock(mod.modifiedAst) const didReParse = await this.kclManager.executeAstMock(
mod.modifiedAst
)
if (err(didReParse)) return
this.tearDownSketch({ removeAxis: false }) this.tearDownSketch({ removeAxis: false })
// eslint-disable-next-line @typescript-eslint/no-floating-promises // eslint-disable-next-line @typescript-eslint/no-floating-promises
this.setupSketch({ this.setupSketch({

View File

@ -760,7 +760,8 @@ export const ModelingMachineProvider = ({
// remove body item at varDecIndex // remove body item at varDecIndex
newAst.body = newAst.body.filter((_, i) => i !== varDecIndex) newAst.body = newAst.body.filter((_, i) => i !== varDecIndex)
await kclManager.executeAstMock(newAst) const didReParse = await kclManager.executeAstMock(newAst)
if (err(didReParse)) return reject(didReParse)
await codeManager.updateEditorWithAstAndWriteToFile(newAst) await codeManager.updateEditorWithAstAndWriteToFile(newAst)
} }
sceneInfra.setCallbacks({ sceneInfra.setCallbacks({
@ -773,6 +774,7 @@ export const ModelingMachineProvider = ({
'animate-to-face': fromPromise(async ({ input }) => { 'animate-to-face': fromPromise(async ({ input }) => {
if (!input) return null if (!input) return null
if (input.type === 'extrudeFace' || input.type === 'offsetPlane') { if (input.type === 'extrudeFace' || input.type === 'offsetPlane') {
const originalCode = codeManager.code
const sketched = const sketched =
input.type === 'extrudeFace' input.type === 'extrudeFace'
? sketchOnExtrudedFace( ? sketchOnExtrudedFace(
@ -791,7 +793,13 @@ export const ModelingMachineProvider = ({
} }
const { modifiedAst, pathToNode: pathToNewSketchNode } = sketched const { modifiedAst, pathToNode: pathToNewSketchNode } = sketched
await kclManager.executeAstMock(modifiedAst) const didReParse = await kclManager.executeAstMock(modifiedAst)
if (err(didReParse)) {
// there was a problem, restore the original code
codeManager.code = originalCode
await kclManager.executeCode()
return reject(didReParse)
}
const id = const id =
input.type === 'extrudeFace' ? input.faceId : input.planeId input.type === 'extrudeFace' ? input.faceId : input.planeId

View File

@ -515,20 +515,21 @@ export class KclManager {
} }
// DO NOT CALL THIS from codemirror ever. // DO NOT CALL THIS from codemirror ever.
async executeAstMock(ast: Program) { async executeAstMock(ast: Program): Promise<null | Error> {
await this.ensureWasmInit() await this.ensureWasmInit()
const newCode = recast(ast) const newCode = recast(ast)
if (err(newCode)) { if (err(newCode)) {
console.error(newCode) console.error(newCode)
return return newCode
} }
const newAst = await this.safeParse(newCode) const newAst = await this.safeParse(newCode)
if (!newAst) { if (!newAst) {
// By clearing the AST we indicate to our callers that there was an issue with execution and // By clearing the AST we indicate to our callers that there was an issue with execution and
// the pre-execution state should be restored. // the pre-execution state should be restored.
this.clearAst() this.clearAst()
return return new Error('failed to re-parse')
} }
this._ast = { ...newAst } this._ast = { ...newAst }
@ -544,6 +545,7 @@ export class KclManager {
this.lastSuccessfulVariables = execState.variables this.lastSuccessfulVariables = execState.variables
this.lastSuccessfulOperations = execState.operations this.lastSuccessfulOperations = execState.operations
} }
return null
} }
cancelAllExecutions() { cancelAllExecutions() {
this._cancelTokens.forEach((_, key) => { this._cancelTokens.forEach((_, key) => {
@ -651,7 +653,8 @@ export class KclManager {
// When we don't re-execute, we still want to update the program // When we don't re-execute, we still want to update the program
// memory with the new ast. So we will hit the mock executor // memory with the new ast. So we will hit the mock executor
// instead.. // instead..
await this.executeAstMock(astWithUpdatedSource) const didReParse = await this.executeAstMock(astWithUpdatedSource)
if (err(didReParse)) return Promise.reject(didReParse)
} }
return { selections: returnVal, newAst: astWithUpdatedSource } return { selections: returnVal, newAst: astWithUpdatedSource }

View File

@ -18,6 +18,7 @@ import {
EXECUTION_TYPE_REAL, EXECUTION_TYPE_REAL,
} from '@src/lib/constants' } from '@src/lib/constants'
import type { Selections } from '@src/lib/selections' import type { Selections } from '@src/lib/selections'
import { err, reject } from '@src/lib/trap'
/** /**
* Updates the complete modeling state: * Updates the complete modeling state:
@ -89,7 +90,10 @@ export async function updateModelingState(
ast: updatedAst.newAst, ast: updatedAst.newAst,
}) })
} else if (executionType === EXECUTION_TYPE_MOCK) { } else if (executionType === EXECUTION_TYPE_MOCK) {
await dependencies.kclManager.executeAstMock(updatedAst.newAst) const didReParse = await dependencies.kclManager.executeAstMock(
updatedAst.newAst
)
if (err(didReParse)) return reject(didReParse)
} else if (executionType === EXECUTION_TYPE_NONE) { } else if (executionType === EXECUTION_TYPE_NONE) {
// No execution. // No execution.
} }