monaco-languageclient 9.11.0 → 10.0.0-next.1
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 +4 -0
- package/lib/{commonTypes.d.ts → common/commonTypes.d.ts} +2 -2
- package/lib/common/commonTypes.d.ts.map +1 -0
- package/lib/common/commonTypes.js +6 -0
- package/lib/common/commonTypes.js.map +1 -0
- package/lib/common/index.d.ts +4 -0
- package/lib/common/index.d.ts.map +1 -0
- package/lib/{tools → common}/index.js +1 -0
- package/lib/common/index.js.map +1 -0
- package/lib/common/logging.d.ts.map +1 -0
- package/lib/common/logging.js.map +1 -0
- package/lib/common/utils.d.ts +5 -0
- package/lib/common/utils.d.ts.map +1 -0
- package/lib/{tools → common}/utils.js +14 -0
- package/lib/common/utils.js.map +1 -0
- package/lib/editorApp/config.d.ts +55 -0
- package/lib/editorApp/config.d.ts.map +1 -0
- package/lib/editorApp/config.js +13 -0
- package/lib/editorApp/config.js.map +1 -0
- package/lib/editorApp/editorApp.d.ts +60 -0
- package/lib/editorApp/editorApp.d.ts.map +1 -0
- package/lib/editorApp/editorApp.js +394 -0
- package/lib/editorApp/editorApp.js.map +1 -0
- package/lib/editorApp/index.d.ts +3 -0
- package/lib/editorApp/index.d.ts.map +1 -0
- package/lib/editorApp/index.js +7 -0
- package/lib/editorApp/index.js.map +1 -0
- package/lib/fs/definitions.d.ts +1 -1
- package/lib/fs/definitions.d.ts.map +1 -1
- package/lib/fs/endpoints/defaultEndpoint.d.ts +1 -1
- package/lib/fs/endpoints/defaultEndpoint.d.ts.map +1 -1
- package/lib/index.d.ts +15 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +18 -2
- package/lib/index.js.map +1 -1
- package/lib/vscode/apiWrapper.d.ts +62 -0
- package/lib/vscode/apiWrapper.d.ts.map +1 -0
- package/lib/vscode/apiWrapper.js +299 -0
- package/lib/vscode/apiWrapper.js.map +1 -0
- package/lib/vscode/config.d.ts +46 -0
- package/lib/vscode/config.d.ts.map +1 -0
- package/lib/vscode/config.js +7 -0
- package/lib/vscode/config.js.map +1 -0
- package/lib/vscode/index.d.ts +4 -2
- package/lib/vscode/index.d.ts.map +1 -1
- package/lib/vscode/index.js +4 -2
- package/lib/vscode/index.js.map +1 -1
- package/lib/vscode/locales.d.ts +5 -0
- package/lib/vscode/locales.d.ts.map +1 -0
- package/lib/vscode/locales.js +124 -0
- package/lib/vscode/locales.js.map +1 -0
- package/lib/vscode/utils.d.ts +13 -0
- package/lib/vscode/utils.d.ts.map +1 -0
- package/lib/vscode/utils.js +56 -0
- package/lib/vscode/utils.js.map +1 -0
- package/lib/vscode/viewsService.d.ts +4 -0
- package/lib/vscode/viewsService.d.ts.map +1 -0
- package/lib/vscode/viewsService.js +67 -0
- package/lib/vscode/viewsService.js.map +1 -0
- package/lib/{vscode → worker}/fakeWorker.d.ts.map +1 -1
- package/lib/{vscode → worker}/fakeWorker.js.map +1 -1
- package/lib/worker/index.d.ts +4 -0
- package/lib/worker/index.d.ts.map +1 -0
- package/lib/worker/index.js +8 -0
- package/lib/worker/index.js.map +1 -0
- package/lib/{workerFactory.d.ts → worker/workerFactory.d.ts} +1 -1
- package/lib/worker/workerFactory.d.ts.map +1 -0
- package/lib/{workerFactory.js → worker/workerFactory.js} +1 -1
- package/lib/worker/workerFactory.js.map +1 -0
- package/lib/worker/workerLoaders.d.ts +5 -0
- package/lib/worker/workerLoaders.d.ts.map +1 -0
- package/lib/worker/workerLoaders.js +26 -0
- package/lib/worker/workerLoaders.js.map +1 -0
- package/lib/wrapper/index.d.ts +4 -0
- package/lib/wrapper/index.d.ts.map +1 -0
- package/lib/wrapper/index.js +8 -0
- package/lib/wrapper/index.js.map +1 -0
- package/lib/wrapper/lcconfig.d.ts +24 -0
- package/lib/wrapper/lcconfig.d.ts.map +1 -0
- package/lib/wrapper/lcconfig.js +6 -0
- package/lib/wrapper/lcconfig.js.map +1 -0
- package/lib/wrapper/lcmanager.d.ts +18 -0
- package/lib/wrapper/lcmanager.d.ts.map +1 -0
- package/lib/wrapper/lcmanager.js +75 -0
- package/lib/wrapper/lcmanager.js.map +1 -0
- package/lib/wrapper/lcwrapper.d.ts +37 -0
- package/lib/wrapper/lcwrapper.d.ts.map +1 -0
- package/lib/wrapper/lcwrapper.js +247 -0
- package/lib/wrapper/lcwrapper.js.map +1 -0
- package/package.json +61 -18
- package/src/{commonTypes.ts → common/commonTypes.ts} +2 -2
- package/src/{tools → common}/index.ts +1 -0
- package/src/{tools → common}/utils.ts +16 -1
- package/src/editorApp/config.ts +67 -0
- package/src/editorApp/editorApp.ts +448 -0
- package/{lib/commonTypes.js → src/editorApp/index.ts} +3 -2
- package/src/fs/definitions.ts +1 -1
- package/src/fs/endpoints/defaultEndpoint.ts +1 -1
- package/src/index.ts +29 -2
- package/src/vscode/apiWrapper.ts +341 -0
- package/src/vscode/config.ts +55 -0
- package/src/vscode/index.ts +4 -2
- package/src/vscode/locales.ts +128 -0
- package/src/vscode/utils.ts +67 -0
- package/src/vscode/viewsService.ts +73 -0
- package/src/worker/index.ts +8 -0
- package/src/{workerFactory.ts → worker/workerFactory.ts} +2 -2
- package/src/worker/workerLoaders.ts +36 -0
- package/src/wrapper/index.ts +8 -0
- package/src/wrapper/lcconfig.ts +32 -0
- package/src/wrapper/lcmanager.ts +89 -0
- package/src/wrapper/lcwrapper.ts +280 -0
- package/lib/client.d.ts +0 -13
- package/lib/client.d.ts.map +0 -1
- package/lib/client.js +0 -16
- package/lib/client.js.map +0 -1
- package/lib/commonTypes.d.ts.map +0 -1
- package/lib/commonTypes.js.map +0 -1
- package/lib/tools/index.d.ts +0 -3
- package/lib/tools/index.d.ts.map +0 -1
- package/lib/tools/index.js.map +0 -1
- package/lib/tools/logging.d.ts.map +0 -1
- package/lib/tools/logging.js.map +0 -1
- package/lib/tools/utils.d.ts +0 -3
- package/lib/tools/utils.d.ts.map +0 -1
- package/lib/tools/utils.js.map +0 -1
- package/lib/vscode/services.d.ts +0 -64
- package/lib/vscode/services.d.ts.map +0 -1
- package/lib/vscode/services.js +0 -192
- package/lib/vscode/services.js.map +0 -1
- package/lib/workerFactory.d.ts.map +0 -1
- package/lib/workerFactory.js.map +0 -1
- package/src/client.ts +0 -26
- package/src/vscode/services.ts +0 -249
- /package/lib/{tools → common}/logging.d.ts +0 -0
- /package/lib/{tools → common}/logging.js +0 -0
- /package/lib/{vscode → worker}/fakeWorker.d.ts +0 -0
- /package/lib/{vscode → worker}/fakeWorker.js +0 -0
- /package/src/{tools → common}/logging.ts +0 -0
- /package/src/{vscode → worker}/fakeWorker.ts +0 -0
|
@@ -0,0 +1,448 @@
|
|
|
1
|
+
/* --------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) 2024 TypeFox and others.
|
|
3
|
+
* Licensed under the MIT License. See LICENSE in the package root for license information.
|
|
4
|
+
* ------------------------------------------------------------------------------------------ */
|
|
5
|
+
|
|
6
|
+
import { ConfigurationTarget, IConfigurationService, LogLevel, StandaloneServices } from '@codingame/monaco-vscode-api';
|
|
7
|
+
import { createModelReference, type ITextFileEditorModel } from '@codingame/monaco-vscode-api/monaco';
|
|
8
|
+
import * as monaco from '@codingame/monaco-vscode-editor-api';
|
|
9
|
+
import type { IReference } from '@codingame/monaco-vscode-editor-service-override';
|
|
10
|
+
import { ConsoleLogger, type Logger } from 'monaco-languageclient/common';
|
|
11
|
+
import { getEnhancedMonacoEnvironment, type OverallConfigType } from 'monaco-languageclient/vscodeApiWrapper';
|
|
12
|
+
import * as vscode from 'vscode';
|
|
13
|
+
import type { CallbackDisposeable, CodeContent, CodeResources, DisposableModelRefs, EditorAppConfig, TextContents, TextModels } from './config.js';
|
|
14
|
+
import { ModelRefs } from './config.js';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* This is the base class for both Monaco Editor Apps:
|
|
18
|
+
* - EditorAppClassic
|
|
19
|
+
* - EditorAppExtended
|
|
20
|
+
*
|
|
21
|
+
* It provides the generic functionality for both implementations.
|
|
22
|
+
*/
|
|
23
|
+
export class EditorApp {
|
|
24
|
+
|
|
25
|
+
private $type: OverallConfigType;
|
|
26
|
+
private id: string;
|
|
27
|
+
private config: EditorAppConfig;
|
|
28
|
+
|
|
29
|
+
protected logger: Logger = new ConsoleLogger();
|
|
30
|
+
|
|
31
|
+
private editor: monaco.editor.IStandaloneCodeEditor | undefined;
|
|
32
|
+
private diffEditor: monaco.editor.IStandaloneDiffEditor | undefined;
|
|
33
|
+
|
|
34
|
+
private modelRefs: ModelRefs = new ModelRefs();
|
|
35
|
+
|
|
36
|
+
private onTextChanged?: (textChanges: TextContents) => void;
|
|
37
|
+
private textChangedDisposables: CallbackDisposeable = {};
|
|
38
|
+
private modelDisposables: DisposableModelRefs = {};
|
|
39
|
+
|
|
40
|
+
private modelRefDisposeTimeout = -1;
|
|
41
|
+
|
|
42
|
+
private startingAwait?: Promise<void>;
|
|
43
|
+
|
|
44
|
+
private disposingAwait?: Promise<void>;
|
|
45
|
+
|
|
46
|
+
constructor(userAppConfig?: EditorAppConfig) {
|
|
47
|
+
this.$type = userAppConfig?.$type ?? 'extended';
|
|
48
|
+
this.id = userAppConfig?.id ?? Math.floor(Math.random() * 1000001).toString();
|
|
49
|
+
if ((userAppConfig?.useDiffEditor ?? false) && !userAppConfig?.codeResources?.original) {
|
|
50
|
+
throw new Error(`Use diff editor was used without a valid config. code: ${userAppConfig?.codeResources?.modified} codeOriginal: ${userAppConfig?.codeResources?.original}`);
|
|
51
|
+
}
|
|
52
|
+
this.config = {
|
|
53
|
+
codeResources: userAppConfig?.codeResources ?? undefined,
|
|
54
|
+
useDiffEditor: userAppConfig?.useDiffEditor ?? false,
|
|
55
|
+
readOnly: userAppConfig?.readOnly ?? false,
|
|
56
|
+
domReadOnly: userAppConfig?.domReadOnly ?? false,
|
|
57
|
+
overrideAutomaticLayout: userAppConfig?.overrideAutomaticLayout ?? true
|
|
58
|
+
};
|
|
59
|
+
this.config.editorOptions = {
|
|
60
|
+
...userAppConfig?.editorOptions,
|
|
61
|
+
automaticLayout: userAppConfig?.overrideAutomaticLayout ?? true
|
|
62
|
+
};
|
|
63
|
+
this.config.diffEditorOptions = {
|
|
64
|
+
...userAppConfig?.diffEditorOptions,
|
|
65
|
+
automaticLayout: userAppConfig?.overrideAutomaticLayout ?? true
|
|
66
|
+
};
|
|
67
|
+
this.config.languageDef = userAppConfig?.languageDef;
|
|
68
|
+
|
|
69
|
+
this.logger.setLevel(this.config.logLevel ?? LogLevel.Off);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
isDiffEditor() {
|
|
73
|
+
return this.config.useDiffEditor === true;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
getConfig(): EditorAppConfig {
|
|
77
|
+
return this.config;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
getEditor(): monaco.editor.IStandaloneCodeEditor | undefined {
|
|
81
|
+
return this.editor;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
getDiffEditor(): monaco.editor.IStandaloneDiffEditor | undefined {
|
|
85
|
+
return this.diffEditor;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
getTextModels(): TextModels {
|
|
89
|
+
return {
|
|
90
|
+
modified: this.modelRefs.modified?.object.textEditorModel ?? undefined,
|
|
91
|
+
original: this.modelRefs.original?.object.textEditorModel ?? undefined
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
getLogger() {
|
|
96
|
+
return this.logger;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
registerOnTextChangedCallback(onTextChanged?: (textChanges: TextContents) => void) {
|
|
100
|
+
this.onTextChanged = onTextChanged;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
public setModelRefDisposeTimeout(modelRefDisposeTimeout: number) {
|
|
104
|
+
this.modelRefDisposeTimeout = modelRefDisposeTimeout;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
isStarting() {
|
|
108
|
+
return this.startingAwait !== undefined;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
getStartingAwait() {
|
|
112
|
+
return this.startingAwait;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
isStarted() {
|
|
116
|
+
return this.editor !== undefined || this.diffEditor !== undefined;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Starts the single editor application.
|
|
121
|
+
*/
|
|
122
|
+
async start(htmlContainer: HTMLElement) {
|
|
123
|
+
if (this.isStarting()) {
|
|
124
|
+
await this.getStartingAwait();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
let startingResolve: (value: void | PromiseLike<void>) => void = () => { };
|
|
128
|
+
this.startingAwait = new Promise<void>((resolve) => {
|
|
129
|
+
startingResolve = resolve;
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
try {
|
|
133
|
+
const envEnhanced = getEnhancedMonacoEnvironment();
|
|
134
|
+
const viewServiceType = envEnhanced.viewServiceType;
|
|
135
|
+
|
|
136
|
+
// check general error case first
|
|
137
|
+
if (!(envEnhanced.vscodeApiInitialised ?? false)) {
|
|
138
|
+
return Promise.reject('monaco-vscode-api was not initialized. Aborting.');
|
|
139
|
+
}
|
|
140
|
+
if (viewServiceType !== 'EditorService' && viewServiceType !== undefined) {
|
|
141
|
+
return Promise.reject('No EditorService configured. monaco-editor will not be started.');
|
|
142
|
+
}
|
|
143
|
+
if (!this.isDisposed()) {
|
|
144
|
+
return Promise.reject('Start was called without properly disposing the EditorApp first.');
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const languageDef = this.config.languageDef;
|
|
148
|
+
if (languageDef) {
|
|
149
|
+
if (this.$type === 'extended') {
|
|
150
|
+
throw new Error('Language definition is not supported for extended editor apps where textmate is used.');
|
|
151
|
+
}
|
|
152
|
+
// register own language first
|
|
153
|
+
monaco.languages.register(languageDef.languageExtensionConfig);
|
|
154
|
+
|
|
155
|
+
const languageRegistered = monaco.languages.getLanguages().filter(x => x.id === languageDef.languageExtensionConfig.id);
|
|
156
|
+
if (languageRegistered.length === 0) {
|
|
157
|
+
// this is only meaningful for languages supported by monaco out of the box
|
|
158
|
+
monaco.languages.register({
|
|
159
|
+
id: languageDef.languageExtensionConfig.id
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// apply monarch definitions
|
|
164
|
+
if (languageDef.monarchLanguage) {
|
|
165
|
+
monaco.languages.setMonarchTokensProvider(languageDef.languageExtensionConfig.id, languageDef.monarchLanguage);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (languageDef.theme) {
|
|
169
|
+
monaco.editor.defineTheme(languageDef.theme.name, languageDef.theme.data);
|
|
170
|
+
monaco.editor.setTheme(languageDef.theme.name);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (this.config.editorOptions?.['semanticHighlighting.enabled'] !== undefined) {
|
|
175
|
+
StandaloneServices.get(IConfigurationService).updateValue('editor.semanticHighlighting.enabled',
|
|
176
|
+
this.config.editorOptions['semanticHighlighting.enabled'], ConfigurationTarget.USER);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
await this.createEditors(htmlContainer!);
|
|
180
|
+
|
|
181
|
+
// everything is fine at this point
|
|
182
|
+
startingResolve();
|
|
183
|
+
this.logger.info('EditorApp start completed successfully.');
|
|
184
|
+
} catch (e) {
|
|
185
|
+
// in case of further errors (after general ones above)
|
|
186
|
+
// take the error and build a new rejection to complete the promise
|
|
187
|
+
return Promise.reject(e);
|
|
188
|
+
} finally {
|
|
189
|
+
this.startingAwait = undefined;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
async createEditors(htmlContainer: HTMLElement): Promise<void> {
|
|
194
|
+
// ensure proper default resources are initialized, uris have to be unique
|
|
195
|
+
const modified = {
|
|
196
|
+
text: this.config.codeResources?.modified?.text ?? '',
|
|
197
|
+
uri: this.config.codeResources?.modified?.uri ?? `default-uri-modified-${this.id}`,
|
|
198
|
+
enforceLanguageId: this.config.codeResources?.modified?.enforceLanguageId ?? undefined
|
|
199
|
+
};
|
|
200
|
+
this.modelRefs.modified = await this.buildModelReference(modified, this.logger);
|
|
201
|
+
|
|
202
|
+
if (this.isDiffEditor()) {
|
|
203
|
+
const original = {
|
|
204
|
+
text: this.config.codeResources?.original?.text ?? '',
|
|
205
|
+
uri: this.config.codeResources?.original?.uri ?? `default-uri-original-${this.id}`,
|
|
206
|
+
enforceLanguageId: this.config.codeResources?.original?.enforceLanguageId ?? undefined
|
|
207
|
+
};
|
|
208
|
+
this.modelRefs.original = await this.buildModelReference(original, this.logger);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
this.logger.info(`Starting monaco-editor (${this.id})`);
|
|
212
|
+
if (this.isDiffEditor()) {
|
|
213
|
+
this.diffEditor = monaco.editor.createDiffEditor(htmlContainer, this.config.diffEditorOptions);
|
|
214
|
+
const modified = this.modelRefs.modified.object.textEditorModel ?? undefined;
|
|
215
|
+
const original = this.modelRefs.original?.object.textEditorModel ?? undefined;
|
|
216
|
+
if (modified !== undefined && original !== undefined) {
|
|
217
|
+
const model = {
|
|
218
|
+
modified,
|
|
219
|
+
original
|
|
220
|
+
};
|
|
221
|
+
this.diffEditor.setModel(model);
|
|
222
|
+
this.announceModelUpdate(model);
|
|
223
|
+
}
|
|
224
|
+
} else {
|
|
225
|
+
const model = {
|
|
226
|
+
modified: this.modelRefs.modified.object.textEditorModel
|
|
227
|
+
};
|
|
228
|
+
this.editor = monaco.editor.create(htmlContainer, {
|
|
229
|
+
...this.config.editorOptions,
|
|
230
|
+
model: model.modified
|
|
231
|
+
});
|
|
232
|
+
this.announceModelUpdate(model);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
updateCode(code: { modified?: string, original?: string }) {
|
|
237
|
+
if (this.isDiffEditor()) {
|
|
238
|
+
if (code.modified !== undefined) {
|
|
239
|
+
this.diffEditor?.getModifiedEditor().setValue(code.modified);
|
|
240
|
+
}
|
|
241
|
+
if (code.original !== undefined) {
|
|
242
|
+
this.diffEditor?.getOriginalEditor().setValue(code.original);
|
|
243
|
+
}
|
|
244
|
+
} else {
|
|
245
|
+
if (code.modified !== undefined) {
|
|
246
|
+
this.editor?.setValue(code.modified);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
async updateCodeResources(codeResources?: CodeResources): Promise<void> {
|
|
253
|
+
let updateModified = false;
|
|
254
|
+
let updateOriginal = false;
|
|
255
|
+
|
|
256
|
+
if (codeResources?.modified !== undefined && codeResources.modified.uri !== this.modelRefs.modified?.object.resource.path) {
|
|
257
|
+
this.modelDisposables.modified = this.modelRefs.modified;
|
|
258
|
+
this.modelRefs.modified = await this.buildModelReference(codeResources.modified, this.logger);
|
|
259
|
+
updateModified = true;
|
|
260
|
+
}
|
|
261
|
+
if (codeResources?.original !== undefined && codeResources.original.uri !== this.modelRefs.original?.object.resource.path) {
|
|
262
|
+
this.modelDisposables.original = this.modelRefs.original;
|
|
263
|
+
this.modelRefs.original = await this.buildModelReference(codeResources.original, this.logger);
|
|
264
|
+
updateOriginal = true;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
if (this.isDiffEditor()) {
|
|
268
|
+
if (updateModified && updateOriginal) {
|
|
269
|
+
const modified = this.modelRefs.modified?.object.textEditorModel ?? undefined;
|
|
270
|
+
const original = this.modelRefs.original?.object.textEditorModel ?? undefined;
|
|
271
|
+
if (modified !== undefined && original !== undefined) {
|
|
272
|
+
const model = {
|
|
273
|
+
modified,
|
|
274
|
+
original
|
|
275
|
+
};
|
|
276
|
+
this.diffEditor?.setModel(model);
|
|
277
|
+
this.announceModelUpdate(model);
|
|
278
|
+
}
|
|
279
|
+
} else {
|
|
280
|
+
this.logger.info('Diff Editor: Code resources were not updated. They are ether unchanged or undefined.');
|
|
281
|
+
}
|
|
282
|
+
} else {
|
|
283
|
+
if (updateModified) {
|
|
284
|
+
const model = {
|
|
285
|
+
modified: this.modelRefs.modified?.object.textEditorModel
|
|
286
|
+
};
|
|
287
|
+
if (model.modified !== undefined && model.modified !== null) {
|
|
288
|
+
this.editor?.setModel(model.modified);
|
|
289
|
+
this.announceModelUpdate(model);
|
|
290
|
+
}
|
|
291
|
+
} else {
|
|
292
|
+
this.logger.info('Editor: Code resources were not updated. They are either unchanged or undefined.');
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
await this.disposeModelRefs();
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
async buildModelReference(codeContent: CodeContent, logger?: Logger): Promise<IReference<ITextFileEditorModel>> {
|
|
300
|
+
const code = codeContent.text;
|
|
301
|
+
const modelRef = await createModelReference(vscode.Uri.parse(codeContent.uri), code);
|
|
302
|
+
|
|
303
|
+
// update the text if different
|
|
304
|
+
if (modelRef.object.textEditorModel?.getValue() !== code) {
|
|
305
|
+
modelRef.object.textEditorModel?.setValue(code);
|
|
306
|
+
}
|
|
307
|
+
const enforceLanguageId = codeContent.enforceLanguageId;
|
|
308
|
+
if (enforceLanguageId !== undefined) {
|
|
309
|
+
modelRef.object.setLanguageId(enforceLanguageId);
|
|
310
|
+
logger?.info(`Main languageId is enforced: ${enforceLanguageId}`);
|
|
311
|
+
}
|
|
312
|
+
return modelRef;
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
private announceModelUpdate(textModels: TextModels) {
|
|
316
|
+
if (this.onTextChanged !== undefined) {
|
|
317
|
+
let changed = false;
|
|
318
|
+
if (textModels.modified !== undefined && textModels.modified !== null) {
|
|
319
|
+
const old = this.textChangedDisposables.modified;
|
|
320
|
+
this.textChangedDisposables.modified = textModels.modified.onDidChangeContent(() => {
|
|
321
|
+
didModelContentChange(textModels, this.onTextChanged);
|
|
322
|
+
});
|
|
323
|
+
old?.dispose();
|
|
324
|
+
changed = true;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
if (textModels.original !== undefined && textModels.original !== null) {
|
|
328
|
+
const old = this.textChangedDisposables.original;
|
|
329
|
+
this.textChangedDisposables.original = textModels.original.onDidChangeContent(() => {
|
|
330
|
+
didModelContentChange(textModels, this.onTextChanged);
|
|
331
|
+
});
|
|
332
|
+
old?.dispose();
|
|
333
|
+
changed = true;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
if (changed) {
|
|
337
|
+
// do it initially
|
|
338
|
+
didModelContentChange(textModels, this.onTextChanged);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
async dispose() {
|
|
344
|
+
if (this.isDisposing()) {
|
|
345
|
+
await this.getDisposingAwait();
|
|
346
|
+
}
|
|
347
|
+
let disposingResolve: (value: void | PromiseLike<void>) => void = () => { };
|
|
348
|
+
this.disposingAwait = new Promise<void>((resolve) => {
|
|
349
|
+
disposingResolve = resolve;
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
if (this.editor) {
|
|
353
|
+
this.editor.dispose();
|
|
354
|
+
this.editor = undefined;
|
|
355
|
+
}
|
|
356
|
+
if (this.diffEditor) {
|
|
357
|
+
this.diffEditor.dispose();
|
|
358
|
+
this.diffEditor = undefined;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
this.textChangedDisposables.modified?.dispose();
|
|
362
|
+
this.textChangedDisposables.original?.dispose();
|
|
363
|
+
this.textChangedDisposables.modified = undefined;
|
|
364
|
+
this.textChangedDisposables.original = undefined;
|
|
365
|
+
|
|
366
|
+
await this.disposeModelRefs();
|
|
367
|
+
|
|
368
|
+
disposingResolve();
|
|
369
|
+
this.disposingAwait = undefined;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
isDisposed(): boolean {
|
|
373
|
+
return this.editor === undefined && this.diffEditor === undefined &&
|
|
374
|
+
this.modelDisposables.original === undefined && this.modelDisposables.modified === undefined;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
isDisposing() {
|
|
378
|
+
return this.disposingAwait !== undefined;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
getDisposingAwait() {
|
|
382
|
+
return this.disposingAwait;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
async disposeModelRefs() {
|
|
386
|
+
const disposeRefs = () => {
|
|
387
|
+
if (this.logger.getLevel() === LogLevel.Debug) {
|
|
388
|
+
const models = monaco.editor.getModels();
|
|
389
|
+
this.logger.debug('Current model URIs:');
|
|
390
|
+
models.forEach((model, _index) => {
|
|
391
|
+
this.logger.debug(`${model.uri.toString()}`);
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
if (this.modelDisposables.modified !== undefined && !this.modelDisposables.modified.object.isDisposed()) {
|
|
396
|
+
this.modelDisposables.modified.dispose();
|
|
397
|
+
this.modelDisposables.modified = undefined;
|
|
398
|
+
}
|
|
399
|
+
if (this.modelDisposables.original !== undefined && !this.modelDisposables.original.object.isDisposed()) {
|
|
400
|
+
this.modelDisposables.original.dispose();
|
|
401
|
+
this.modelDisposables.original = undefined;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
if (this.logger.getLevel() === LogLevel.Debug) {
|
|
405
|
+
if (this.modelDisposables.modified === undefined && this.modelDisposables.original === undefined) {
|
|
406
|
+
this.logger.debug('All model references are disposed.');
|
|
407
|
+
} else {
|
|
408
|
+
this.logger.debug('Model references are still available.');
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
if (this.modelRefDisposeTimeout > 0) {
|
|
414
|
+
this.logger.debug('Using async dispose of model references');
|
|
415
|
+
await new Promise<void>(resolve => setTimeout(() => {
|
|
416
|
+
disposeRefs();
|
|
417
|
+
resolve();
|
|
418
|
+
}, this.modelRefDisposeTimeout));
|
|
419
|
+
} else {
|
|
420
|
+
disposeRefs();
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
updateLayout() {
|
|
425
|
+
if (this.isDiffEditor()) {
|
|
426
|
+
this.diffEditor?.layout();
|
|
427
|
+
} else {
|
|
428
|
+
this.editor?.layout();
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
reportStatus() {
|
|
433
|
+
const status: string[] = [];
|
|
434
|
+
status.push('EditorApp status:');
|
|
435
|
+
status.push(`Editor: ${this.editor?.getId()}`);
|
|
436
|
+
status.push(`DiffEditor: ${this.diffEditor?.getId()}`);
|
|
437
|
+
return status;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
export const didModelContentChange = (textModels: TextModels, onTextChanged?: (textChanges: TextContents) => void) => {
|
|
442
|
+
const modified = textModels.modified?.getValue() ?? '';
|
|
443
|
+
const original = textModels.original?.getValue() ?? '';
|
|
444
|
+
onTextChanged?.({
|
|
445
|
+
modified,
|
|
446
|
+
original
|
|
447
|
+
});
|
|
448
|
+
};
|
|
@@ -2,5 +2,6 @@
|
|
|
2
2
|
* Copyright (c) 2024 TypeFox and others.
|
|
3
3
|
* Licensed under the MIT License. See LICENSE in the package root for license information.
|
|
4
4
|
* ------------------------------------------------------------------------------------------ */
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
|
|
6
|
+
export * from './config.js';
|
|
7
|
+
export * from './editorApp.js';
|
package/src/fs/definitions.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Licensed under the MIT License. See LICENSE in the package root for license information.
|
|
4
4
|
* ------------------------------------------------------------------------------------------ */
|
|
5
5
|
|
|
6
|
-
import type { Logger } from 'monaco-languageclient/
|
|
6
|
+
import type { Logger } from 'monaco-languageclient/common';
|
|
7
7
|
|
|
8
8
|
export interface FileReadRequest {
|
|
9
9
|
resourceUri: string
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Licensed under the MIT License. See LICENSE in the package root for license information.
|
|
4
4
|
* ------------------------------------------------------------------------------------------ */
|
|
5
5
|
|
|
6
|
-
import type { Logger } from 'monaco-languageclient/
|
|
6
|
+
import type { Logger } from 'monaco-languageclient/common';
|
|
7
7
|
import type { DirectoryListingRequest, DirectoryListingRequestResult, FileReadRequest, FileReadRequestResult, FileSystemEndpoint, FileUpdate, FileUpdateResult, StatsRequest, StatsRequestResult } from '../definitions.js';
|
|
8
8
|
import { EndpointType } from '../definitions.js';
|
|
9
9
|
|
package/src/index.ts
CHANGED
|
@@ -3,5 +3,32 @@
|
|
|
3
3
|
* Licensed under the MIT License. See LICENSE in the package root for license information.
|
|
4
4
|
* ------------------------------------------------------------------------------------------ */
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
import { BaseLanguageClient, MessageTransports, ProposedFeatures, type LanguageClientOptions } from 'vscode-languageclient/browser.js';
|
|
7
|
+
|
|
8
|
+
export type MonacoLanguageClientOptions = {
|
|
9
|
+
name: string;
|
|
10
|
+
id?: string;
|
|
11
|
+
clientOptions: LanguageClientOptions;
|
|
12
|
+
messageTransports: MessageTransports;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class MonacoLanguageClient extends BaseLanguageClient {
|
|
16
|
+
protected readonly messageTransports: MessageTransports;
|
|
17
|
+
|
|
18
|
+
constructor({ id, name, clientOptions, messageTransports }: MonacoLanguageClientOptions) {
|
|
19
|
+
super(id ?? name.toLowerCase(), name, clientOptions);
|
|
20
|
+
this.messageTransports = messageTransports;
|
|
21
|
+
ProposedFeatures.createAll(this);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
protected override createMessageTransports(_encoding: string): Promise<MessageTransports> {
|
|
25
|
+
return Promise.resolve(this.messageTransports);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export class MonacoLanguageClientWithProposedFeatures extends MonacoLanguageClient {
|
|
30
|
+
constructor({ id, name, clientOptions, messageTransports }: MonacoLanguageClientOptions) {
|
|
31
|
+
super({ id, name, clientOptions, messageTransports });
|
|
32
|
+
ProposedFeatures.createAll(this);
|
|
33
|
+
}
|
|
34
|
+
}
|