Use code editor in diagnostics tab (#1024)

This commit is contained in:
Shuchang Zheng
2024-10-22 06:45:46 -07:00
committed by GitHub
parent 439815c33a
commit d571519a67
5 changed files with 59 additions and 137 deletions

View File

@@ -1,13 +1,25 @@
import CodeMirror, { EditorView } from "@uiw/react-codemirror";
import { json } from "@codemirror/lang-json";
import { python } from "@codemirror/lang-python";
import { html } from "@codemirror/lang-html";
import { tokyoNightStorm } from "@uiw/codemirror-theme-tokyo-night-storm";
import { cn } from "@/util/utils";
function getLanguageExtension(language: "python" | "json" | "html") {
switch (language) {
case "python":
return python();
case "json":
return json();
case "html":
return html();
}
}
type Props = {
value: string;
onChange?: (value: string) => void;
language: "python" | "json";
language?: "python" | "json" | "html";
readOnly?: boolean;
minHeight?: string;
maxHeight?: string;
@@ -25,10 +37,10 @@ function CodeEditor({
readOnly = false,
fontSize = 12,
}: Props) {
const extensions =
language === "json"
? [json(), EditorView.lineWrapping]
: [python(), EditorView.lineWrapping];
const extensions = language
? [getLanguageExtension(language), EditorView.lineWrapping]
: [EditorView.lineWrapping];
return (
<CodeMirror
value={value}