import { createWorkbench, type WorkbenchTheme } from 'minwebide'; import { createMipSystem } from './numbl/mipSystem'; import { createNumblRunner } from './numbl/runner'; import { openProjectFileSystem, touchProject, type ProjectInfo } from './projects'; /** Opens the IDE for a project. Returns a disposable view. */ export async function openIde(container: HTMLElement, project: ProjectInfo, theme: WorkbenchTheme): Promise<{ dispose(): void }> { touchProject(project.id); document.title = `${project.name} — numbl web IDE`; const fs = await openProjectFileSystem(project.id); const mip = await createMipSystem(); // fetch/refresh mip core in the background; runs await it (and say so // in the output channel if they actually have to wait) void mip.ensureCore().catch(() => { /* retried on the next run */ }); const workbench = createWorkbench(container, { fileSystem: fs, theme, workspaceName: project.name, }); const numbl = createNumblRunner(fs, workbench, mip); workbench.registerRunner(numbl.runner); // the project indicator: click to go back to the project list workbench.statusBar.setItem('project', 'left', project.name, { icon: 'folder-opened', title: 'Back to projects', onClick: () => { location.hash = '#/'; }, }); // replace the default branding item with the project indicator workbench.statusBar.removeItem('branding'); // open the most useful starting file for (const path of ['/waves.m', '/main.m', '/README.md']) { const uri = fs.root.with({ path }); if (await fs.fileService.exists(uri)) { await workbench.openFile(uri); break; } } return { dispose() { numbl.dispose(); workbench.dispose(); fs.dispose(); mip.dispose(); }, }; }