Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/test/simulation/workbench/simulationWorkbench.tsx
13394 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { ipcRenderer } from 'electron';
7
import * as path from 'path';
8
import * as React from 'react';
9
import { render } from 'react-dom';
10
import { Disposable } from '../../../src/util/vs/base/common/lifecycle';
11
import { App, DisplayOptions } from './components/app';
12
import { InitArgs, parseInitEventArgs as parseProcessArgv } from './initArgs';
13
import { AMLProvider } from './stores/amlSimulations';
14
import { NesExternalOptions } from './stores/nesExternalOptions';
15
import { RunnerOptions } from './stores/runnerOptions';
16
import { SimulationRunsProvider } from './stores/simulationBaseline';
17
import { SimulationRunner } from './stores/simulationRunner';
18
import { SimulationStorage } from './stores/simulationStorage';
19
import { SimulationTestsProvider } from './stores/simulationTestsProvider';
20
import { TestSource, TestSourceValue } from './stores/testSource';
21
import { REPO_ROOT, monacoModule } from './utils/utils';
22
23
24
class SimulationWorkbench extends Disposable {
25
private readonly storage: SimulationStorage;
26
private readonly testSource: TestSourceValue;
27
private readonly simulationRunsProvider: SimulationRunsProvider;
28
private readonly amlProvider: AMLProvider;
29
private readonly runner: SimulationRunner;
30
private readonly runnerOptions: RunnerOptions;
31
private readonly nesExternalOptions: NesExternalOptions;
32
private readonly tests: SimulationTestsProvider;
33
private readonly displayOptions: DisplayOptions;
34
35
constructor() {
36
super();
37
38
this.storage = new SimulationStorage();
39
this.testSource = this.storage.bind('testSource', TestSource.Local);
40
this.amlProvider = this._register(new AMLProvider(this.storage));
41
this.runnerOptions = new RunnerOptions(this.storage);
42
this.nesExternalOptions = new NesExternalOptions(this.storage);
43
this.runner = this._register(new SimulationRunner(this.storage, this.runnerOptions));
44
this.simulationRunsProvider = this._register(new SimulationRunsProvider(this.storage, this.runner));
45
this.tests = this._register(new SimulationTestsProvider(this.testSource, this.runner, this.simulationRunsProvider, this.amlProvider, this.nesExternalOptions));
46
this.displayOptions = new DisplayOptions(this.storage);
47
}
48
49
public run(initArgs: InitArgs | undefined) {
50
const elt = document.createElement('div');
51
elt.style.minHeight = 'inherit';
52
document.body.appendChild(elt);
53
render(
54
<App
55
initArgs={initArgs}
56
testsProvider={this.tests}
57
runner={this.runner}
58
runnerOptions={this.runnerOptions}
59
nesExternalOptions={this.nesExternalOptions}
60
simulationRunsProvider={this.simulationRunsProvider}
61
amlProvider={this.amlProvider}
62
displayOptions={this.displayOptions}
63
/>,
64
elt
65
);
66
}
67
}
68
69
let monacoPromise: Promise<typeof import('monaco-editor')> | undefined = undefined;
70
function loadMonaco(): Promise<typeof import('monaco-editor')> {
71
if (!monacoPromise) {
72
monacoPromise = doLoadMonaco();
73
}
74
return monacoPromise;
75
}
76
77
function doLoadMonaco(): Promise<typeof import('monaco-editor')> {
78
return new Promise<typeof import('monaco-editor')>((resolve, reject) => {
79
const amdLoader = require('../../node_modules/monaco-editor/min/vs/loader.js');
80
const amdRequire = amdLoader.require;
81
82
function uriFromPath(_path: string) {
83
let pathName = path.resolve(_path).replace(/\\/g, '/');
84
if (pathName.length > 0 && pathName.charAt(0) !== '/') {
85
pathName = '/' + pathName;
86
}
87
return encodeURI('file://' + pathName);
88
}
89
90
const baseUrl = uriFromPath(path.join(REPO_ROOT, 'node_modules/monaco-editor/min'));
91
amdRequire.config({ baseUrl });
92
93
amdRequire(['vs/editor/editor.main'], function (monaco: typeof import('monaco-editor')) {
94
resolve(monaco);
95
}, reject);
96
});
97
}
98
99
async function startup() {
100
monacoModule.value = await loadMonaco();
101
const processArgv: string[] = await ipcRenderer.invoke('processArgv');
102
const parsedArgs = parseProcessArgv(processArgv);
103
new SimulationWorkbench().run(parsedArgs);
104
}
105
106
startup();
107
108