mirror of
https://github.com/massbug/judge4c.git
synced 2025-05-18 07:16:34 +00:00
feat(monaco): Integrate clangd LSP for C language support in Monaco Editor
This commit is contained in:
parent
e2bb58a034
commit
672f63f10a
177
src/app/page.tsx
177
src/app/page.tsx
@ -1,101 +1,88 @@
|
|||||||
import Image from "next/image";
|
"use client";
|
||||||
|
|
||||||
|
import {
|
||||||
|
toSocket,
|
||||||
|
WebSocketMessageReader,
|
||||||
|
WebSocketMessageWriter,
|
||||||
|
} from "vscode-ws-jsonrpc";
|
||||||
|
import { useEffect } from "react";
|
||||||
|
import dynamic from "next/dynamic";
|
||||||
|
import normalizeUrl from "normalize-url";
|
||||||
|
import { Skeleton } from "@/components/ui/skeleton";
|
||||||
|
|
||||||
|
const DynamicEditor = dynamic(
|
||||||
|
async () => {
|
||||||
|
const monaco = await import("monaco-editor");
|
||||||
|
const { loader, Editor } = await import("@monaco-editor/react");
|
||||||
|
|
||||||
|
loader.config({ monaco });
|
||||||
|
|
||||||
|
return Editor;
|
||||||
|
},
|
||||||
|
{ ssr: false }
|
||||||
|
);
|
||||||
|
|
||||||
export default function Home() {
|
export default function Home() {
|
||||||
return (
|
useEffect(() => {
|
||||||
<div className="grid grid-rows-[20px_1fr_20px] items-center justify-items-center min-h-screen p-8 pb-20 gap-16 sm:p-20 font-[family-name:var(--font-geist-sans)]">
|
const url = normalizeUrl("ws://localhost:4594/clangd");
|
||||||
<main className="flex flex-col gap-8 row-start-2 items-center sm:items-start">
|
const webSocket = new WebSocket(url);
|
||||||
<Image
|
|
||||||
className="dark:invert"
|
|
||||||
src="/next.svg"
|
|
||||||
alt="Next.js logo"
|
|
||||||
width={180}
|
|
||||||
height={38}
|
|
||||||
priority
|
|
||||||
/>
|
|
||||||
<ol className="list-inside list-decimal text-sm text-center sm:text-left font-[family-name:var(--font-geist-mono)]">
|
|
||||||
<li className="mb-2">
|
|
||||||
Get started by editing{" "}
|
|
||||||
<code className="bg-black/[.05] dark:bg-white/[.06] px-1 py-0.5 rounded font-semibold">
|
|
||||||
src/app/page.tsx
|
|
||||||
</code>
|
|
||||||
.
|
|
||||||
</li>
|
|
||||||
<li>Save and see your changes instantly.</li>
|
|
||||||
</ol>
|
|
||||||
|
|
||||||
<div className="flex gap-4 items-center flex-col sm:flex-row">
|
webSocket.onopen = async () => {
|
||||||
<a
|
const socket = toSocket(webSocket);
|
||||||
className="rounded-full border border-solid border-transparent transition-colors flex items-center justify-center bg-foreground text-background gap-2 hover:bg-[#383838] dark:hover:bg-[#ccc] text-sm sm:text-base h-10 sm:h-12 px-4 sm:px-5"
|
const reader = new WebSocketMessageReader(socket);
|
||||||
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
|
const writer = new WebSocketMessageWriter(socket);
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
const { MonacoLanguageClient } = await import("monaco-languageclient");
|
||||||
>
|
const { ErrorAction, CloseAction } = await import(
|
||||||
<Image
|
"vscode-languageclient"
|
||||||
className="dark:invert"
|
);
|
||||||
src="/vercel.svg"
|
|
||||||
alt="Vercel logomark"
|
const languageClient = new MonacoLanguageClient({
|
||||||
width={20}
|
name: "C Language Client",
|
||||||
height={20}
|
clientOptions: {
|
||||||
/>
|
documentSelector: ["c"],
|
||||||
Deploy now
|
errorHandler: {
|
||||||
</a>
|
error: () => ({ action: ErrorAction.Continue }),
|
||||||
<a
|
closed: () => ({ action: CloseAction.DoNotRestart }),
|
||||||
className="rounded-full border border-solid border-black/[.08] dark:border-white/[.145] transition-colors flex items-center justify-center hover:bg-[#f2f2f2] dark:hover:bg-[#1a1a1a] hover:border-transparent text-sm sm:text-base h-10 sm:h-12 px-4 sm:px-5 sm:min-w-44"
|
},
|
||||||
href="https://nextjs.org/docs?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
|
},
|
||||||
target="_blank"
|
connectionProvider: {
|
||||||
rel="noopener noreferrer"
|
get: () => Promise.resolve({ reader, writer }),
|
||||||
>
|
},
|
||||||
Read our docs
|
});
|
||||||
</a>
|
|
||||||
</div>
|
languageClient.start();
|
||||||
</main>
|
reader.onClose(() => languageClient.stop());
|
||||||
<footer className="row-start-3 flex gap-6 flex-wrap items-center justify-center">
|
};
|
||||||
<a
|
|
||||||
className="flex items-center gap-2 hover:underline hover:underline-offset-4"
|
webSocket.onerror = (event) => {
|
||||||
href="https://nextjs.org/learn?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
|
console.error("WebSocket error observed:", event);
|
||||||
target="_blank"
|
};
|
||||||
rel="noopener noreferrer"
|
|
||||||
>
|
webSocket.onclose = (event) => {
|
||||||
<Image
|
console.log("WebSocket closed:", event);
|
||||||
aria-hidden
|
};
|
||||||
src="/file.svg"
|
|
||||||
alt="File icon"
|
return () => {
|
||||||
width={16}
|
webSocket.close();
|
||||||
height={16}
|
};
|
||||||
/>
|
}, []);
|
||||||
Learn
|
|
||||||
</a>
|
return (
|
||||||
<a
|
<div className="h-screen flex flex-col">
|
||||||
className="flex items-center gap-2 hover:underline hover:underline-offset-4"
|
<DynamicEditor
|
||||||
href="https://vercel.com/templates?framework=next.js&utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
|
theme="vs-dark"
|
||||||
target="_blank"
|
defaultLanguage="c"
|
||||||
rel="noopener noreferrer"
|
defaultValue="# include<stdio.h>"
|
||||||
>
|
path="file:///main.c"
|
||||||
<Image
|
onValidate={(markers) => {
|
||||||
aria-hidden
|
markers.forEach((marker) =>
|
||||||
src="/window.svg"
|
console.log("onValidate:", marker.message)
|
||||||
alt="Window icon"
|
);
|
||||||
width={16}
|
}}
|
||||||
height={16}
|
options={{ automaticLayout: true }}
|
||||||
/>
|
loading={<Skeleton className="h-full w-full p-4" />}
|
||||||
Examples
|
/>
|
||||||
</a>
|
|
||||||
<a
|
|
||||||
className="flex items-center gap-2 hover:underline hover:underline-offset-4"
|
|
||||||
href="https://nextjs.org?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
>
|
|
||||||
<Image
|
|
||||||
aria-hidden
|
|
||||||
src="/globe.svg"
|
|
||||||
alt="Globe icon"
|
|
||||||
width={16}
|
|
||||||
height={16}
|
|
||||||
/>
|
|
||||||
Go to nextjs.org →
|
|
||||||
</a>
|
|
||||||
</footer>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user