This repository was archived by the owner on Mar 22, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathreactPython.tsx
120 lines (114 loc) · 4.25 KB
/
reactPython.tsx
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import getKeybindingsServiceOverride from '@codingame/monaco-vscode-keybindings-service-override';
import { whenReady as whenReadyPython } from '@codingame/monaco-vscode-python-default-extension';
import React from 'react';
import ReactDOM from 'react-dom/client';
import { MonacoEditorReactComp } from '@typefox/monaco-editor-react';
import { UserConfig } from 'monaco-editor-wrapper';
import { buildWorkerDefinition } from 'monaco-editor-workers';
import { Uri, commands } from 'vscode';
import { MonacoLanguageClient } from 'monaco-languageclient';
buildWorkerDefinition('../../../../node_modules/monaco-editor-workers/dist/workers', import.meta.url, false);
/**
* Code is intentionally incorrect - language server will pick this up on connection and highlight the error
*/
const code = `def main():
return pass`;
const rootElem = document.getElementById('root')!;
const userConfig: UserConfig = {
languageClientConfig: {
options: {
name: 'Python Language Server Example',
$type: 'WebSocket',
host: 'localhost',
port: 30001,
path: 'pyright',
extraParams: {
authorization: 'UserAuth'
},
secured: false,
startOptions: {
onCall: (languageClient?: MonacoLanguageClient ) => {
setTimeout(()=>{
['pyright.restartserver', 'pyright.organizeimports'].forEach((cmdName) => {
commands.registerCommand(cmdName, (...args: unknown[]) => {
languageClient?.sendRequest('workspace/executeCommand', { command: cmdName, arguments: args });
});
});
},250);
},
reportStatus: true,
}
}, configurationOptions: {
workspaceFolder: {
index: 0,
name: 'workspace',
uri: Uri.parse('/workspace/')
},
},
},
wrapperConfig: {
serviceConfig: {
userServices: {
...getKeybindingsServiceOverride()
},
debugLogging: true
},
editorAppConfig: {
$type: 'extended',
languageId: 'python',
codeUri: '/workspace/python.py',
awaitExtensionReadiness: [whenReadyPython],
extensions: [{
config: {
name: 'python-client',
publisher: 'monaco-languageclient-project',
version: '1.0.0',
engines: {
vscode: '^1.81.5'
},
contributes: {
languages: [{
id: 'python',
extensions: ['.py', 'pyi'],
aliases: ['python'],
mimetypes: ['application/python'],
}],
commands: [{
command: 'pyright.restartserver',
title: 'Pyright: Restart Server',
category: 'Pyright'
},
{
command: 'pyright.organizeimports',
title: 'Pyright: Organize Imports',
category: 'Pyright'
}],
keybindings: [{
key: 'ctrl+k',
command: 'pyright.restartserver',
when: 'editorTextFocus'
}]
}
}
}],
userConfiguration: {
json: JSON.stringify({'workbench.colorTheme': 'Default Dark Modern'})
},
useDiffEditor: false,
code: code,
}
}
};
const onTextChanged = (text: string, isDirty: boolean) => {
console.log(`Dirty? ${isDirty} Content: ${text}`);
};
const comp = <MonacoEditorReactComp
userConfig={userConfig}
style={{
'paddingTop': '5px',
'height': '80vh'
}}
onTextChanged={onTextChanged}
/>;
const root = ReactDOM.createRoot(rootElem);
root.render(comp);