1- import {
2- SemanticError ,
3- SemanticWarning ,
4- SyntaxError ,
5- } from "@mpeggroup/mpeg-sdl-parser" ;
1+ import { SemanticError , SemanticWarning , SyntaxError } from "@mpeggroup/mpeg-sdl-parser" ;
62import { Editor } from "./components/Editor.tsx" ;
73import type { EditorRef } from "./components/Editor.tsx" ;
84import { Navbar } from "./components/Navbar.tsx" ;
@@ -36,12 +32,9 @@ function getInitialCodeFromHash(): string | null {
3632}
3733
3834export function App ( ) {
39- const defaultCode =
40- "// Start typing your SDL here... <Ctrl+Space> for completions\n" ;
35+ const defaultCode = "// Start typing your SDL here... <Ctrl+Space> for completions\n" ;
4136
42- const [ code , setCodeInternal ] = useState < string > (
43- ( ) => getInitialCodeFromHash ( ) ?? defaultCode ,
44- ) ;
37+ const [ code , setCodeInternal ] = useState < string > ( ( ) => getInitialCodeFromHash ( ) ?? defaultCode ) ;
4538
4639 const setCode = useCallback ( ( newCode : string ) => {
4740 setCodeInternal ( newCode ) ;
@@ -62,34 +55,29 @@ export function App() {
6255 const isMobile = useMobileDetection ( ) ;
6356 const [ isSettingsShown , setSettingsShown ] = useState ( false ) ;
6457 const { rulerWidth, setRulerWidth } = useRulerWidth ( ) ;
65- const { autoDisplayCompletions, setAutoDisplayCompletions } =
66- useAutoDisplayCompletions ( ) ;
58+ const { autoDisplayCompletions, setAutoDisplayCompletions } = useAutoDisplayCompletions ( ) ;
6759 const { enableLinting, setEnableLinting } = useEnableLinting ( ) ;
6860 const { showSyntaxErrors, setShowSyntaxErrors } = useShowSyntaxErrors ( ) ;
6961 const { showSemanticErrors, setShowSemanticErrors } = useShowSemanticErrors ( ) ;
70- const { showSemanticWarnings, setShowSemanticWarnings } =
71- useShowSemanticWarnings ( ) ;
72- const [ cursorPosition , setCursorPosition ] = useState <
73- { line : number ; col : number }
74- > ( { line : 1 , col : 1 } ) ;
62+ const { showSemanticWarnings, setShowSemanticWarnings } = useShowSemanticWarnings ( ) ;
63+ const [ cursorPosition , setCursorPosition ] = useState < { line : number ; col : number } > ( {
64+ line : 1 ,
65+ col : 1 ,
66+ } ) ;
7567 const editorRef = useRef < EditorRef > ( null ) ;
7668
77- const onCursorChange = useCallback (
78- ( position : { line : number ; col : number } ) => {
79- setCursorPosition ( ( prev ) => {
80- // Only update if position actually changed
81- if ( prev . line !== position . line || prev . col !== position . col ) {
82- return position ;
83- }
84- return prev ;
85- } ) ;
86- } ,
87- [ ] ,
88- ) ;
69+ const onCursorChange = useCallback ( ( position : { line : number ; col : number } ) => {
70+ setCursorPosition ( ( prev ) => {
71+ // Only update if position actually changed
72+ if ( prev . line !== position . line || prev . col !== position . col ) {
73+ return position ;
74+ }
75+ return prev ;
76+ } ) ;
77+ } , [ ] ) ;
8978 const handleShare = useCallback ( async ( ) => {
9079 const encoded = btoa ( code ) ;
91- const url =
92- `${ globalThis . location . origin } ${ globalThis . location . pathname } #c=${ encoded } ` ;
80+ const url = `${ globalThis . location . origin } ${ globalThis . location . pathname } #c=${ encoded } ` ;
9381 try {
9482 await navigator . clipboard . writeText ( url ) ;
9583 showToast ( "URL copied!" ) ;
@@ -98,11 +86,7 @@ export function App() {
9886 }
9987 } , [ code , showToast ] ) ;
10088
101- const {
102- handleSave,
103- handleLoad,
104- handleCopy,
105- } = useFileOperations ( {
89+ const { handleSave, handleLoad, handleCopy } = useFileOperations ( {
10690 code,
10791 setCode,
10892 showToast,
@@ -113,9 +97,7 @@ export function App() {
11397 const characterCount = useMemo ( ( ) => code . length , [ code ] ) ;
11498 const [ syntaxErrors , setSyntaxErrors ] = useState < SyntaxError [ ] > ( [ ] ) ;
11599 const [ semanticErrors , setSemanticErrors ] = useState < SemanticError [ ] > ( [ ] ) ;
116- const [ semanticWarnings , setSemanticWarnings ] = useState < SemanticWarning [ ] > (
117- [ ] ,
118- ) ;
100+ const [ semanticWarnings , setSemanticWarnings ] = useState < SemanticWarning [ ] > ( [ ] ) ;
119101
120102 const onSyntaxErrorChange = useCallback ( ( newErrors : SyntaxError [ ] ) => {
121103 setSyntaxErrors ( newErrors ) ;
@@ -125,24 +107,15 @@ export function App() {
125107 setSemanticErrors ( newErrors ) ;
126108 } , [ ] ) ;
127109
128- const onSemanticWarningChange = useCallback (
129- ( newErrors : SemanticWarning [ ] ) => {
130- setSemanticWarnings ( newErrors ) ;
131- } ,
132- [ ] ,
133- ) ;
110+ const onSemanticWarningChange = useCallback ( ( newErrors : SemanticWarning [ ] ) => {
111+ setSemanticWarnings ( newErrors ) ;
112+ } , [ ] ) ;
134113
135- const syntaxErrorCount = useMemo ( ( ) => syntaxErrors . length , [
136- syntaxErrors ,
137- ] ) ;
114+ const syntaxErrorCount = useMemo ( ( ) => syntaxErrors . length , [ syntaxErrors ] ) ;
138115
139- const semanticErrorCount = useMemo ( ( ) => semanticErrors . length , [
140- semanticErrors ,
141- ] ) ;
116+ const semanticErrorCount = useMemo ( ( ) => semanticErrors . length , [ semanticErrors ] ) ;
142117
143- const semanticWarningCount = useMemo ( ( ) => semanticWarnings . length , [
144- semanticWarnings ,
145- ] ) ;
118+ const semanticWarningCount = useMemo ( ( ) => semanticWarnings . length , [ semanticWarnings ] ) ;
146119
147120 const { handlePrettify } = usePrettier ( {
148121 code,
@@ -251,8 +224,8 @@ export function App() {
251224 toastState . type === "success"
252225 ? "alert-success"
253226 : toastState . type === "warning"
254- ? "alert-warning"
255- : "alert-error"
227+ ? "alert-warning"
228+ : "alert-error"
256229 } `}
257230 >
258231 < span > { toastState . message } </ span >
0 commit comments