Clean up vite build warnings (#1332)

* WIP Clean up vite build warnings
Fixes #1014

* Fix lint

* Fix React Hooks dependencies
Clean up, use void when await not straightforward

* Clean up

* Fix missing deconstruction
This commit is contained in:
Pierre Jacquier
2024-01-31 10:17:24 +01:00
committed by GitHub
parent 7d887a1497
commit c1f661ab52
16 changed files with 90 additions and 96 deletions

View File

@ -138,14 +138,14 @@ export function useCalc({
}, [kclManager.ast, kclManager.programMemory, selectionRange])
useEffect(() => {
try {
const execAstAndSetResult = async () => {
const code = `const __result__ = ${value}`
const ast = parse(code)
const _programMem: any = { root: {}, return: null }
availableVarInfo.variables.forEach(({ key, value }) => {
_programMem.root[key] = { type: 'userVal', value, __meta: [] }
})
executeAst({
const { programMemory } = await executeAst({
ast,
engineCommandManager,
defaultPlanes: kclManager.defaultPlanes,
@ -153,23 +153,23 @@ export function useCalc({
programMemoryOverride: JSON.parse(
JSON.stringify(kclManager.programMemory)
),
}).then(({ programMemory }) => {
const resultDeclaration = ast.body.find(
(a) =>
a.type === 'VariableDeclaration' &&
a.declarations?.[0]?.id?.name === '__result__'
)
const init =
resultDeclaration?.type === 'VariableDeclaration' &&
resultDeclaration?.declarations?.[0]?.init
const result = programMemory?.root?.__result__?.value
setCalcResult(typeof result === 'number' ? String(result) : 'NAN')
init && setValueNode(init)
})
} catch (e) {
const resultDeclaration = ast.body.find(
(a) =>
a.type === 'VariableDeclaration' &&
a.declarations?.[0]?.id?.name === '__result__'
)
const init =
resultDeclaration?.type === 'VariableDeclaration' &&
resultDeclaration?.declarations?.[0]?.init
const result = programMemory?.root?.__result__?.value
setCalcResult(typeof result === 'number' ? String(result) : 'NAN')
init && setValueNode(init)
}
execAstAndSetResult().catch(() => {
setCalcResult('NAN')
setValueNode(null)
}
})
}, [value, availableVarInfo])
return {

View File

@ -93,7 +93,7 @@ export const ExportButton = ({ children, className }: ExportButtonProps) => {
if (values.type === 'ply' || values.type === 'stl') {
values.selection = { type: 'default_scene' }
}
engineCommandManager.sendSceneCommand({
void engineCommandManager.sendSceneCommand({
type: 'modeling_cmd_req',
cmd: {
type: 'export',

View File

@ -101,7 +101,7 @@ export const GlobalStateProvider = ({
goToSignInPage: () => {
navigate(paths.SIGN_IN)
logout()
void logout()
},
goToIndexPage: () => {
if (window.location.pathname.includes(paths.SIGN_IN)) {

View File

@ -97,19 +97,19 @@ export const ModelingMachineProvider = ({
'Modify AST': () => {},
'Update code selection cursors': () => {},
'show default planes': () => {
kclManager.showPlanes()
void kclManager.showPlanes()
},
'create path': assign({
sketchEnginePathId: () => {
const sketchUuid = uuidv4()
engineCommandManager.sendSceneCommand({
void engineCommandManager.sendSceneCommand({
type: 'modeling_cmd_req',
cmd_id: sketchUuid,
cmd: {
type: 'start_path',
},
})
engineCommandManager.sendSceneCommand({
void engineCommandManager.sendSceneCommand({
type: 'modeling_cmd_req',
cmd_id: uuidv4(),
cmd: {
@ -177,7 +177,7 @@ export const ModelingMachineProvider = ({
raw: {} as any,
}
kclManager.executeAstMock(astWithUpdatedSource, true)
void kclManager.executeAstMock(astWithUpdatedSource, true)
return {
sketchPathToNode: _pathToNode,
@ -228,7 +228,7 @@ export const ModelingMachineProvider = ({
pathToNode: sketchPathToNode,
})
const _modifiedAst = newSketchLn.modifiedAst
kclManager.executeAstMock(_modifiedAst, true).then(() => {
void kclManager.executeAstMock(_modifiedAst, true).then(() => {
const lineCallExp = getNodeFromPath<CallExpression>(
kclManager.ast,
newSketchLn.pathToNode
@ -249,22 +249,22 @@ export const ModelingMachineProvider = ({
programMemory: kclManager.programMemory,
pathToNode: sketchPathToNode,
})
engineCommandManager.sendSceneCommand({
void engineCommandManager.sendSceneCommand({
type: 'modeling_cmd_req',
cmd_id: uuidv4(),
cmd: { type: 'edit_mode_exit' },
})
engineCommandManager.sendSceneCommand({
void engineCommandManager.sendSceneCommand({
type: 'modeling_cmd_req',
cmd_id: uuidv4(),
cmd: { type: 'default_camera_disable_sketch_mode' },
})
kclManager.executeAstMock(_modifiedAst, true)
void kclManager.executeAstMock(_modifiedAst, true)
// updateAst(_modifiedAst, true)
}
},
'sketch exit execute': () => {
kclManager.executeAst()
void kclManager.executeAst()
},
'set tool': () => {}, // TODO
'Set selection': assign(({ selectionRanges }, event) => {

View File

@ -91,7 +91,7 @@ export const Stream = ({ className = '' }) => {
) {
return
}
engineCommandManager.sendSceneCommand({
void engineCommandManager.sendSceneCommand({
type: 'modeling_cmd_req',
cmd: {
type: 'handle_mouse_drag_start',
@ -100,7 +100,7 @@ export const Stream = ({ className = '' }) => {
cmd_id: newId,
})
} else if (!state.matches('Sketch.Line Tool')) {
engineCommandManager.sendSceneCommand({
void engineCommandManager.sendSceneCommand({
type: 'modeling_cmd_req',
cmd: {
type: 'camera_drag_start',
@ -118,7 +118,7 @@ export const Stream = ({ className = '' }) => {
const fps = 60
const handleScroll: WheelEventHandler<HTMLVideoElement> = throttle((e) => {
if (!cameraMouseDragGuards[cameraControls].zoom.scrollCallback(e)) return
engineCommandManager.sendSceneCommand({
void engineCommandManager.sendSceneCommand({
type: 'modeling_cmd_req',
cmd: {
type: 'default_camera_zoom',
@ -161,13 +161,13 @@ export const Stream = ({ className = '' }) => {
selection_type: 'add',
selected_at_window: { x, y },
}
engineCommandManager.sendSceneCommand(command)
void engineCommandManager.sendSceneCommand(command)
} else if (!didDragInStream && state.matches('Sketch.Line Tool')) {
command.cmd = {
type: 'mouse_click',
window: { x, y },
}
engineCommandManager.sendSceneCommand(command).then(async (resp) => {
void engineCommandManager.sendSceneCommand(command).then(async (resp) => {
const entities_modified = resp?.data?.data?.entities_modified
if (!entities_modified) return
if (state.matches('Sketch.Line Tool.No Points')) {
@ -251,20 +251,20 @@ export const Stream = ({ className = '' }) => {
selection_type: 'add',
}
engineCommandManager.sendSceneCommand(command)
void engineCommandManager.sendSceneCommand(command)
} else if (!didDragInStream && state.matches('Sketch.Move Tool')) {
command.cmd = {
type: 'select_with_point',
selected_at_window: { x, y },
selection_type: 'add',
}
engineCommandManager.sendSceneCommand(command)
void engineCommandManager.sendSceneCommand(command)
} else if (didDragInStream && state.matches('Sketch.Move Tool')) {
command.cmd = {
type: 'handle_mouse_drag_end',
window: { x, y },
}
engineCommandManager.sendSceneCommand(command).then(async () => {
void engineCommandManager.sendSceneCommand(command).then(async () => {
if (!context.sketchPathToNode) return
getNodeFromPath<VariableDeclarator>(
kclManager.ast,
@ -353,10 +353,10 @@ export const Stream = ({ className = '' }) => {
]
}
kclManager.executeAstMock(modifiedAst, true)
void kclManager.executeAstMock(modifiedAst, true)
})
} else {
engineCommandManager.sendSceneCommand(command)
void engineCommandManager.sendSceneCommand(command)
}
setDidDragInStream(false)

View File

@ -76,10 +76,12 @@ export const TextEditor = ({
const fromServer: FromServer = FromServer.create()
const client = new Client(fromServer, intoServer)
if (!TEST) {
Server.initialize(intoServer, fromServer).then((lspServer) => {
lspServer.start()
setIsLSPServerReady(true)
})
Server.initialize(intoServer, fromServer)
.then((lspServer) => {
void lspServer.start()
setIsLSPServerReady(true)
})
.catch((e) => console.log(e))
}
const lspClient = new LanguageServerClient({ client })
@ -151,7 +153,7 @@ export const TextEditor = ({
key: editorShortcutMeta.convertToVariable.codeMirror,
run: () => {
if (convertEnabled) {
convertCallback()
void convertCallback()
return true
}
return false