diff --git a/src/App.tsx b/src/App.tsx index 1742b188..8f72b637 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -15,7 +15,7 @@ import { SimulationProvider } from './SimulationContext'; import { simulationMachine } from './simulationMachine'; import { getSourceActor } from './sourceMachine'; import { theme } from './theme'; -import { EditorThemeProvider } from './themeContext'; +import { EditorSettingsProvider } from './editorSettingsContext'; import { useInterpretCanvas } from './useInterpretCanvas'; function App() { @@ -48,7 +48,7 @@ function App() { return ( - + - + ); } diff --git a/src/EditorWithXStateImports.tsx b/src/EditorWithXStateImports.tsx index 42af15be..22d83e26 100644 --- a/src/EditorWithXStateImports.tsx +++ b/src/EditorWithXStateImports.tsx @@ -4,7 +4,7 @@ import { useEffect, useRef } from 'react'; import { themes } from './editor-themes'; import { localCache } from './localCache'; import { SpinnerWithText } from './SpinnerWithText'; -import { useEditorTheme } from './themeContext'; +import { useEditorSettings } from './editorSettingsContext'; import { detectNewImportsToAcquireTypeFor } from './typeAcquisition'; /** @@ -83,14 +83,14 @@ const withTypeAcquisition = ( export const EditorWithXStateImports = ( props: EditorWithXStateImportsProps, ) => { - const editorTheme = useEditorTheme(); + const editorSettings = useEditorSettings(); const editorRef = useRef(null); const definedEditorThemes = useRef(new Set()); useEffect(() => { const editor = editorRef.current; const definedThemes = definedEditorThemes.current; - const theme = editorTheme.theme; + const theme = editorSettings.theme; if (!editor || !definedThemes) { return; @@ -100,8 +100,8 @@ export const EditorWithXStateImports = ( editor.defineTheme(theme, themes[theme]); } editor.setTheme(theme); - localCache.saveEditorTheme(editorTheme.theme); - }, [editorTheme.theme]); + localCache.saveEditorTheme(editorSettings.theme); + }, [editorSettings.theme]); return ( { editorRef.current = monaco.editor; - const theme = editorTheme.theme; + + const theme = editorSettings.theme; monaco.editor.defineTheme(theme, themes[theme]); monaco.editor.setTheme(theme); @@ -132,6 +133,11 @@ export const EditorWithXStateImports = ( )}viz/ts-worker.js`, }); + monaco?.languages.typescript.typescriptDefaults.setDiagnosticsOptions({ + noSemanticValidation: editorSettings.isTypescriptEnabled, + noSyntaxValidation: editorSettings.isTypescriptEnabled, + }); + monaco.languages.typescript.typescriptDefaults.setCompilerOptions({ ...monaco.languages.typescript.typescriptDefaults.getCompilerOptions(), module: monaco.languages.typescript.ModuleKind.CommonJS, diff --git a/src/SettingsPanel.tsx b/src/SettingsPanel.tsx index 1b49863e..3b7e341b 100644 --- a/src/SettingsPanel.tsx +++ b/src/SettingsPanel.tsx @@ -10,9 +10,10 @@ import { Kbd, VStack, Select, + Checkbox, } from '@chakra-ui/react'; import { ThemeName, themes } from './editor-themes'; -import { useEditorTheme } from './themeContext'; +import { useEditorSettings } from './editorSettingsContext'; import { useSimulationMode } from './SimulationContext'; import { getPlatformMetaKeyLabel } from './utils'; @@ -60,21 +61,34 @@ const KeyboardShortcuts = () => ( ); export const SettingsPanel: React.FC = () => { - const editorTheme = useEditorTheme(); + const editorSettings = useEditorSettings(); const simulationMode = useSimulationMode(); return ( {simulationMode === 'visualizing' && } + {simulationMode === 'visualizing' && ( + + + Enable Typescript + + { + editorSettings.setIsTypescriptEnabled(e.target.checked); + }} + > + + )} Editor theme