@typefox/monaco-editor-react 7.1.0 → 7.3.0-next.0
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 +10 -0
- package/lib/index.d.ts +3 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +98 -63
- package/lib/index.js.map +1 -1
- package/package.json +3 -3
- package/src/index.tsx +110 -69
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
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.3.0-next.0] - 2025-11-03
|
|
6
|
+
|
|
7
|
+
- Updated to `monaco-languageclient@10.3.0-next.0`.
|
|
8
|
+
- Updated all `@codingame/monaco-vscode` packages to `22.1.4`.
|
|
9
|
+
|
|
10
|
+
## [7.2.0] - 2025-10-20
|
|
11
|
+
|
|
12
|
+
- Updated to `monaco-languageclient@10.2.0`.
|
|
13
|
+
- Updated all `@codingame/monaco-vscode` packages to `22.1.0`.
|
|
14
|
+
|
|
5
15
|
## [7.1.0] - 2025-09-30
|
|
6
16
|
|
|
7
17
|
- Updated migration guide, relaxed requirement to specify htmlContainer [#966](https://github.com/TypeFox/monaco-languageclient/pull/966).
|
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 LanguageClientConfig,
|
|
2
|
+
import { type LanguageClientConfig, LanguageClientManager } 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;
|
|
@@ -9,9 +9,10 @@ export type MonacoEditorProps = {
|
|
|
9
9
|
vscodeApiConfig: MonacoVscodeApiConfig;
|
|
10
10
|
editorAppConfig?: EditorAppConfig;
|
|
11
11
|
languageClientConfig?: LanguageClientConfig;
|
|
12
|
+
enforceDisposeLanguageClient?: boolean;
|
|
12
13
|
onVscodeApiInitDone?: (monacoVscodeApiManager: MonacoVscodeApiWrapper) => void;
|
|
13
14
|
onEditorStartDone?: (editorApp?: EditorApp) => void;
|
|
14
|
-
onLanguageClientsStartDone?: (lcsManager?:
|
|
15
|
+
onLanguageClientsStartDone?: (lcsManager?: LanguageClientManager) => void;
|
|
15
16
|
onTextChanged?: (textChanges: TextContents) => void;
|
|
16
17
|
onError?: (error: Error) => void;
|
|
17
18
|
onDisposeEditor?: () => void;
|
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,oBAAoB,EAAE,
|
|
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,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AACnG,OAAO,EAAgC,KAAK,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAC;AAC1I,OAAO,KAAK,EAAE,EAAE,KAAK,aAAa,EAAqB,MAAM,OAAO,CAAC;AAErE,MAAM,MAAM,SAAS,GAAG,CAAC,KAAK,EAAE,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC;AAElE,MAAM,MAAM,iBAAiB,GAAG;IAC5B,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,qBAAqB,CAAC;IACvC,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;IAC5C,4BAA4B,CAAC,EAAE,OAAO,CAAC;IACvC,mBAAmB,CAAC,EAAE,CAAC,sBAAsB,EAAE,sBAAsB,KAAK,IAAI,CAAC;IAC/E,iBAAiB,CAAC,EAAE,CAAC,SAAS,CAAC,EAAE,SAAS,KAAK,IAAI,CAAC;IACpD,0BAA0B,CAAC,EAAE,CAAC,UAAU,CAAC,EAAE,qBAAqB,KAAK,IAAI,CAAC;IAC1E,aAAa,CAAC,EAAE,CAAC,WAAW,EAAE,YAAY,KAAK,IAAI,CAAC;IACpD,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,eAAe,CAAC,EAAE,MAAM,IAAI,CAAC;IAC7B,uBAAuB,CAAC,EAAE,MAAM,IAAI,CAAC;IACrC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC9B,CAAA;AAKD,eAAO,MAAM,qBAAqB,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAmQ7D,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -3,35 +3,52 @@
|
|
|
3
3
|
* Licensed under the MIT License. See LICENSE in the package root for license information.
|
|
4
4
|
* ------------------------------------------------------------------------------------------ */
|
|
5
5
|
import { EditorApp } from 'monaco-languageclient/editorApp';
|
|
6
|
-
import {
|
|
6
|
+
import { LanguageClientManager } from 'monaco-languageclient/lcwrapper';
|
|
7
7
|
import { getEnhancedMonacoEnvironment, MonacoVscodeApiWrapper } from 'monaco-languageclient/vscodeApiWrapper';
|
|
8
|
-
import React, { useEffect, useRef
|
|
8
|
+
import React, { useEffect, useRef } from 'react';
|
|
9
|
+
// this must be outside of the component as this is valid across multiple instances
|
|
10
|
+
const lcsManager = new LanguageClientManager();
|
|
9
11
|
export const MonacoEditorReactComp = (props) => {
|
|
10
|
-
const { style, className, vscodeApiConfig, editorAppConfig, languageClientConfig, onVscodeApiInitDone, onEditorStartDone, onLanguageClientsStartDone, onTextChanged, onError, onDisposeEditor, onDisposeLanguageClient, modifiedTextValue, originalTextValue } = props;
|
|
12
|
+
const { style, className, vscodeApiConfig, editorAppConfig, languageClientConfig, enforceDisposeLanguageClient, onVscodeApiInitDone, onEditorStartDone, onLanguageClientsStartDone, onTextChanged, onError, onDisposeEditor, onDisposeLanguageClient, modifiedTextValue, originalTextValue } = props;
|
|
11
13
|
const apiWrapperRef = useRef(new MonacoVscodeApiWrapper(vscodeApiConfig));
|
|
12
14
|
const haveEditorService = useRef(true);
|
|
15
|
+
const currentEditorConfig = useRef(undefined);
|
|
13
16
|
const editorAppRef = useRef(null);
|
|
14
|
-
const lcsManagerRef = useRef(null);
|
|
15
17
|
const containerRef = useRef(null);
|
|
16
18
|
const onTextChangedRef = useRef(onTextChanged);
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
+
const modifiedCode = useRef(modifiedTextValue);
|
|
20
|
+
const originalCode = useRef(originalTextValue);
|
|
19
21
|
const runQueue = useRef([]);
|
|
20
|
-
|
|
22
|
+
let queueAwait = undefined;
|
|
23
|
+
let queueResolve = undefined;
|
|
24
|
+
const addQueue = (id, func) => {
|
|
21
25
|
debugLogging(`Adding to queue: ${id}`);
|
|
22
26
|
debugLogging(`QUEUE SIZE before: ${runQueue.current.length}`);
|
|
23
|
-
runQueue.current.push(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
runQueue.current.push({ id, func });
|
|
28
|
+
};
|
|
29
|
+
const triggerQueue = () => {
|
|
30
|
+
setInterval(() => {
|
|
31
|
+
if (queueAwait === undefined) {
|
|
32
|
+
queueAwait = new Promise((resolve) => {
|
|
33
|
+
queueResolve = resolve;
|
|
34
|
+
});
|
|
35
|
+
executeQueue();
|
|
36
|
+
}
|
|
37
|
+
}, 50);
|
|
38
|
+
};
|
|
39
|
+
const executeQueue = async () => {
|
|
40
|
+
while (runQueue.current.length > 0) {
|
|
41
|
+
const queueObj = runQueue.current.shift();
|
|
42
|
+
if (queueObj !== undefined) {
|
|
43
|
+
debugLogging(`QUEUE ${queueObj.id} start`, true);
|
|
44
|
+
await queueObj.func();
|
|
45
|
+
debugLogging(`QUEUE ${queueObj.id} SIZE after: ${runQueue.current.length}`);
|
|
46
|
+
debugLogging(`QUEUE ${queueObj.id} end`);
|
|
32
47
|
}
|
|
33
|
-
|
|
34
|
-
|
|
48
|
+
}
|
|
49
|
+
queueResolve?.();
|
|
50
|
+
queueAwait = undefined;
|
|
51
|
+
queueResolve = undefined;
|
|
35
52
|
};
|
|
36
53
|
const debugLogging = (id, useTime) => {
|
|
37
54
|
if (useTime === true) {
|
|
@@ -52,22 +69,17 @@ export const MonacoEditorReactComp = (props) => {
|
|
|
52
69
|
useEffect(() => {
|
|
53
70
|
// this is only available if EditorService is configured
|
|
54
71
|
if (modifiedTextValue !== undefined && haveEditorService.current) {
|
|
55
|
-
|
|
72
|
+
modifiedCode.current = modifiedTextValue;
|
|
56
73
|
editorAppRef.current?.updateCode({ modified: modifiedTextValue });
|
|
57
74
|
}
|
|
58
75
|
}, [modifiedTextValue]);
|
|
59
76
|
useEffect(() => {
|
|
60
77
|
// this is only available if EditorService is configured
|
|
61
78
|
if (originalTextValue !== undefined && haveEditorService.current) {
|
|
62
|
-
|
|
79
|
+
originalCode.current = originalTextValue;
|
|
63
80
|
editorAppRef.current?.updateCode({ original: originalTextValue });
|
|
64
81
|
}
|
|
65
82
|
}, [originalTextValue]);
|
|
66
|
-
const awaitGlobal = async () => {
|
|
67
|
-
// await global init if not completed before doing anything else
|
|
68
|
-
const envEnhanced = getEnhancedMonacoEnvironment();
|
|
69
|
-
return envEnhanced.vscodeApiGlobalInitAwait ?? Promise.resolve();
|
|
70
|
-
};
|
|
71
83
|
const performGlobalInit = async () => {
|
|
72
84
|
if (containerRef.current === null) {
|
|
73
85
|
performErrorHandling(new Error('No htmlContainer found! Aborting...'));
|
|
@@ -84,20 +96,35 @@ export const MonacoEditorReactComp = (props) => {
|
|
|
84
96
|
await apiWrapperRef.current.start();
|
|
85
97
|
// set if editor mode is available, otherwise text bindings will not work
|
|
86
98
|
haveEditorService.current = envEnhanced.viewServiceType === 'EditorService';
|
|
99
|
+
lcsManager.setLogger(apiWrapperRef.current.getLogger());
|
|
87
100
|
onVscodeApiInitDone?.(apiWrapperRef.current);
|
|
101
|
+
triggerQueue();
|
|
88
102
|
debugLogging('GLOBAL INIT DONE', true);
|
|
89
103
|
};
|
|
90
104
|
globalInitFunc();
|
|
91
105
|
}
|
|
106
|
+
else if (envEnhanced.vscodeApiInitialised === true) {
|
|
107
|
+
triggerQueue();
|
|
108
|
+
}
|
|
92
109
|
};
|
|
93
110
|
useEffect(() => {
|
|
111
|
+
// fast-fail
|
|
112
|
+
if (editorAppConfig === undefined)
|
|
113
|
+
return;
|
|
94
114
|
// always try to perform global init. Reason: we cannot ensure order
|
|
95
115
|
performGlobalInit();
|
|
116
|
+
let createEditor = false;
|
|
117
|
+
// it is possible to run without an editorApp, for example when using the ViewsService
|
|
118
|
+
if (haveEditorService.current) {
|
|
119
|
+
createEditor = currentEditorConfig.current === undefined || JSON.stringify(editorAppConfig) !== JSON.stringify(currentEditorConfig.current);
|
|
120
|
+
}
|
|
96
121
|
const editorInitFunc = async () => {
|
|
97
122
|
try {
|
|
98
123
|
debugLogging('INIT', true);
|
|
99
|
-
|
|
100
|
-
|
|
124
|
+
if (createEditor) {
|
|
125
|
+
debugLogging('INIT: Creating editor', true);
|
|
126
|
+
editorAppRef.current?.dispose();
|
|
127
|
+
currentEditorConfig.current = editorAppConfig;
|
|
101
128
|
editorAppRef.current = new EditorApp(editorAppConfig);
|
|
102
129
|
if (editorAppRef.current.isStarting() === true || editorAppRef.current.isDisposing() === true) {
|
|
103
130
|
await Promise.all([
|
|
@@ -107,10 +134,10 @@ export const MonacoEditorReactComp = (props) => {
|
|
|
107
134
|
}
|
|
108
135
|
editorAppRef.current.registerOnTextChangedCallback((textChanges) => {
|
|
109
136
|
if (textChanges.modified !== undefined) {
|
|
110
|
-
|
|
137
|
+
modifiedCode.current = textChanges.modified;
|
|
111
138
|
}
|
|
112
139
|
if (textChanges.original !== undefined) {
|
|
113
|
-
|
|
140
|
+
originalCode.current = textChanges.original;
|
|
114
141
|
}
|
|
115
142
|
if (onTextChangedRef.current !== undefined) {
|
|
116
143
|
onTextChangedRef.current(textChanges);
|
|
@@ -118,11 +145,6 @@ export const MonacoEditorReactComp = (props) => {
|
|
|
118
145
|
});
|
|
119
146
|
await editorAppRef.current.start(containerRef.current);
|
|
120
147
|
onEditorStartDone?.(editorAppRef.current);
|
|
121
|
-
// originalTextValue and modifiedTextValue useEffects may happen before
|
|
122
|
-
editorAppRef.current.updateCode({
|
|
123
|
-
original: originalCode,
|
|
124
|
-
modified: modifiedCode
|
|
125
|
-
});
|
|
126
148
|
}
|
|
127
149
|
debugLogging('INIT DONE', true);
|
|
128
150
|
}
|
|
@@ -130,52 +152,65 @@ export const MonacoEditorReactComp = (props) => {
|
|
|
130
152
|
performErrorHandling(error);
|
|
131
153
|
}
|
|
132
154
|
};
|
|
133
|
-
|
|
155
|
+
addQueue('editorInit', editorInitFunc);
|
|
134
156
|
}, [editorAppConfig]);
|
|
135
157
|
useEffect(() => {
|
|
158
|
+
// fast-fail
|
|
159
|
+
if (languageClientConfig === undefined)
|
|
160
|
+
return;
|
|
136
161
|
// always try to perform global init. Reason: we cannot ensure order
|
|
137
162
|
performGlobalInit();
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
};
|
|
152
|
-
executeQueue('lcInit', lcInitFunc);
|
|
153
|
-
}
|
|
163
|
+
const lcInitFunc = async () => {
|
|
164
|
+
try {
|
|
165
|
+
debugLogging('INIT LC2', true);
|
|
166
|
+
await lcsManager.setConfig(languageClientConfig);
|
|
167
|
+
await lcsManager.start();
|
|
168
|
+
onLanguageClientsStartDone?.(lcsManager);
|
|
169
|
+
debugLogging('INIT LC DONE', true);
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
performErrorHandling(error);
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
addQueue('lcInit', lcInitFunc);
|
|
154
176
|
}, [languageClientConfig]);
|
|
155
177
|
useEffect(() => {
|
|
178
|
+
// this part runs on mount (componentDidMount)
|
|
156
179
|
// always try to perform global init. Reason: we cannot ensure order
|
|
157
180
|
performGlobalInit();
|
|
181
|
+
// this part runs on unmount (componentWillUnmount)
|
|
158
182
|
return () => {
|
|
159
183
|
const disposeFunc = async () => {
|
|
160
|
-
// dispose editor
|
|
184
|
+
// dispose editor if used
|
|
185
|
+
debugLogging('DISPOSE', true);
|
|
186
|
+
await editorAppRef.current?.dispose();
|
|
187
|
+
onDisposeEditor?.();
|
|
188
|
+
editorAppRef.current = null;
|
|
189
|
+
debugLogging('DISPOSE DONE', true);
|
|
190
|
+
};
|
|
191
|
+
addQueue('dispose', disposeFunc);
|
|
192
|
+
};
|
|
193
|
+
}, []);
|
|
194
|
+
useEffect(() => {
|
|
195
|
+
// always try to perform global init. Reason: we cannot ensure order
|
|
196
|
+
performGlobalInit();
|
|
197
|
+
if (enforceDisposeLanguageClient === true) {
|
|
198
|
+
const disposeLCFunc = async () => {
|
|
199
|
+
// dispose editor if used
|
|
161
200
|
try {
|
|
162
|
-
debugLogging('DISPOSE', true);
|
|
163
|
-
await
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
lcsManagerRef.current?.dispose();
|
|
167
|
-
onDisposeLanguageClient?.();
|
|
168
|
-
}
|
|
169
|
-
debugLogging('DISPOSE DONE', true);
|
|
201
|
+
debugLogging('DISPOSE LC', true);
|
|
202
|
+
await lcsManager.dispose();
|
|
203
|
+
onDisposeLanguageClient?.();
|
|
204
|
+
debugLogging('DISPOSE LC DONE', true);
|
|
170
205
|
}
|
|
171
206
|
catch (error) {
|
|
172
207
|
// The language client may throw an error during disposal, but we want to continue anyway
|
|
173
208
|
performErrorHandling(new Error(`Unexpected error occurred during disposal of the language client: ${error}`));
|
|
174
209
|
}
|
|
175
210
|
};
|
|
176
|
-
|
|
177
|
-
}
|
|
178
|
-
}, []);
|
|
211
|
+
addQueue('dispose lc', disposeLCFunc);
|
|
212
|
+
}
|
|
213
|
+
}, [enforceDisposeLanguageClient]);
|
|
179
214
|
return (React.createElement("div", { ref: containerRef, style: style, className: className }));
|
|
180
215
|
};
|
|
181
216
|
//# sourceMappingURL=index.js.map
|
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,EAA6B,
|
|
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,EAA6B,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AACnG,OAAO,EAAE,4BAA4B,EAA8B,sBAAsB,EAAE,MAAM,wCAAwC,CAAC;AAC1I,OAAO,KAAK,EAAE,EAAsB,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAsBrE,mFAAmF;AACnF,MAAM,UAAU,GAAG,IAAI,qBAAqB,EAAE,CAAC;AAE/C,MAAM,CAAC,MAAM,qBAAqB,GAAgC,CAAC,KAAK,EAAE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AC,OAAO,GAAG,IAAI,CAAC;gBAE5B,YAAY,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC;YAAA,CACtC,CAAC;YACF,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;QAAA,CACpC,CAAC;IAAA,CACL,EAAE,EAAE,CAAC,CAAC;IAEP,SAAS,CAAC,GAAG,EAAE,CAAC;QACZ,oEAAoE;QACpE,iBAAiB,EAAE,CAAC;QAEpB,IAAI,4BAA4B,KAAK,IAAI,EAAE,CAAC;YACxC,MAAM,aAAa,GAAG,KAAK,IAAI,EAAE,CAAC;gBAC9B,yBAAyB;gBACzB,IAAI,CAAC;oBACD,YAAY,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;oBAEjC,MAAM,UAAU,CAAC,OAAO,EAAE,CAAC;oBAC3B,uBAAuB,EAAE,EAAE,CAAC;oBAE5B,YAAY,CAAC,iBAAiB,EAAE,IAAI,CAAC,CAAC;gBAC1C,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACb,yFAAyF;oBACzF,oBAAoB,CAAC,IAAI,KAAK,CAAC,qEAAqE,KAAK,EAAE,CAAC,CAAC,CAAC;gBAClH,CAAC;YAAA,CACJ,CAAC;YACF,QAAQ,CAAC,YAAY,EAAE,aAAa,CAAC,CAAC;QAC1C,CAAC;IAAA,CACJ,EAAE,CAAC,4BAA4B,CAAC,CAAC,CAAC;IAEnC,OAAO,CACH,6BACI,GAAG,EAAE,YAAY,EACjB,KAAK,EAAE,KAAK,EACZ,SAAS,EAAE,SAAS,GACtB,CACL,CAAC;AAAA,CACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typefox/monaco-editor-react",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.3.0-next.0",
|
|
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.
|
|
45
|
+
"node": "22.20.0",
|
|
46
46
|
"npm": "10.9.3"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@codingame/monaco-vscode-editor-api": "^
|
|
49
|
+
"@codingame/monaco-vscode-editor-api": "^22.1.3",
|
|
50
50
|
"react": ">=18.0.0 || <20.0.0"
|
|
51
51
|
},
|
|
52
52
|
"repository": {
|
package/src/index.tsx
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
* ------------------------------------------------------------------------------------------ */
|
|
5
5
|
|
|
6
6
|
import { EditorApp, type EditorAppConfig, type TextContents } from 'monaco-languageclient/editorApp';
|
|
7
|
-
import { type LanguageClientConfig,
|
|
7
|
+
import { type LanguageClientConfig, LanguageClientManager } from 'monaco-languageclient/lcwrapper';
|
|
8
8
|
import { getEnhancedMonacoEnvironment, type MonacoVscodeApiConfig, MonacoVscodeApiWrapper } from 'monaco-languageclient/vscodeApiWrapper';
|
|
9
|
-
import React, { type CSSProperties, useEffect, useRef
|
|
9
|
+
import React, { type CSSProperties, useEffect, useRef } from 'react';
|
|
10
10
|
|
|
11
11
|
export type ResolveFc = (value: void | PromiseLike<void>) => void;
|
|
12
12
|
|
|
@@ -16,9 +16,10 @@ export type MonacoEditorProps = {
|
|
|
16
16
|
vscodeApiConfig: MonacoVscodeApiConfig;
|
|
17
17
|
editorAppConfig?: EditorAppConfig;
|
|
18
18
|
languageClientConfig?: LanguageClientConfig;
|
|
19
|
+
enforceDisposeLanguageClient?: boolean;
|
|
19
20
|
onVscodeApiInitDone?: (monacoVscodeApiManager: MonacoVscodeApiWrapper) => void;
|
|
20
21
|
onEditorStartDone?: (editorApp?: EditorApp) => void;
|
|
21
|
-
onLanguageClientsStartDone?: (lcsManager?:
|
|
22
|
+
onLanguageClientsStartDone?: (lcsManager?: LanguageClientManager) => void;
|
|
22
23
|
onTextChanged?: (textChanges: TextContents) => void;
|
|
23
24
|
onError?: (error: Error) => void;
|
|
24
25
|
onDisposeEditor?: () => void;
|
|
@@ -27,6 +28,9 @@ export type MonacoEditorProps = {
|
|
|
27
28
|
originalTextValue?: string;
|
|
28
29
|
}
|
|
29
30
|
|
|
31
|
+
// this must be outside of the component as this is valid across multiple instances
|
|
32
|
+
const lcsManager = new LanguageClientManager();
|
|
33
|
+
|
|
30
34
|
export const MonacoEditorReactComp: React.FC<MonacoEditorProps> = (props) => {
|
|
31
35
|
const {
|
|
32
36
|
style,
|
|
@@ -34,6 +38,7 @@ export const MonacoEditorReactComp: React.FC<MonacoEditorProps> = (props) => {
|
|
|
34
38
|
vscodeApiConfig,
|
|
35
39
|
editorAppConfig,
|
|
36
40
|
languageClientConfig,
|
|
41
|
+
enforceDisposeLanguageClient,
|
|
37
42
|
onVscodeApiInitDone,
|
|
38
43
|
onEditorStartDone,
|
|
39
44
|
onLanguageClientsStartDone,
|
|
@@ -47,31 +52,47 @@ export const MonacoEditorReactComp: React.FC<MonacoEditorProps> = (props) => {
|
|
|
47
52
|
|
|
48
53
|
const apiWrapperRef = useRef<MonacoVscodeApiWrapper>(new MonacoVscodeApiWrapper(vscodeApiConfig));
|
|
49
54
|
const haveEditorService = useRef(true);
|
|
55
|
+
const currentEditorConfig = useRef<EditorAppConfig | undefined>(undefined);
|
|
50
56
|
const editorAppRef = useRef<EditorApp>(null);
|
|
51
|
-
const lcsManagerRef = useRef<LanguageClientsManager>(null);
|
|
52
57
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
53
58
|
const onTextChangedRef = useRef(onTextChanged);
|
|
54
|
-
const
|
|
55
|
-
const
|
|
59
|
+
const modifiedCode = useRef<string>(modifiedTextValue);
|
|
60
|
+
const originalCode = useRef<string>(originalTextValue);
|
|
56
61
|
|
|
57
|
-
const runQueue = useRef<Array<() => Promise<void
|
|
62
|
+
const runQueue = useRef<Array<{id: string, func: () => Promise<void>}>>([]);
|
|
63
|
+
let queueAwait: Promise<void> | undefined = undefined;
|
|
64
|
+
let queueResolve: ((value: void | PromiseLike<void>) => void) | undefined = undefined;
|
|
58
65
|
|
|
59
|
-
const
|
|
66
|
+
const addQueue = (id: string, func: () => Promise<void>) => {
|
|
60
67
|
debugLogging(`Adding to queue: ${id}`);
|
|
61
68
|
debugLogging(`QUEUE SIZE before: ${runQueue.current.length}`);
|
|
62
|
-
runQueue.current.push(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
runQueue.current.push({id, func});
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const triggerQueue = () => {
|
|
73
|
+
setInterval(() => {
|
|
74
|
+
if (queueAwait === undefined) {
|
|
75
|
+
queueAwait = new Promise<void>((resolve) => {
|
|
76
|
+
queueResolve = resolve;
|
|
77
|
+
});
|
|
78
|
+
executeQueue();
|
|
79
|
+
}
|
|
80
|
+
}, 50);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const executeQueue = async () => {
|
|
84
|
+
while (runQueue.current.length > 0) {
|
|
85
|
+
const queueObj = runQueue.current.shift();
|
|
86
|
+
if (queueObj !== undefined) {
|
|
87
|
+
debugLogging(`QUEUE ${queueObj.id} start`, true);
|
|
88
|
+
await queueObj.func();
|
|
89
|
+
debugLogging(`QUEUE ${queueObj.id} SIZE after: ${runQueue.current.length}`);
|
|
90
|
+
debugLogging(`QUEUE ${queueObj.id} end`);
|
|
72
91
|
}
|
|
73
|
-
|
|
74
|
-
|
|
92
|
+
}
|
|
93
|
+
queueResolve?.();
|
|
94
|
+
queueAwait = undefined;
|
|
95
|
+
queueResolve = undefined;
|
|
75
96
|
};
|
|
76
97
|
|
|
77
98
|
const debugLogging = (id: string, useTime?: boolean) => {
|
|
@@ -93,7 +114,7 @@ export const MonacoEditorReactComp: React.FC<MonacoEditorProps> = (props) => {
|
|
|
93
114
|
useEffect(() => {
|
|
94
115
|
// this is only available if EditorService is configured
|
|
95
116
|
if (modifiedTextValue !== undefined && haveEditorService.current) {
|
|
96
|
-
|
|
117
|
+
modifiedCode.current = modifiedTextValue;
|
|
97
118
|
editorAppRef.current?.updateCode({modified: modifiedTextValue});
|
|
98
119
|
}
|
|
99
120
|
}, [modifiedTextValue]);
|
|
@@ -101,17 +122,11 @@ export const MonacoEditorReactComp: React.FC<MonacoEditorProps> = (props) => {
|
|
|
101
122
|
useEffect(() => {
|
|
102
123
|
// this is only available if EditorService is configured
|
|
103
124
|
if (originalTextValue !== undefined && haveEditorService.current) {
|
|
104
|
-
|
|
125
|
+
originalCode.current = originalTextValue;
|
|
105
126
|
editorAppRef.current?.updateCode({original: originalTextValue});
|
|
106
127
|
}
|
|
107
128
|
}, [originalTextValue]);
|
|
108
129
|
|
|
109
|
-
const awaitGlobal = async () => {
|
|
110
|
-
// await global init if not completed before doing anything else
|
|
111
|
-
const envEnhanced = getEnhancedMonacoEnvironment();
|
|
112
|
-
return envEnhanced.vscodeApiGlobalInitAwait ?? Promise.resolve();
|
|
113
|
-
};
|
|
114
|
-
|
|
115
130
|
const performGlobalInit = async () => {
|
|
116
131
|
if (containerRef.current === null) {
|
|
117
132
|
performErrorHandling(new Error('No htmlContainer found! Aborting...'));
|
|
@@ -132,25 +147,41 @@ export const MonacoEditorReactComp: React.FC<MonacoEditorProps> = (props) => {
|
|
|
132
147
|
|
|
133
148
|
// set if editor mode is available, otherwise text bindings will not work
|
|
134
149
|
haveEditorService.current = envEnhanced.viewServiceType === 'EditorService';
|
|
150
|
+
lcsManager.setLogger(apiWrapperRef.current.getLogger());
|
|
135
151
|
|
|
136
152
|
onVscodeApiInitDone?.(apiWrapperRef.current);
|
|
137
|
-
|
|
153
|
+
triggerQueue();
|
|
138
154
|
debugLogging('GLOBAL INIT DONE', true);
|
|
139
155
|
};
|
|
140
156
|
globalInitFunc();
|
|
157
|
+
} else if (envEnhanced.vscodeApiInitialised === true) {
|
|
158
|
+
triggerQueue();
|
|
141
159
|
}
|
|
142
160
|
};
|
|
143
161
|
|
|
144
162
|
useEffect(() => {
|
|
163
|
+
// fast-fail
|
|
164
|
+
if (editorAppConfig === undefined) return;
|
|
165
|
+
|
|
145
166
|
// always try to perform global init. Reason: we cannot ensure order
|
|
146
167
|
performGlobalInit();
|
|
147
168
|
|
|
169
|
+
let createEditor = false;
|
|
170
|
+
// it is possible to run without an editorApp, for example when using the ViewsService
|
|
171
|
+
if (haveEditorService.current) {
|
|
172
|
+
createEditor = currentEditorConfig.current === undefined || JSON.stringify(editorAppConfig) !== JSON.stringify(currentEditorConfig.current);
|
|
173
|
+
}
|
|
174
|
+
|
|
148
175
|
const editorInitFunc = async () => {
|
|
149
176
|
try {
|
|
150
177
|
debugLogging('INIT', true);
|
|
151
178
|
|
|
152
|
-
|
|
153
|
-
|
|
179
|
+
if (createEditor) {
|
|
180
|
+
debugLogging('INIT: Creating editor', true);
|
|
181
|
+
|
|
182
|
+
editorAppRef.current?.dispose();
|
|
183
|
+
|
|
184
|
+
currentEditorConfig.current = editorAppConfig;
|
|
154
185
|
editorAppRef.current = new EditorApp(editorAppConfig);
|
|
155
186
|
if (editorAppRef.current.isStarting() === true || editorAppRef.current.isDisposing() === true) {
|
|
156
187
|
await Promise.all([
|
|
@@ -161,10 +192,10 @@ export const MonacoEditorReactComp: React.FC<MonacoEditorProps> = (props) => {
|
|
|
161
192
|
|
|
162
193
|
editorAppRef.current.registerOnTextChangedCallback((textChanges) => {
|
|
163
194
|
if (textChanges.modified !== undefined) {
|
|
164
|
-
|
|
195
|
+
modifiedCode.current = textChanges.modified;
|
|
165
196
|
}
|
|
166
197
|
if (textChanges.original !== undefined) {
|
|
167
|
-
|
|
198
|
+
originalCode.current = textChanges.original;
|
|
168
199
|
}
|
|
169
200
|
if (onTextChangedRef.current !== undefined) {
|
|
170
201
|
onTextChangedRef.current(textChanges);
|
|
@@ -173,12 +204,6 @@ export const MonacoEditorReactComp: React.FC<MonacoEditorProps> = (props) => {
|
|
|
173
204
|
await editorAppRef.current.start(containerRef.current!);
|
|
174
205
|
|
|
175
206
|
onEditorStartDone?.(editorAppRef.current);
|
|
176
|
-
|
|
177
|
-
// originalTextValue and modifiedTextValue useEffects may happen before
|
|
178
|
-
editorAppRef.current.updateCode({
|
|
179
|
-
original: originalCode,
|
|
180
|
-
modified: modifiedCode
|
|
181
|
-
});
|
|
182
207
|
}
|
|
183
208
|
|
|
184
209
|
debugLogging('INIT DONE', true);
|
|
@@ -186,61 +211,77 @@ export const MonacoEditorReactComp: React.FC<MonacoEditorProps> = (props) => {
|
|
|
186
211
|
performErrorHandling(error as Error);
|
|
187
212
|
}
|
|
188
213
|
};
|
|
189
|
-
|
|
214
|
+
addQueue('editorInit', editorInitFunc);
|
|
190
215
|
}, [editorAppConfig]);
|
|
191
216
|
|
|
192
217
|
useEffect(() => {
|
|
218
|
+
// fast-fail
|
|
219
|
+
if (languageClientConfig === undefined) return;
|
|
220
|
+
|
|
193
221
|
// always try to perform global init. Reason: we cannot ensure order
|
|
194
222
|
performGlobalInit();
|
|
195
223
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
debugLogging('INIT LC', true);
|
|
200
|
-
|
|
201
|
-
lcsManagerRef.current = new LanguageClientsManager(apiWrapperRef.current.getLogger());
|
|
224
|
+
const lcInitFunc = async () => {
|
|
225
|
+
try {
|
|
226
|
+
debugLogging('INIT LC2', true);
|
|
202
227
|
|
|
203
|
-
|
|
204
|
-
|
|
228
|
+
await lcsManager.setConfig(languageClientConfig);
|
|
229
|
+
await lcsManager.start();
|
|
205
230
|
|
|
206
|
-
|
|
231
|
+
onLanguageClientsStartDone?.(lcsManager);
|
|
207
232
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
}
|
|
233
|
+
debugLogging('INIT LC DONE', true);
|
|
234
|
+
} catch (error) {
|
|
235
|
+
performErrorHandling(error as Error);
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
addQueue('lcInit', lcInitFunc);
|
|
215
239
|
}, [languageClientConfig]);
|
|
216
240
|
|
|
217
241
|
useEffect(() => {
|
|
242
|
+
// this part runs on mount (componentDidMount)
|
|
243
|
+
|
|
218
244
|
// always try to perform global init. Reason: we cannot ensure order
|
|
219
245
|
performGlobalInit();
|
|
220
246
|
|
|
247
|
+
// this part runs on unmount (componentWillUnmount)
|
|
221
248
|
return () => {
|
|
222
249
|
const disposeFunc = async () => {
|
|
223
|
-
// dispose editor
|
|
224
|
-
|
|
225
|
-
debugLogging('DISPOSE', true);
|
|
250
|
+
// dispose editor if used
|
|
251
|
+
debugLogging('DISPOSE', true);
|
|
226
252
|
|
|
227
|
-
|
|
228
|
-
|
|
253
|
+
await editorAppRef.current?.dispose();
|
|
254
|
+
onDisposeEditor?.();
|
|
255
|
+
editorAppRef.current = null;
|
|
229
256
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
257
|
+
debugLogging('DISPOSE DONE', true);
|
|
258
|
+
};
|
|
259
|
+
addQueue('dispose', disposeFunc);
|
|
260
|
+
};
|
|
261
|
+
}, []);
|
|
262
|
+
|
|
263
|
+
useEffect(() => {
|
|
264
|
+
// always try to perform global init. Reason: we cannot ensure order
|
|
265
|
+
performGlobalInit();
|
|
234
266
|
|
|
235
|
-
|
|
267
|
+
if (enforceDisposeLanguageClient === true) {
|
|
268
|
+
const disposeLCFunc = async () => {
|
|
269
|
+
// dispose editor if used
|
|
270
|
+
try {
|
|
271
|
+
debugLogging('DISPOSE LC', true);
|
|
272
|
+
|
|
273
|
+
await lcsManager.dispose();
|
|
274
|
+
onDisposeLanguageClient?.();
|
|
275
|
+
|
|
276
|
+
debugLogging('DISPOSE LC DONE', true);
|
|
236
277
|
} catch (error) {
|
|
237
278
|
// The language client may throw an error during disposal, but we want to continue anyway
|
|
238
279
|
performErrorHandling(new Error(`Unexpected error occurred during disposal of the language client: ${error}`));
|
|
239
280
|
}
|
|
240
281
|
};
|
|
241
|
-
|
|
242
|
-
}
|
|
243
|
-
}, []);
|
|
282
|
+
addQueue('dispose lc', disposeLCFunc);
|
|
283
|
+
}
|
|
284
|
+
}, [enforceDisposeLanguageClient]);
|
|
244
285
|
|
|
245
286
|
return (
|
|
246
287
|
<div
|