diff --git a/code-editor/src/App.tsx b/code-editor/src/App.tsx index e30fbe1..85eac0b 100644 --- a/code-editor/src/App.tsx +++ b/code-editor/src/App.tsx @@ -3,16 +3,33 @@ import { DEFAULT_EDITOR_THEME, DEFAULT_EDITOR_LANGUAGE, } from "@/config"; +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, +} from "@/components/ui/select"; +import { Palette } from "lucide-react"; import * as monaco from "monaco-editor"; import { highlighter } from "@/lib/shiki"; import { Bot, CodeXml } from "lucide-react"; import { shikiToMonaco } from "@shikijs/monaco"; -import { connectToLanguageServer } from "@/lib/lsp"; import { useEffect, useRef, useState } from "react"; +import { SUPPORTED_EDITOR_THEMES } from "@/constants/themes"; import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area"; import { DiffEditor, Editor, Monaco, loader } from "@monaco-editor/react"; +import { SUPPORTED_EDITOR_LANGUAGES_CONFIG } from "@/constants/languages"; +import editorWorker from "monaco-editor/esm/vs/editor/editor.worker?worker"; +import { connectToLanguageServer, SUPPORTED_LSP_LANGUAGES } from "@/lib/lsp"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; +self.MonacoEnvironment = { + getWorker(_, _label) { + return new editorWorker(); + }, +}; + loader.config({ monaco }); function App() { @@ -25,9 +42,12 @@ function App() { if (webSocketRef.current) { webSocketRef.current.close(); } - connectToLanguageServer(language).then((webSocket) => { - webSocketRef.current = webSocket; - }); + + if (language in SUPPORTED_LSP_LANGUAGES) { + connectToLanguageServer(language).then((webSocket) => { + webSocketRef.current = webSocket; + }); + } return () => { if (webSocketRef.current) { @@ -40,32 +60,66 @@ function App() {
- - - - - - +
+ + + + + + +
+ + +
+
@@ -98,9 +152,11 @@ function App() { "*" ); } - connectToLanguageServer(language).then((webSocket) => { - webSocketRef.current = webSocket; - }); + if (language in SUPPORTED_LSP_LANGUAGES) { + connectToLanguageServer(language).then((webSocket) => { + webSocketRef.current = webSocket; + }); + } }} onChange={(value) => { if (value !== undefined) { diff --git a/code-editor/src/config/index.ts b/code-editor/src/config/index.ts index 0b9e984..d21b84a 100644 --- a/code-editor/src/config/index.ts +++ b/code-editor/src/config/index.ts @@ -28,15 +28,6 @@ using namespace std; int main() { cout << "Hello, World!"; return 0; -}`, - }, - java: { - path: "playground/Main.java", - language: "java", - value: `public class Main { - public static void main(String[] args) { - System.out.println("Hello, World!"); - } }`, }, }; diff --git a/code-editor/src/constants/languages.ts b/code-editor/src/constants/languages.ts index 2ddf2cc..fed5529 100644 --- a/code-editor/src/constants/languages.ts +++ b/code-editor/src/constants/languages.ts @@ -1,6 +1,6 @@ -import { COriginal, CplusplusOriginal, JavaOriginal } from "devicons-react"; +import { COriginal, CplusplusOriginal } from "devicons-react"; -export const SUPPORTED_EDITOR_LANGUAGES = ["c", "cpp", "java"]; +export const SUPPORTED_EDITOR_LANGUAGES = ["c", "cpp"]; export const SUPPORTED_EDITOR_LANGUAGES_CONFIG = { c: { @@ -13,11 +13,6 @@ export const SUPPORTED_EDITOR_LANGUAGES_CONFIG = { label: "C++", icon: CplusplusOriginal, }, - java: { - id: "java", - label: "Java", - icon: JavaOriginal, - }, }; export type SupportedEditorLanguage =