mirror of
https://litchi.icu/ngc2207/judge.git
synced 2025-05-18 20:07:41 +00:00
fix(playground): enhance language server connection handling with support for LSP_SUPPORTED_LANGUAGES
This commit is contained in:
parent
9ecb387418
commit
44ef62c03a
@ -1,13 +1,13 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import * as monaco from "monaco-editor";
|
import * as monaco from "monaco-editor";
|
||||||
import { connectToLanguageServer } from "@/lib/lsp";
|
|
||||||
import { useEffect, useRef, useState } from "react";
|
import { useEffect, useRef, useState } from "react";
|
||||||
import { Editor, loader } from "@monaco-editor/react";
|
import { Editor, loader } from "@monaco-editor/react";
|
||||||
import { MonacoLanguageClient } from "monaco-languageclient";
|
import { MonacoLanguageClient } from "monaco-languageclient";
|
||||||
import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
||||||
import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area";
|
import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area";
|
||||||
import { COriginal, CplusplusOriginal, JavaOriginal } from "devicons-react";
|
import { COriginal, CplusplusOriginal, JavaOriginal } from "devicons-react";
|
||||||
|
import { connectToLanguageServer, LSP_SUPPORTED_LANGUAGES } from "@/lib/lsp";
|
||||||
|
|
||||||
const files: {
|
const files: {
|
||||||
[key: string]: { name: string; language: string; value: string };
|
[key: string]: { name: string; language: string; value: string };
|
||||||
@ -62,26 +62,32 @@ export default function PlaygroundPage() {
|
|||||||
column: lastLineLength + 1,
|
column: lastLineLength + 1,
|
||||||
});
|
});
|
||||||
editorRef.current.focus();
|
editorRef.current.focus();
|
||||||
if (languageClientRef.current) {
|
if (
|
||||||
|
languageClientRef.current &&
|
||||||
|
language in LSP_SUPPORTED_LANGUAGES
|
||||||
|
) {
|
||||||
await languageClientRef.current.stop();
|
await languageClientRef.current.stop();
|
||||||
languageClientRef.current = null;
|
languageClientRef.current = null;
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
webSocketRef.current &&
|
webSocketRef.current &&
|
||||||
webSocketRef.current.readyState !== WebSocket.CLOSED &&
|
webSocketRef.current.readyState !== WebSocket.CLOSED &&
|
||||||
webSocketRef.current.readyState !== WebSocket.CLOSING
|
webSocketRef.current.readyState !== WebSocket.CLOSING &&
|
||||||
|
language in LSP_SUPPORTED_LANGUAGES
|
||||||
) {
|
) {
|
||||||
webSocketRef.current.close();
|
webSocketRef.current.close();
|
||||||
webSocketRef.current = null;
|
webSocketRef.current = null;
|
||||||
}
|
}
|
||||||
try {
|
if(language in LSP_SUPPORTED_LANGUAGES){
|
||||||
const languageClient = await connectToLanguageServer(
|
try {
|
||||||
language,
|
const languageClient = await connectToLanguageServer(
|
||||||
webSocketRef
|
language,
|
||||||
);
|
webSocketRef
|
||||||
languageClientRef.current = languageClient;
|
);
|
||||||
} catch (error) {
|
languageClientRef.current = languageClient;
|
||||||
console.error("Failed to connect to language server:", error);
|
} catch (error) {
|
||||||
|
console.error("Failed to connect to language server:", error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ import { RefObject } from "react";
|
|||||||
import normalizeUrl from "normalize-url";
|
import normalizeUrl from "normalize-url";
|
||||||
import { MonacoLanguageClient } from "monaco-languageclient";
|
import { MonacoLanguageClient } from "monaco-languageclient";
|
||||||
|
|
||||||
const LSP_SUPPORTED_LANGUAGES: {
|
export const LSP_SUPPORTED_LANGUAGES: {
|
||||||
[key: string]: { hostname: string; port: number; path: string };
|
[key: string]: { hostname: string; port: number; path: string };
|
||||||
} = {
|
} = {
|
||||||
c: {
|
c: {
|
||||||
|
Loading…
Reference in New Issue
Block a user