mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-03 23:25:14 +00:00
playground: Add AST/Tokens/Formatter panels (#5859)
This commit is contained in:
parent
9ed7ceeb0a
commit
46a17d11f3
19 changed files with 1343 additions and 780 deletions
|
@ -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" } }}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue