/ concept-collection / numbl-web-ide
Sign in
concept-collection / numbl-web-ide
numbl-web-ide / src / ide.ts
52 lines · 1.7 KBBlameHistoryRaw
1import { createWorkbench, type WorkbenchTheme } from 'minwebide';
2import { createMipSystem } from './numbl/mipSystem';
3import { createNumblRunner } from './numbl/runner';
4import { openProjectFileSystem, touchProject, type ProjectInfo } from './projects';
6/** Opens the IDE for a project. Returns a disposable view. */
7export async function openIde(container: HTMLElement, project: ProjectInfo, theme: WorkbenchTheme): Promise<{ dispose(): void }> {
8 touchProject(project.id);
9 document.title = `${project.name} — numbl web IDE`;
11 const fs = await openProjectFileSystem(project.id);
12 const mip = await createMipSystem();
13 // fetch/refresh mip core in the background; runs await it (and say so
14 // in the output channel if they actually have to wait)
15 void mip.ensureCore().catch(() => { /* retried on the next run */ });
17 const workbench = createWorkbench(container, {
18 fileSystem: fs,
19 theme,
20 workspaceName: project.name,
21 });
23 const numbl = createNumblRunner(fs, workbench, mip);
24 workbench.registerRunner(numbl.runner);
26 // the project indicator: click to go back to the project list
27 workbench.statusBar.setItem('project', 'left', project.name, {
28 icon: 'folder-opened',
29 title: 'Back to projects',
30 onClick: () => { location.hash = '#/'; },
31 });
32 // replace the default branding item with the project indicator
33 workbench.statusBar.removeItem('branding');
35 // open the most useful starting file
36 for (const path of ['/waves.m', '/main.m', '/README.md']) {
37 const uri = fs.root.with({ path });
38 if (await fs.fileService.exists(uri)) {
39 await workbench.openFile(uri);
40 break;
41 }
42 }
44 return {
45 dispose() {
46 numbl.dispose();
47 workbench.dispose();
48 fs.dispose();
49 mip.dispose();
50 },
51 };
moveopenescclose