/ concept-collection / stan-web-ide
Sign in
concept-collection / stan-web-ide
stan-web-ide / src / ide.ts
57 lines · 2.3 KBCodeBlameHistory
e20b703Build on minwebide's project-app shellJeremy Magland 1import { createWorkbench, type AppWorkbench, type WorkbenchTheme, type WorkspaceFileSystem } from 'minwebide';
ad7d2c4CSV table view: default editor for .csv filesJeremy Magland 2import { createCsvTableProvider } from './csvTable';
f66b0fbOpen GitHub repos as workspaces via #/github/<spec>Jeremy Magland 3import { createResultsViewProvider } from './stan/resultsView';
21efcb6stan web IDE: run Stan sampling in the browserJeremy Magland 4import { createStanRunner } from './stan/runner';
5import { createSampleEditorProvider } from './stan/sampleEditor';
6import { showServerDialog } from './stan/serverDialog';
7import { getServerUrl, onDidChangeServerUrl, probeServer } from './stan/settings';
10 * Assembles the Stan workbench (runner, custom editors, compile-server status
e20b703Build on minwebide's project-app shellJeremy Magland 11 * item) on a file system. Used by the project-app shell for both project IDEs
12 * and GitHub repo IDEs; does not own `fs` — the caller disposes it.
e20b703Build on minwebide's project-app shellJeremy Magland 14export async function openStanWorkbench(container: HTMLElement, fs: WorkspaceFileSystem, workspaceName: string, theme: WorkbenchTheme): Promise<AppWorkbench> {
21efcb6stan web IDE: run Stan sampling in the browserJeremy Magland 15 const workbench = createWorkbench(container, {
16 fileSystem: fs,
17 theme,
f66b0fbOpen GitHub repos as workspaces via #/github/<spec>Jeremy Magland 18 workspaceName,
f66b0fbOpen GitHub repos as workspaces via #/github/<spec>Jeremy Magland 20 const stan = createStanRunner(fs, (path) => workbench.openFile(fs.root.with({ path })));
21efcb6stan web IDE: run Stan sampling in the browserJeremy Magland 21 workbench.registerRunner(stan.runner);
22 workbench.registerCustomEditor(createSampleEditorProvider(fs, workbench, { stop: stan.stop }));
f66b0fbOpen GitHub repos as workspaces via #/github/<spec>Jeremy Magland 23 workbench.registerCustomEditor(createResultsViewProvider(fs));
ad7d2c4CSV table view: default editor for .csv filesJeremy Magland 24 workbench.registerCustomEditor(createCsvTableProvider());
26 // compile-server status: shows connectivity, click to change the URL
27 let disposed = false;
28 const refreshServerItem = async () => {
29 const url = getServerUrl();
30 workbench.statusBar.setItem('stan-server', 'right', 'Stan server: checking...', {
31 icon: 'server',
32 title: `${url}\nClick to change the compilation server`,
33 onClick: () => showServerDialog(container),
34 });
35 const ok = await probeServer(url);
36 if (disposed || url !== getServerUrl()) {
37 return;
38 }
39 workbench.statusBar.setItem('stan-server', 'right', `Stan server: ${ok ? 'connected' : 'offline'}`, {
40 icon: ok ? 'server' : 'warning',
41 title: `${url}${ok ? 'connected' : 'not reachable'}\nClick to change the compilation server`,
42 onClick: () => showServerDialog(container),
43 });
44 };
45 void refreshServerItem();
46 const serverListener = onDidChangeServerUrl(() => void refreshServerItem());
49 workbench,
50 dispose() {
51 disposed = true;
52 serverListener.dispose();
53 stan.dispose();
54 workbench.dispose();
55 },
56 };
moveopenescclose