From f0d64064a98c5b391b3cb8a68d22ee9220f24f5d Mon Sep 17 00:00:00 2001 From: Lauren Tan Date: Mon, 30 Jan 2023 10:36:35 -0500 Subject: [PATCH] Support partial compilation in playground This adds support in the playground for best effort compilation: if any passes have errors, we'll try to render as many successful tabs leading up to the pass with an error. Also contains some styling updates ![Screenshot 2023-01-27 at 2 18 06 PM](https://user-images.githubusercontent.com/1390709/215222635-59b42555-f1f3-4fc0-b1cd-3959946df6da.png) ![Screenshot 2023-01-27 at 2 18 54 PM](https://user-images.githubusercontent.com/1390709/215222636-4c0275fd-a95b-4f0f-946a-258ad8b27722.png) ![Screenshot 2023-01-27 at 5 03 02 PM](https://user-images.githubusercontent.com/1390709/215222637-92a8e459-173a-41ae-be9f-0cc0d54479d0.png) --- .../forget/packages/playground/app/layout.tsx | 2 +- .../playground/components/Editor/Input.tsx | 2 +- .../playground/components/Editor/Output.tsx | 42 ++++++++++++------- .../playground/components/Editor/index.tsx | 24 +++++------ .../playground/components/TabbedWindow.tsx | 14 ++++++- .../packages/playground/tailwind.config.js | 1 + 6 files changed, 53 insertions(+), 32 deletions(-) diff --git a/compiler/forget/packages/playground/app/layout.tsx b/compiler/forget/packages/playground/app/layout.tsx index 88cf805212..d40615681d 100644 --- a/compiler/forget/packages/playground/app/layout.tsx +++ b/compiler/forget/packages/playground/app/layout.tsx @@ -37,7 +37,7 @@ export default function RootLayout({ crossOrigin="anonymous" /> - {children} + {children} ); } diff --git a/compiler/forget/packages/playground/components/Editor/Input.tsx b/compiler/forget/packages/playground/components/Editor/Input.tsx index 75f67c1558..df96ad2e17 100644 --- a/compiler/forget/packages/playground/components/Editor/Input.tsx +++ b/compiler/forget/packages/playground/components/Editor/Input.tsx @@ -98,7 +98,7 @@ export default function Input({ errors }: Props) {
{/* Restrict MonacoEditor's height, since the config autoLayout:true will grow the editor to fit within parent element */} -
+
} - | { kind: "err"; error: CompilerError }; + | { + kind: "err"; + results: Map; + error: CompilerError; + }; type Props = { store: Store; @@ -48,7 +52,6 @@ function tabify(source: string, compilerOutput: CompilerOutput) { const reorderedTabs = new Map(); const concattedResults = new Map(); let topLevelFnDecls: Array = []; - if (compilerOutput.kind === "err") return reorderedTabs; // Concat all top level function declaration results into a single tab for each pass for (const [passName, results] of compilerOutput.results) { for (const result of results) { @@ -152,21 +155,28 @@ function Output({ store, compilerOutput }: Props) { [store.source, compilerOutput] ); - if (compilerOutput.kind === "err") { - return ( -
-        {compilerOutput.error.toString()}
-      
- ); - } - return ( - + <> + + {compilerOutput.kind === "err" ? ( +
+
+

COMPILER ERRORS

+
+
+            {compilerOutput.error.toString()}
+          
+
+ ) : null} + ); } diff --git a/compiler/forget/packages/playground/components/Editor/index.tsx b/compiler/forget/packages/playground/components/Editor/index.tsx index a75b79b419..ebe59d98b2 100644 --- a/compiler/forget/packages/playground/components/Editor/index.tsx +++ b/compiler/forget/packages/playground/components/Editor/index.tsx @@ -57,16 +57,16 @@ function parseFunctions( } function compile(source: string): CompilerOutput { + const results = new Map(); + const upsert = (result: PrintedCompilerPipelineValue) => { + const entry = results.get(result.name); + if (Array.isArray(entry)) { + entry.push(result); + } else { + results.set(result.name, [result]); + } + }; try { - const results = new Map(); - const upsert = (result: PrintedCompilerPipelineValue) => { - const entry = results.get(result.name); - if (Array.isArray(entry)) { - entry.push(result); - } else { - results.set(result.name, [result]); - } - }; for (const fn of parseFunctions(source)) { for (const result of run(fn)) { const fnName = fn.node.id?.name ?? null; @@ -112,7 +112,7 @@ function compile(source: string): CompilerOutput { if (error.details == null) { error.details = []; } - return { kind: "err", error }; + return { kind: "err", results, error }; } } @@ -150,7 +150,7 @@ export default function Editor() { return ( <> -
+
-
+
diff --git a/compiler/forget/packages/playground/components/TabbedWindow.tsx b/compiler/forget/packages/playground/components/TabbedWindow.tsx index dadf5c281d..b1ab3aad19 100644 --- a/compiler/forget/packages/playground/components/TabbedWindow.tsx +++ b/compiler/forget/packages/playground/components/TabbedWindow.tsx @@ -15,8 +15,18 @@ export default function TabbedWindow(props: { tabsOpen: Set; setTabsOpen: (newTab: Set) => void; }): React.ReactElement { + if (props.tabs.size === 0) { + return ( +
+ No compiler output detected, see errors below +
+ ); + } return ( -
+
{Array.from(props.tabs.keys()).map((name) => { return ( {isShow ? ( -
+