Skip to content

Commit

Permalink
Work towards red knot playground
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser committed Aug 5, 2024
1 parent 40e3317 commit 90cf86e
Show file tree
Hide file tree
Showing 3 changed files with 267 additions and 156 deletions.
57 changes: 24 additions & 33 deletions playground/src/red_knot.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
import React from "react";
import ReactDOM from "react-dom/client";
import Editor from "./ruff/Editor";
import Editor from "./red_knot/Editor";
import "./index.css";
import { loader } from "@monaco-editor/react";
import { setupMonaco } from "./shared/setupMonaco";
import { restore } from "./ruff/settings";
import { DEFAULT_PYTHON_SOURCE } from "./constants";
import init from "./ruff/pkg";
import init from "./red_knot/pkg";

startPlayground()
.then(({ sourceCode, settings, ruffVersion }) => {
console.log("Render", sourceCode, settings, ruffVersion);
.then(({ sourceCode }) => {
console.log("Render", sourceCode);
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
<React.StrictMode>
<Editor
initialSettings={settings}
initialSource={sourceCode}
ruffVersion={ruffVersion}
/>
<Editor initialSource={sourceCode} version="0.0.0" />
</React.StrictMode>,
);
})
Expand All @@ -28,33 +23,29 @@ startPlayground()
// Run once during startup. Initializes monaco, loads the wasm file, and restores the previous editor state.
async function startPlayground(): Promise<{
sourceCode: string;
settings: string;
ruffVersion: string;
}> {
const initialized = init();
loader.init().then(setupMonaco);
await initialized;

try {
const response = await restore();
// try {
// // const response = await restore();
//
// const [settingsSource, pythonSource] = response ?? [
// "",
// DEFAULT_PYTHON_SOURCE,
// ];
//
// return {
// sourceCode: pythonSource,
// settings: settingsSource,
// ruffVersion: "0.0.0",
// };
// } catch (error) {
// console.warn("Failed to restore editor state", error);

const [settingsSource, pythonSource] = response ?? [
"",
DEFAULT_PYTHON_SOURCE,
];

return {
sourceCode: pythonSource,
settings: settingsSource,
ruffVersion: "0.0.0",
};
} catch (error) {
console.warn("Failed to restore editor state", error);

return {
sourceCode: DEFAULT_PYTHON_SOURCE,
settings: "{}",
ruffVersion: "0.0.0",
};
}
return {
sourceCode: DEFAULT_PYTHON_SOURCE,
};
//s }
}
Loading

0 comments on commit 90cf86e

Please sign in to comment.