From 0710f6e5f2c331bfbfa8cea05c7f89dce6e8711d Mon Sep 17 00:00:00 2001 From: Jonathan Tran Date: Fri, 12 Jul 2024 13:08:01 -0400 Subject: [PATCH] Add format code to the command palette (#3001) * Add format code to the command palette * Fix to use renamed groupId parameter * Add icon to format code command * Fix to remove commands during teardown * Fix dependencies * Change formatting --- src/components/CustomIcon.tsx | 10 ++++++++++ src/lang/KclProvider.tsx | 25 +++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/components/CustomIcon.tsx b/src/components/CustomIcon.tsx index 0b69eee8d..440ee62a4 100644 --- a/src/components/CustomIcon.tsx +++ b/src/components/CustomIcon.tsx @@ -131,6 +131,16 @@ const CustomIconMap = { /> ), + code: ( + + + + ), dimension: ( ([]) const [logs, setLogs] = useState([]) const [wasmInitFailed, setWasmInitFailed] = useState(false) + const { commandBarSend } = useCommandsContext() useEffect(() => { codeManager.registerCallBacks({ @@ -50,6 +53,28 @@ export function KclContextProvider({ }) }, []) + // Add format code to command palette. + useEffect(() => { + const commands: Command[] = [ + { + name: 'format-code', + displayName: 'Format Code', + description: 'Nicely formats the KCL code in the editor.', + needsReview: false, + groupId: 'code', + icon: 'code', + onSubmit: (data) => { + kclManager.format() + }, + }, + ] + commandBarSend({ type: 'Add commands', data: { commands } }) + + return () => { + commandBarSend({ type: 'Remove commands', data: { commands } }) + } + }, [kclManager, commandBarSend]) + return (