From e2ac9f27f023fe7d6f778c2b0484d5a5e7dd4ddb Mon Sep 17 00:00:00 2001 From: Paul Pan Date: Tue, 30 Jan 2024 21:01:22 +0800 Subject: [PATCH] fix: feat add rust lang --- src/components/editor.tsx | 2 ++ src/components/lang.ts | 27 +++++++++++++++++++++++++++ src/components/problem-details.tsx | 8 +------- src/pages/details.tsx | 3 ++- src/pages/submit.tsx | 10 ++-------- 5 files changed, 34 insertions(+), 16 deletions(-) create mode 100644 src/components/lang.ts diff --git a/src/components/editor.tsx b/src/components/editor.tsx index ead5467..578d7c9 100644 --- a/src/components/editor.tsx +++ b/src/components/editor.tsx @@ -3,9 +3,11 @@ import AceEditor from "react-ace"; import "ace-builds/src-noconflict/mode-c_cpp"; import "ace-builds/src-noconflict/mode-python"; import "ace-builds/src-noconflict/mode-golang"; +import "ace-builds/src-noconflict/mode-rust"; import "ace-builds/src-noconflict/snippets/c_cpp"; import "ace-builds/src-noconflict/snippets/python"; import "ace-builds/src-noconflict/snippets/golang"; +import "ace-builds/src-noconflict/snippets/rust"; import "ace-builds/src-noconflict/theme-textmate"; import "ace-builds/src-noconflict/ext-language_tools"; diff --git a/src/components/lang.ts b/src/components/lang.ts new file mode 100644 index 0000000..b61d36f --- /dev/null +++ b/src/components/lang.ts @@ -0,0 +1,27 @@ +export const AvailLang = [ + { value: "cpp", label: "C++" }, + { value: "c", label: "C" }, + { value: "python3", label: "Python3" }, + { value: "pypy3", label: "PyPy3" }, + { value: "go", label: "Go" }, + { value: "rust", label: "Rust" }, +]; + +export const LangToPrism: { [lang: string]: string } = { + cpp: "cpp", + c: "c", + python3: "python", + pypy3: "python", + go: "go", + rust: "rust", +}; + +// also check includes in components/editor.tsx +export const LangToAce: { [lang: string]: string } = { + cpp: "c_cpp", + c: "c_cpp", + python3: "python", + pypy3: "python", + go: "golang", + rust: "rust", +}; diff --git a/src/components/problem-details.tsx b/src/components/problem-details.tsx index 8be5536..d6b7f13 100644 --- a/src/components/problem-details.tsx +++ b/src/components/problem-details.tsx @@ -3,13 +3,7 @@ import { Link } from "react-router-dom"; import { Collapse, CollapseProps, Descriptions, Select, Space, Tag } from "antd"; import { DetailsResp, RuntimeInfo } from "../api/problem.ts"; - -const AvailLang = [ - { value: "cpp", label: "C++" }, - { value: "c", label: "C" }, - { value: "python", label: "Python" }, - { value: "golang", label: "Go" }, -]; +import { AvailLang } from "./lang.ts"; interface ProblemDetailsProps { details: DetailsResp; diff --git a/src/pages/details.tsx b/src/pages/details.tsx index ef46e73..8265619 100644 --- a/src/pages/details.tsx +++ b/src/pages/details.tsx @@ -10,6 +10,7 @@ import { useAuth } from "../components/hook.ts"; import { DetailsResp } from "../api/problem.ts"; import { ProblemLoader } from "../api/loader.ts"; import { StatusApi, StatusInfo, Verdict } from "../api/status.ts"; +import { LangToPrism } from "../components/lang.ts"; const { Title, Paragraph } = Typography; @@ -101,7 +102,7 @@ export default function DetailsPage() { const showSourceCode = status === undefined ? false : status.submission.code !== ""; const sourceCode = (