@typefox/monaco-editor-react 7.0.0-next.0 → 7.0.0-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -3
- package/README.md +89 -37
- package/lib/index.d.ts +4 -4
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +61 -33
- package/lib/index.js.map +1 -1
- package/package.json +4 -4
- package/src/index.tsx +77 -40
package/CHANGELOG.md
CHANGED
|
@@ -2,10 +2,34 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to npm module [@typefox/monaco-editor-react](https://www.npmjs.com/package/@typefox/monaco-editor-react) are documented in this file.
|
|
4
4
|
|
|
5
|
-
## [7.0.0
|
|
5
|
+
## [7.0.0] - unreleased
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
- Updated
|
|
7
|
+
- Merge `monaco-editor-wrapper` with `monaco-languageclient`:
|
|
8
|
+
- Updated to `monaco-languageclient@10.0.0`.
|
|
9
|
+
- Documentation update [#956](https://github.com/TypeFox/monaco-languageclient/pull/956).
|
|
10
|
+
- Lifecycle adjustments [#939](https://github.com/TypeFox/monaco-languageclient/pull/939).
|
|
11
|
+
- Move MonacoLanguageClientWrapper to monaco-languageclient [#920](https://github.com/TypeFox/monaco-languageclient/pull/920).
|
|
12
|
+
- Please see the [migration guide](https://github.com/TypeFox/monaco-languageclient/blob/main/docs/migration.md).
|
|
13
|
+
- Noteworthy updates and stability improvements:
|
|
14
|
+
- Fix React Stict Mode
|
|
15
|
+
- Only one language client can be used directly with the component
|
|
16
|
+
- Fixed rerendering issue by introducing an internal update queue
|
|
17
|
+
- Updated all `@codingame/monaco-vscode` packages to `^21.0.1`.
|
|
18
|
+
|
|
19
|
+
## [6.12.0] - 2025-08-21
|
|
20
|
+
|
|
21
|
+
- Updated to `monaco-languageclient@9.11.0` and `monaco-editor-wrapper@6.12.0`.
|
|
22
|
+
- Updated all `@codingame/monaco-vscode` packages to `20.2.1`.
|
|
23
|
+
|
|
24
|
+
## [6.11.0] - 2025-08-14
|
|
25
|
+
|
|
26
|
+
- Updated to `monaco-languageclient@9.10.0` and `monaco-editor-wrapper@6.11.0`.
|
|
27
|
+
- Updated all `@codingame/monaco-vscode` packages to `20.1.1`.
|
|
28
|
+
|
|
29
|
+
## [6.10.0] - 2025-08-11
|
|
30
|
+
|
|
31
|
+
- Updated to `monaco-languageclient@9.9.0` and `monaco-editor-wrapper@6.10.0`.
|
|
32
|
+
- Updated all `@codingame/monaco-vscode` packages to `19.1.4`.
|
|
9
33
|
|
|
10
34
|
## [6.9.0] - 2025-06-24
|
|
11
35
|
|
package/README.md
CHANGED
|
@@ -1,58 +1,110 @@
|
|
|
1
1
|
# React component for Monaco-Editor and Monaco Languageclient
|
|
2
2
|
|
|
3
|
-
This packages provides a React component that
|
|
4
|
-
|
|
5
|
-
The [monaco-languageclient](https://github.com/TypeFox/monaco-languageclient) can be activated to connect to a language server either via jsonrpc over a websocket to an exernal server process, or via the Language Server Protocol for the browser where the language server runs in a web worker.
|
|
3
|
+
This packages provides a React component that wraps the functionality of [monaco-languageclient](https://www.npmjs.com/package/monaco-languageclient) and all its tools.
|
|
6
4
|
|
|
7
5
|
## CHANGELOG
|
|
8
6
|
|
|
9
7
|
All changes are noted in the [CHANGELOG](https://github.com/TypeFox/monaco-languageclient/blob/main/packages/wrapper-react/CHANGELOG.md).
|
|
10
8
|
|
|
11
|
-
##
|
|
9
|
+
## Official documentation, quick start and examples
|
|
10
|
+
|
|
11
|
+
This is npm package is part of the [monaco-languageclient mono repo](https://github.com/TypeFox/monaco-languageclient).
|
|
12
|
+
|
|
13
|
+
You find detailed information in the [official documentation](https://github.com/TypeFox/monaco-languageclient/blob/main/docs/index.md).
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
If interested, check [quick start for local development]](<https://github.com/TypeFox/monaco-languageclient#getting-started>).
|
|
16
|
+
|
|
17
|
+
A detailed list of examples is contained in the GitHub repository, please see [this listing](<https://github.com/TypeFox/monaco-languageclient#examples-overview>).
|
|
14
18
|
|
|
15
19
|
## Usage
|
|
16
20
|
|
|
17
|
-
You can import the monaco react component for easy use in an existing React project. Below you can see a quick example of a fully functional implementation in TypeScript. The react component uses the same
|
|
21
|
+
You can import the monaco react component for easy use in an existing React project. Below you can see a quick example of a fully functional implementation in TypeScript. The react component uses the same configuration objects you using `monaco-languageclient` directly with TypeScript/JavaScript.
|
|
22
|
+
|
|
23
|
+
The language client on start can connect to a language server either via jsonrpc over a websocket to an exernal server process, or directly in the browser where the language server runs in a web worker. In both cases they use the Language Server Protocol to communicate. The react component is limited to one language client per component.
|
|
18
24
|
|
|
19
25
|
```tsx
|
|
26
|
+
import * as vscode from 'vscode';
|
|
27
|
+
// Import Monaco Language Client components
|
|
28
|
+
import { configureDefaultWorkerFactory } from 'monaco-languageclient/workerFactory';
|
|
29
|
+
import type { MonacoVscodeApiConfig } from 'monaco-languageclient/vscodeApiWrapper';
|
|
30
|
+
import type { LanguageClientConfig } from 'monaco-languageclient/lcwrapper';
|
|
31
|
+
import type { EditorAppConfig } from 'monaco-languageclient/editorApp';
|
|
32
|
+
import { MonacoEditorReactComp } from '@typefox/monaco-editor-react';
|
|
20
33
|
import React from 'react';
|
|
21
34
|
import ReactDOM from 'react-dom/client';
|
|
22
|
-
import '@codingame/monaco-vscode-python-default-extension';
|
|
23
|
-
import { WrapperConfig } from 'monaco-languageclient/editorApp';
|
|
24
|
-
import { MonacoEditorReactComp } from '@typefox/monaco-editor-react';
|
|
25
|
-
import { configureDefaultWorkerFactory } from 'monaco-editor-wrapper/workers/workerLoaders';
|
|
26
|
-
|
|
27
|
-
const wrapperConfig: WrapperConfig = {
|
|
28
|
-
$type: 'extended',
|
|
29
|
-
htmlContainer: document.getElementById('monaco-editor-root')!,
|
|
30
|
-
editorAppConfig: {
|
|
31
|
-
codeResources: {
|
|
32
|
-
modified: {
|
|
33
|
-
uri: '/workspace/hello.py',
|
|
34
|
-
text: 'print("Hello, World!")'
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
monacoWorkerFactory: configureDefaultWorkerFactory
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const comp = <MonacoEditorReactComp
|
|
42
|
-
wrapperConfig={wrapperConfig}
|
|
43
|
-
style={{ 'height': '100%' }}
|
|
44
|
-
onLoad={(wrapper: MonacoEditorLanguageClientWrapper) => {
|
|
45
|
-
// use the wrapper to get access to monaco-editor or the languageclient
|
|
46
|
-
}}
|
|
47
|
-
/>;
|
|
48
|
-
ReactDOM.createRoot(document.getElementById('react-root')!).render(comp);
|
|
49
35
|
|
|
36
|
+
export const createEditorAndLanguageClient = async () => {
|
|
37
|
+
const languageId = 'mylang';
|
|
38
|
+
const code = '// initial editor content';
|
|
39
|
+
const codeUri = '/workspace/hello.mylang';
|
|
40
|
+
|
|
41
|
+
// Monaco VSCode API configuration
|
|
42
|
+
const vscodeApiConfig: MonacoVscodeApiConfig = {
|
|
43
|
+
$type: 'extended',
|
|
44
|
+
viewsConfig: {
|
|
45
|
+
$type: 'EditorService',
|
|
46
|
+
// the div to which monaco-editor is added
|
|
47
|
+
htmlContainer: document.getElementById('monaco-editor-root')!
|
|
48
|
+
},
|
|
49
|
+
userConfiguration: {
|
|
50
|
+
json: JSON.stringify({
|
|
51
|
+
'workbench.colorTheme': 'Default Dark Modern',
|
|
52
|
+
'editor.wordBasedSuggestions': 'off'
|
|
53
|
+
})
|
|
54
|
+
},
|
|
55
|
+
monacoWorkerFactory: configureDefaultWorkerFactory
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// Language client configuration
|
|
59
|
+
const languageClientConfig: LanguageClientConfig = {
|
|
60
|
+
languageId,
|
|
61
|
+
connection: {
|
|
62
|
+
options: {
|
|
63
|
+
$type: 'WebSocketUrl',
|
|
64
|
+
// at this url the language server for myLang must be reachable
|
|
65
|
+
url: 'ws://localhost:30000/myLangLS'
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
clientOptions: {
|
|
69
|
+
documentSelector: [languageId],
|
|
70
|
+
orkspaceFolder: {
|
|
71
|
+
index: 0,
|
|
72
|
+
name: 'workspace',
|
|
73
|
+
uri: vscode.Uri.file('/workspace')
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// editor app / monaco-editor configuration
|
|
79
|
+
const editorAppConfig: EditorAppConfig = {
|
|
80
|
+
codeResources: {
|
|
81
|
+
main: {
|
|
82
|
+
text: code,
|
|
83
|
+
uri: codeUri
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const root = ReactDOM.createRoot(document.getElementById('react-root')!);
|
|
89
|
+
const App = () => {
|
|
90
|
+
return (
|
|
91
|
+
<div style={{ 'backgroundColor': '#1f1f1f' }} >
|
|
92
|
+
<MonacoEditorReactComp
|
|
93
|
+
vscodeApiConfig={vscodeApiConfig}
|
|
94
|
+
editorAppConfig={editorAppConfig}
|
|
95
|
+
languageClientConfig={languageClientConfig}
|
|
96
|
+
style={{ 'height': '100%' }}
|
|
97
|
+
onError={(e) => {
|
|
98
|
+
console.error(e);
|
|
99
|
+
}} />
|
|
100
|
+
</div>
|
|
101
|
+
);
|
|
102
|
+
};
|
|
103
|
+
root.render(<App />);
|
|
104
|
+
};
|
|
105
|
+
createEditorAndLanguageClient();
|
|
50
106
|
```
|
|
51
107
|
|
|
52
|
-
## Examples
|
|
53
|
-
|
|
54
|
-
For a detailed list of examples please look at [this section](<https://github.com/TypeFox/monaco-languageclient#examples-overview>) in the main repository.
|
|
55
|
-
|
|
56
108
|
## License
|
|
57
109
|
|
|
58
110
|
[MIT](https://github.com/TypeFox/monaco-languageclient/blob/main/packages/wrapper-react/LICENSE)
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EditorApp, type EditorAppConfig, type TextContents } from 'monaco-languageclient/editorApp';
|
|
2
|
-
import { type
|
|
2
|
+
import { type LanguageClientConfig, LanguageClientsManager } from 'monaco-languageclient/lcwrapper';
|
|
3
3
|
import { type MonacoVscodeApiConfig, MonacoVscodeApiWrapper } from 'monaco-languageclient/vscodeApiWrapper';
|
|
4
4
|
import React, { type CSSProperties } from 'react';
|
|
5
5
|
export type ResolveFc = (value: void | PromiseLike<void>) => void;
|
|
@@ -8,14 +8,14 @@ export type MonacoEditorProps = {
|
|
|
8
8
|
className?: string;
|
|
9
9
|
vscodeApiConfig: MonacoVscodeApiConfig;
|
|
10
10
|
editorAppConfig?: EditorAppConfig;
|
|
11
|
-
|
|
11
|
+
languageClientConfig?: LanguageClientConfig;
|
|
12
12
|
onVscodeApiInitDone?: (monacoVscodeApiManager: MonacoVscodeApiWrapper) => void;
|
|
13
13
|
onEditorStartDone?: (editorApp?: EditorApp) => void;
|
|
14
|
-
|
|
14
|
+
onLanguageClientsStartDone?: (lcsManager?: LanguageClientsManager) => void;
|
|
15
15
|
onTextChanged?: (textChanges: TextContents) => void;
|
|
16
16
|
onError?: (error: Error) => void;
|
|
17
17
|
onDisposeEditor?: () => void;
|
|
18
|
-
|
|
18
|
+
onDisposeLanguageClient?: () => void;
|
|
19
19
|
modifiedTextValue?: string;
|
|
20
20
|
originalTextValue?: string;
|
|
21
21
|
};
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,KAAK,eAAe,EAAE,KAAK,YAAY,EAAE,MAAM,iCAAiC,CAAC;AACrG,OAAO,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,KAAK,eAAe,EAAE,KAAK,YAAY,EAAE,MAAM,iCAAiC,CAAC;AACrG,OAAO,EAAE,KAAK,oBAAoB,EAAE,sBAAsB,EAAE,MAAM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} from 'monaco-languageclient/vscodeApiWrapper';
|
|
8
8
|
import React, { useEffect, useRef, useState } from 'react';
|
|
9
9
|
export const MonacoEditorReactComp = (props) => {
|
|
10
|
-
const { style, className, vscodeApiConfig, editorAppConfig,
|
|
10
|
+
const { style, className, vscodeApiConfig, editorAppConfig, languageClientConfig, onVscodeApiInitDone, onEditorStartDone, onLanguageClientsStartDone, onTextChanged, onError, onDisposeEditor, onDisposeLanguageClient, modifiedTextValue, originalTextValue } = props;
|
|
11
11
|
const apiWrapperRef = useRef(new MonacoVscodeApiWrapper(vscodeApiConfig));
|
|
12
12
|
const haveEditorService = useRef(true);
|
|
13
13
|
const editorAppRef = useRef(null);
|
|
@@ -16,6 +16,31 @@ export const MonacoEditorReactComp = (props) => {
|
|
|
16
16
|
const onTextChangedRef = useRef(onTextChanged);
|
|
17
17
|
const [modifiedCode, setModifiedCode] = useState(modifiedTextValue);
|
|
18
18
|
const [originalCode, setOriginalCode] = useState(originalTextValue);
|
|
19
|
+
const runQueue = useRef([]);
|
|
20
|
+
const executeQueue = (id, newfunc) => {
|
|
21
|
+
debugLogging(`Adding to queue: ${id}`);
|
|
22
|
+
debugLogging(`QUEUE SIZE before: ${runQueue.current.length}`);
|
|
23
|
+
runQueue.current.push(newfunc);
|
|
24
|
+
(async () => {
|
|
25
|
+
// always expect to need to await the global init
|
|
26
|
+
await awaitGlobal();
|
|
27
|
+
while (runQueue.current.length > 0) {
|
|
28
|
+
const func = runQueue.current.shift();
|
|
29
|
+
debugLogging('QUEUE FUNC start', true);
|
|
30
|
+
await func?.();
|
|
31
|
+
debugLogging('QUEUE FUNC end');
|
|
32
|
+
}
|
|
33
|
+
debugLogging(`QUEUE SIZE after: ${runQueue.current.length}`);
|
|
34
|
+
})();
|
|
35
|
+
};
|
|
36
|
+
const debugLogging = (id, useTime) => {
|
|
37
|
+
if (useTime === true) {
|
|
38
|
+
apiWrapperRef.current.getLogger().debug(`${id}: ${Date.now()}`);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
apiWrapperRef.current.getLogger().debug(id);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
19
44
|
const performErrorHandling = (error) => {
|
|
20
45
|
if (onError) {
|
|
21
46
|
onError(error);
|
|
@@ -41,7 +66,7 @@ export const MonacoEditorReactComp = (props) => {
|
|
|
41
66
|
const awaitGlobal = async () => {
|
|
42
67
|
// await global init if not completed before doing anything else
|
|
43
68
|
const envEnhanced = getEnhancedMonacoEnvironment();
|
|
44
|
-
return
|
|
69
|
+
return envEnhanced.vscodeApiGlobalInitAwait ?? Promise.resolve();
|
|
45
70
|
};
|
|
46
71
|
const performGlobalInit = async () => {
|
|
47
72
|
if (containerRef.current === null) {
|
|
@@ -49,26 +74,28 @@ export const MonacoEditorReactComp = (props) => {
|
|
|
49
74
|
}
|
|
50
75
|
const envEnhanced = getEnhancedMonacoEnvironment();
|
|
51
76
|
// init will only performed once
|
|
52
|
-
if (
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
77
|
+
if (envEnhanced.vscodeApiInitialising !== true) {
|
|
78
|
+
const globalInitFunc = async () => {
|
|
79
|
+
debugLogging('GLOBAL INIT', true);
|
|
80
|
+
apiWrapperRef.current.overrideViewsConfig({
|
|
81
|
+
$type: apiWrapperRef.current.getMonacoVscodeApiConfig().viewsConfig.$type,
|
|
57
82
|
htmlContainer: containerRef.current
|
|
58
83
|
});
|
|
84
|
+
await apiWrapperRef.current.start();
|
|
59
85
|
// set if editor mode is available, otherwise text bindings will not work
|
|
60
86
|
haveEditorService.current = envEnhanced.viewServiceType === 'EditorService';
|
|
61
87
|
onVscodeApiInitDone?.(apiWrapperRef.current);
|
|
62
|
-
|
|
88
|
+
debugLogging('GLOBAL INIT DONE', true);
|
|
89
|
+
};
|
|
90
|
+
globalInitFunc();
|
|
63
91
|
}
|
|
64
92
|
};
|
|
65
93
|
useEffect(() => {
|
|
66
|
-
// always try to perform
|
|
94
|
+
// always try to perform global init. Reason: we cannot ensure order
|
|
67
95
|
performGlobalInit();
|
|
68
|
-
|
|
96
|
+
const editorInitFunc = async () => {
|
|
69
97
|
try {
|
|
70
|
-
|
|
71
|
-
await awaitGlobal();
|
|
98
|
+
debugLogging('INIT', true);
|
|
72
99
|
// it is possible to run without an editorApp, for example when using the ViewsService
|
|
73
100
|
if (haveEditorService.current) {
|
|
74
101
|
editorAppRef.current = new EditorApp(editorAppConfig);
|
|
@@ -97,55 +124,56 @@ export const MonacoEditorReactComp = (props) => {
|
|
|
97
124
|
modified: modifiedCode
|
|
98
125
|
});
|
|
99
126
|
}
|
|
100
|
-
|
|
127
|
+
debugLogging('INIT DONE', true);
|
|
101
128
|
}
|
|
102
129
|
catch (error) {
|
|
103
130
|
performErrorHandling(error);
|
|
104
131
|
}
|
|
105
|
-
}
|
|
132
|
+
};
|
|
133
|
+
executeQueue('editorInit', editorInitFunc);
|
|
106
134
|
}, [editorAppConfig]);
|
|
107
135
|
useEffect(() => {
|
|
108
|
-
// always try to perform
|
|
136
|
+
// always try to perform global init. Reason: we cannot ensure order
|
|
109
137
|
performGlobalInit();
|
|
110
|
-
if (
|
|
111
|
-
|
|
138
|
+
if (languageClientConfig !== undefined) {
|
|
139
|
+
const lcInitFunc = async () => {
|
|
112
140
|
try {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
lcsManagerRef.current = new LanguageClientsManager(apiWrapperRef.current.getLogger());
|
|
117
|
-
}
|
|
118
|
-
await lcsManagerRef.current.setConfigs(languageClientConfigs);
|
|
141
|
+
debugLogging('INIT LC', true);
|
|
142
|
+
lcsManagerRef.current = new LanguageClientsManager(apiWrapperRef.current.getLogger());
|
|
143
|
+
await lcsManagerRef.current.setConfig(languageClientConfig);
|
|
119
144
|
await lcsManagerRef.current.start();
|
|
120
|
-
|
|
121
|
-
|
|
145
|
+
onLanguageClientsStartDone?.(lcsManagerRef.current);
|
|
146
|
+
debugLogging('INIT LC DONE', true);
|
|
122
147
|
}
|
|
123
148
|
catch (error) {
|
|
124
149
|
performErrorHandling(error);
|
|
125
150
|
}
|
|
126
|
-
}
|
|
151
|
+
};
|
|
152
|
+
executeQueue('lcInit', lcInitFunc);
|
|
127
153
|
}
|
|
128
|
-
}, [
|
|
154
|
+
}, [languageClientConfig]);
|
|
129
155
|
useEffect(() => {
|
|
130
|
-
// always try to perform
|
|
156
|
+
// always try to perform global init. Reason: we cannot ensure order
|
|
131
157
|
performGlobalInit();
|
|
132
158
|
return () => {
|
|
133
|
-
|
|
159
|
+
const disposeFunc = async () => {
|
|
134
160
|
// dispose editor id used and languageclient if enforced
|
|
135
161
|
try {
|
|
136
|
-
|
|
162
|
+
debugLogging('DISPOSE', true);
|
|
137
163
|
await editorAppRef.current?.dispose();
|
|
138
164
|
onDisposeEditor?.();
|
|
139
|
-
if (
|
|
165
|
+
if (languageClientConfig?.enforceDispose === true) {
|
|
140
166
|
lcsManagerRef.current?.dispose();
|
|
141
|
-
|
|
167
|
+
onDisposeLanguageClient?.();
|
|
142
168
|
}
|
|
169
|
+
debugLogging('DISPOSE DONE', true);
|
|
143
170
|
}
|
|
144
171
|
catch (error) {
|
|
145
172
|
// The language client may throw an error during disposal, but we want to continue anyway
|
|
146
173
|
performErrorHandling(new Error(`Unexpected error occurred during disposal of the language client: ${error}`));
|
|
147
174
|
}
|
|
148
|
-
}
|
|
175
|
+
};
|
|
176
|
+
executeQueue('dispose', disposeFunc);
|
|
149
177
|
};
|
|
150
178
|
}, []);
|
|
151
179
|
return (React.createElement("div", { ref: containerRef, style: style, className: className }));
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F,OAAO,EAAE,SAAS,EAA2C,MAAM,iCAAiC,CAAC;AACrG,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA;;;+FAG+F;AA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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typefox/monaco-editor-react",
|
|
3
|
-
"version": "7.0.0-next.
|
|
3
|
+
"version": "7.0.0-next.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "React component for Monaco-Editor and Monaco Languageclient",
|
|
6
6
|
"keywords": [
|
|
@@ -42,11 +42,11 @@
|
|
|
42
42
|
"npm": ">=10.2.3"
|
|
43
43
|
},
|
|
44
44
|
"volta": {
|
|
45
|
-
"node": "22.
|
|
46
|
-
"npm": "10.9.
|
|
45
|
+
"node": "22.19.0",
|
|
46
|
+
"npm": "10.9.3"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@codingame/monaco-vscode-editor-api": "
|
|
49
|
+
"@codingame/monaco-vscode-editor-api": "^21.0.1",
|
|
50
50
|
"react": ">=18.0.0 || <20.0.0"
|
|
51
51
|
},
|
|
52
52
|
"repository": {
|
package/src/index.tsx
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* ------------------------------------------------------------------------------------------ */
|
|
5
5
|
|
|
6
6
|
import { EditorApp, type EditorAppConfig, type TextContents } from 'monaco-languageclient/editorApp';
|
|
7
|
-
import { type
|
|
7
|
+
import { type LanguageClientConfig, LanguageClientsManager } from 'monaco-languageclient/lcwrapper';
|
|
8
8
|
import { getEnhancedMonacoEnvironment, type MonacoVscodeApiConfig, MonacoVscodeApiWrapper } from 'monaco-languageclient/vscodeApiWrapper';
|
|
9
9
|
import React, { type CSSProperties, useEffect, useRef, useState } from 'react';
|
|
10
10
|
|
|
@@ -15,14 +15,14 @@ export type MonacoEditorProps = {
|
|
|
15
15
|
className?: string;
|
|
16
16
|
vscodeApiConfig: MonacoVscodeApiConfig;
|
|
17
17
|
editorAppConfig?: EditorAppConfig;
|
|
18
|
-
|
|
18
|
+
languageClientConfig?: LanguageClientConfig;
|
|
19
19
|
onVscodeApiInitDone?: (monacoVscodeApiManager: MonacoVscodeApiWrapper) => void;
|
|
20
20
|
onEditorStartDone?: (editorApp?: EditorApp) => void;
|
|
21
|
-
|
|
21
|
+
onLanguageClientsStartDone?: (lcsManager?: LanguageClientsManager) => void;
|
|
22
22
|
onTextChanged?: (textChanges: TextContents) => void;
|
|
23
23
|
onError?: (error: Error) => void;
|
|
24
24
|
onDisposeEditor?: () => void;
|
|
25
|
-
|
|
25
|
+
onDisposeLanguageClient?: () => void;
|
|
26
26
|
modifiedTextValue?: string;
|
|
27
27
|
originalTextValue?: string;
|
|
28
28
|
}
|
|
@@ -33,14 +33,14 @@ export const MonacoEditorReactComp: React.FC<MonacoEditorProps> = (props) => {
|
|
|
33
33
|
className,
|
|
34
34
|
vscodeApiConfig,
|
|
35
35
|
editorAppConfig,
|
|
36
|
-
|
|
36
|
+
languageClientConfig,
|
|
37
37
|
onVscodeApiInitDone,
|
|
38
38
|
onEditorStartDone,
|
|
39
|
-
|
|
39
|
+
onLanguageClientsStartDone,
|
|
40
40
|
onTextChanged,
|
|
41
41
|
onError,
|
|
42
42
|
onDisposeEditor,
|
|
43
|
-
|
|
43
|
+
onDisposeLanguageClient,
|
|
44
44
|
modifiedTextValue,
|
|
45
45
|
originalTextValue
|
|
46
46
|
} = props;
|
|
@@ -54,6 +54,34 @@ export const MonacoEditorReactComp: React.FC<MonacoEditorProps> = (props) => {
|
|
|
54
54
|
const [modifiedCode, setModifiedCode] = useState(modifiedTextValue);
|
|
55
55
|
const [originalCode, setOriginalCode] = useState(originalTextValue);
|
|
56
56
|
|
|
57
|
+
const runQueue = useRef<Array<() => Promise<void>>>([]);
|
|
58
|
+
|
|
59
|
+
const executeQueue = (id: string, newfunc: () => Promise<void>) => {
|
|
60
|
+
debugLogging(`Adding to queue: ${id}`);
|
|
61
|
+
debugLogging(`QUEUE SIZE before: ${runQueue.current.length}`);
|
|
62
|
+
runQueue.current.push(newfunc);
|
|
63
|
+
(async () => {
|
|
64
|
+
// always expect to need to await the global init
|
|
65
|
+
await awaitGlobal();
|
|
66
|
+
|
|
67
|
+
while (runQueue.current.length > 0) {
|
|
68
|
+
const func = runQueue.current.shift();
|
|
69
|
+
debugLogging('QUEUE FUNC start', true);
|
|
70
|
+
await func?.();
|
|
71
|
+
debugLogging('QUEUE FUNC end');
|
|
72
|
+
}
|
|
73
|
+
debugLogging(`QUEUE SIZE after: ${runQueue.current.length}`);
|
|
74
|
+
})();
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const debugLogging = (id: string, useTime?: boolean) => {
|
|
78
|
+
if (useTime === true) {
|
|
79
|
+
apiWrapperRef.current.getLogger().debug(`${id}: ${Date.now()}`);
|
|
80
|
+
} else {
|
|
81
|
+
apiWrapperRef.current.getLogger().debug(id);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
57
85
|
const performErrorHandling = (error: Error) => {
|
|
58
86
|
if (onError) {
|
|
59
87
|
onError(error);
|
|
@@ -81,7 +109,7 @@ export const MonacoEditorReactComp: React.FC<MonacoEditorProps> = (props) => {
|
|
|
81
109
|
const awaitGlobal = async () => {
|
|
82
110
|
// await global init if not completed before doing anything else
|
|
83
111
|
const envEnhanced = getEnhancedMonacoEnvironment();
|
|
84
|
-
return
|
|
112
|
+
return envEnhanced.vscodeApiGlobalInitAwait ?? Promise.resolve();
|
|
85
113
|
};
|
|
86
114
|
|
|
87
115
|
const performGlobalInit = async () => {
|
|
@@ -91,31 +119,35 @@ export const MonacoEditorReactComp: React.FC<MonacoEditorProps> = (props) => {
|
|
|
91
119
|
const envEnhanced = getEnhancedMonacoEnvironment();
|
|
92
120
|
|
|
93
121
|
// init will only performed once
|
|
94
|
-
if (
|
|
122
|
+
if (envEnhanced.vscodeApiInitialising !== true) {
|
|
95
123
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
124
|
+
const globalInitFunc = async () => {
|
|
125
|
+
debugLogging('GLOBAL INIT', true);
|
|
126
|
+
|
|
127
|
+
apiWrapperRef.current.overrideViewsConfig({
|
|
128
|
+
$type: apiWrapperRef.current.getMonacoVscodeApiConfig().viewsConfig.$type,
|
|
129
|
+
htmlContainer: containerRef.current!
|
|
101
130
|
});
|
|
131
|
+
await apiWrapperRef.current.start();
|
|
102
132
|
|
|
103
133
|
// set if editor mode is available, otherwise text bindings will not work
|
|
104
134
|
haveEditorService.current = envEnhanced.viewServiceType === 'EditorService';
|
|
105
135
|
|
|
106
136
|
onVscodeApiInitDone?.(apiWrapperRef.current);
|
|
107
|
-
|
|
137
|
+
|
|
138
|
+
debugLogging('GLOBAL INIT DONE', true);
|
|
139
|
+
};
|
|
140
|
+
globalInitFunc();
|
|
108
141
|
}
|
|
109
142
|
};
|
|
110
143
|
|
|
111
144
|
useEffect(() => {
|
|
112
|
-
// always try to perform
|
|
145
|
+
// always try to perform global init. Reason: we cannot ensure order
|
|
113
146
|
performGlobalInit();
|
|
114
147
|
|
|
115
|
-
|
|
148
|
+
const editorInitFunc = async () => {
|
|
116
149
|
try {
|
|
117
|
-
|
|
118
|
-
await awaitGlobal();
|
|
150
|
+
debugLogging('INIT', true);
|
|
119
151
|
|
|
120
152
|
// it is possible to run without an editorApp, for example when using the ViewsService
|
|
121
153
|
if (haveEditorService.current) {
|
|
@@ -148,60 +180,65 @@ export const MonacoEditorReactComp: React.FC<MonacoEditorProps> = (props) => {
|
|
|
148
180
|
modified: modifiedCode
|
|
149
181
|
});
|
|
150
182
|
}
|
|
151
|
-
|
|
183
|
+
|
|
184
|
+
debugLogging('INIT DONE', true);
|
|
152
185
|
} catch (error) {
|
|
153
186
|
performErrorHandling(error as Error);
|
|
154
187
|
}
|
|
155
|
-
}
|
|
188
|
+
};
|
|
189
|
+
executeQueue('editorInit', editorInitFunc);
|
|
156
190
|
}, [editorAppConfig]);
|
|
157
191
|
|
|
158
192
|
useEffect(() => {
|
|
159
|
-
// always try to perform
|
|
193
|
+
// always try to perform global init. Reason: we cannot ensure order
|
|
160
194
|
performGlobalInit();
|
|
161
195
|
|
|
162
|
-
if (
|
|
163
|
-
|
|
196
|
+
if (languageClientConfig !== undefined) {
|
|
197
|
+
const lcInitFunc = async () => {
|
|
164
198
|
try {
|
|
165
|
-
|
|
166
|
-
await awaitGlobal();
|
|
199
|
+
debugLogging('INIT LC', true);
|
|
167
200
|
|
|
168
|
-
|
|
169
|
-
lcsManagerRef.current = new LanguageClientsManager(apiWrapperRef.current.getLogger());
|
|
170
|
-
}
|
|
201
|
+
lcsManagerRef.current = new LanguageClientsManager(apiWrapperRef.current.getLogger());
|
|
171
202
|
|
|
172
|
-
await lcsManagerRef.current.
|
|
203
|
+
await lcsManagerRef.current.setConfig(languageClientConfig);
|
|
173
204
|
await lcsManagerRef.current.start();
|
|
174
205
|
|
|
175
|
-
|
|
176
|
-
|
|
206
|
+
onLanguageClientsStartDone?.(lcsManagerRef.current);
|
|
207
|
+
|
|
208
|
+
debugLogging('INIT LC DONE', true);
|
|
177
209
|
} catch (error) {
|
|
178
210
|
performErrorHandling(error as Error);
|
|
179
211
|
}
|
|
180
|
-
}
|
|
212
|
+
};
|
|
213
|
+
executeQueue('lcInit', lcInitFunc);
|
|
181
214
|
}
|
|
182
|
-
}, [
|
|
215
|
+
}, [languageClientConfig]);
|
|
183
216
|
|
|
184
217
|
useEffect(() => {
|
|
185
|
-
// always try to perform
|
|
218
|
+
// always try to perform global init. Reason: we cannot ensure order
|
|
186
219
|
performGlobalInit();
|
|
187
220
|
|
|
188
221
|
return () => {
|
|
189
|
-
|
|
222
|
+
const disposeFunc = async () => {
|
|
190
223
|
// dispose editor id used and languageclient if enforced
|
|
191
224
|
try {
|
|
192
|
-
|
|
225
|
+
debugLogging('DISPOSE', true);
|
|
226
|
+
|
|
193
227
|
await editorAppRef.current?.dispose();
|
|
194
228
|
onDisposeEditor?.();
|
|
195
229
|
|
|
196
|
-
if (
|
|
230
|
+
if (languageClientConfig?.enforceDispose === true) {
|
|
197
231
|
lcsManagerRef.current?.dispose();
|
|
198
|
-
|
|
232
|
+
onDisposeLanguageClient?.();
|
|
199
233
|
}
|
|
234
|
+
|
|
235
|
+
debugLogging('DISPOSE DONE', true);
|
|
200
236
|
} catch (error) {
|
|
201
237
|
// The language client may throw an error during disposal, but we want to continue anyway
|
|
202
238
|
performErrorHandling(new Error(`Unexpected error occurred during disposal of the language client: ${error}`));
|
|
203
239
|
}
|
|
204
|
-
}
|
|
240
|
+
};
|
|
241
|
+
executeQueue('dispose', disposeFunc);
|
|
205
242
|
};
|
|
206
243
|
}, []);
|
|
207
244
|
|