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