forked from TypeFox/monaco-languageclient
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreactPython.tsx
More file actions
50 lines (44 loc) · 2.31 KB
/
reactPython.tsx
File metadata and controls
50 lines (44 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* --------------------------------------------------------------------------------------------
* Copyright (c) 2024 TypeFox and others.
* Licensed under the MIT License. See LICENSE in the package root for license information.
* ------------------------------------------------------------------------------------------ */
import { type RegisterLocalProcessExtensionResult } from '@codingame/monaco-vscode-api/extensions';
import { MonacoEditorReactComp } from '@typefox/monaco-editor-react';
import { configureDebugging } from 'monaco-languageclient/debugger';
import type { MonacoVscodeApiWrapper } from 'monaco-languageclient/vscodeApiWrapper';
import React from 'react';
import ReactDOM from 'react-dom/client';
import * as vscode from 'vscode';
import { createPythonAppConfig } from './config.js';
export const runPythonReact = async () => {
const appConfig = createPythonAppConfig();
const onVscodeApiInitDone = async (apiWrapper: MonacoVscodeApiWrapper) => {
const result = apiWrapper.getExtensionRegisterResult('mlc-python-example') as RegisterLocalProcessExtensionResult;
result.setAsDefaultApi();
const initResult = apiWrapper.getExtensionRegisterResult('debugger-py-client') as RegisterLocalProcessExtensionResult | undefined;
if (initResult !== undefined) {
configureDebugging(await initResult.getApi(), appConfig.configParams);
}
await vscode.commands.executeCommand('workbench.view.explorer');
await vscode.window.showTextDocument(appConfig.configParams.files.get('hello2.py')!.uri);
};
const root = ReactDOM.createRoot(document.getElementById('react-root')!);
const App = () => {
return (
<>
<div style={{ 'backgroundColor': '#1f1f1f' }} >
<MonacoEditorReactComp
vscodeApiConfig={appConfig.vscodeApiConfig}
editorAppConfig={appConfig.editorAppConfig}
languageClientConfig={appConfig.languageClientConfig}
style={{ 'height': '100%' }}
onVscodeApiInitDone={onVscodeApiInitDone}
onError={(e) => {
console.error(e);
}} />
</div>
</>
);
};
root.render(<App />);
};