playground: Add AST/Tokens/Formatter panels (#5859)

This commit is contained in:
Micha Reiser 2023-07-19 16:46:08 +02:00 committed by GitHub
parent 9ed7ceeb0a
commit 46a17d11f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 1343 additions and 780 deletions

View file

@ -2,9 +2,9 @@
* Editor for the Python source code.
*/
import Editor, { useMonaco } from "@monaco-editor/react";
import Editor, { BeforeMount, Monaco } from "@monaco-editor/react";
import { MarkerSeverity, MarkerTag } from "monaco-editor";
import { useCallback, useEffect } from "react";
import { useCallback, useEffect, useRef } from "react";
import { Diagnostic } from "../pkg";
import { Theme } from "./theme";
@ -21,7 +21,8 @@ export default function SourceEditor({
theme: Theme;
onChange: (pythonSource: string) => void;
}) {
const monaco = useMonaco();
const monacoRef = useRef<Monaco | null>(null);
const monaco = monacoRef.current;
useEffect(() => {
const editor = monaco?.editor;
@ -98,14 +99,21 @@ export default function SourceEditor({
[onChange],
);
const handleMount: BeforeMount = useCallback(
(instance) => (monacoRef.current = instance),
[],
);
return (
<Editor
beforeMount={handleMount}
options={{
readOnly: false,
minimap: { enabled: false },
fontSize: 14,
roundedSelection: false,
scrollBeyondLastLine: false,
contextmenu: false,
}}
language={"python"}
wrapperProps={visible ? {} : { style: { display: "none" } }}